2 * Copyright (C) 1998-2001 Mark Tuempfel and Uli Luckas
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * To reach the Authors you can send E-Mail to:
20 * Mark Tuempfel <marktop@cs.tu-berlin.de>
21 * Uli Luckas <luckas@cs.tu-brelin.de>
29 import java
.awt
.event
.*;
31 import java
.applet
.Applet
;
32 import java
.io
.IOException
;
35 import musoft
.utils
.*;
37 public class MUMail
extends Applet
implements ActionListener
, PropertyChangeListener
{
40 public static final int HiVersion
= 1;
41 public static final int MedVersion
= 4;
42 public static final int LowVersion
= 2;
43 public static final String ID
= "MUMail " + HiVersion
+ "." + MedVersion
+ "." + LowVersion
;
45 public static final String LOGIN_PANEL
= "LoginPanel";
46 public static final String SPLASH_PANEL
= "SplashPanel";
47 public static final String SENDMAIL_PANEL
= "SendMailPanel";
48 public static final String MAIL_PANEL
= "MailPanel";
49 public static final String MESSAGE_PANEL
= "MessagePanel";
51 public static final String Homepage
= "http://www.musoft.de/MUMail";
53 // configurable options
54 private static String ServerHost
= "";
55 private static String ServerPort
= "";
56 private static String SmtpHost
= "";
57 private static String SmtpPort
= "";
58 private static String User
= "";
59 private static String MailDomain
= "";
60 private static String MailAddress
= "";
61 private static String Password
= "";
62 public static boolean novice
= false;
63 public static boolean showFontChoice
= false;
64 public static boolean authorizedSend
= false;
65 public static int headerListRows
= 5;
66 public static boolean protocolSelect
= false;
76 boolean inSplash
= false;
79 MailClientFactory factory
;
81 public static boolean applet
= true;
83 public static void main(String
[] argv
) {
85 MUMail app
= new MUMail();
91 Frame f
= new Frame ("MUMail");
92 f
.addWindowListener(new WindowAdapter() {
93 public void windowClosing(WindowEvent event
) {
98 Insets i
= f
.getInsets();
99 f
.setSize(app
.getPreferredSize().width
+i
.right
+i
.left
, app
.getPreferredSize().height
+i
.bottom
+i
.top
);
100 f
.setBackground(Color
.lightGray
);
109 //System.setErr(System.out);
110 System
.out
.println(getAppletInfo());
111 setLayout(new CardLayout(0,0));
115 String name
= "MUMail.gif";
116 timer
= new Timer(5000, new TimerAdapter(){
117 public void timerAlarm() {
118 switchFromSplashToLogin();
122 image
= getImage(getCodeBase(), name
);
125 image
= java
.awt
.Toolkit
.getDefaultToolkit().getImage(name
);
127 splash
= new SplashPanel(image
, timer
);
128 //((CardLayout)getLayout()).addLayoutComponent(splash, SPLASH_PANEL);
129 add(SPLASH_PANEL
, splash
);
130 splash
.addMouseListener(new MouseAdapter(){
131 public void mouseClicked(MouseEvent e
){
135 switchFromSplashToLogin();
138 showPanel(SPLASH_PANEL
);
141 // init textfields in login panel
150 factory
= new MailClientFactory("mumail.net.Pop3Client:mumail.net.Imap4Client");
151 lp
= new LoginPanel(ServerHost
, ServerPort
, SmtpHost
, SmtpPort
, User
, Password
, this, factory
);
152 add(LOGIN_PANEL
, lp
);
156 public void switchFromSplashToLogin(){
159 boolean allParametersThere
= ! (lp
.getPassword().equals("") || lp
.getUser().equals("") || lp
.getServerHost().equals("") || lp
.getSmtpHost().equals("") || lp
.getServerPort().equals("") || lp
.getSmtpPort().equals(""));
160 if(allParametersThere
){
164 showPanel(LOGIN_PANEL
);
170 public synchronized void stop() {
176 private String
getParam(String Param
, String Default
){
177 String dummy
= getParameter(Param
);
184 public void initApplet(){
185 ServerHost
= (getParam("ServerHost", getCodeBase().getHost()));
186 SmtpHost
= (getParam("SmtpHost", ServerHost
));
187 ServerPort
= (getParam("ServerPort", "110"));
188 SmtpPort
= (getParam("SmtpPort", "25"));
189 User
= (getParam("User", ""));
190 MailDomain
= (getParam("MailDomain", ""));
191 MailAddress
= (getParam("MailAddress", ""));
192 Password
= (getParam("Password", ""));
193 showFontChoice
= Boolean
.valueOf(getParam("showFontChoice", "false")).booleanValue();
194 novice
= Boolean
.valueOf(getParam("novice", "false")).booleanValue();
195 protocolSelect
= Boolean
.valueOf(getParam("protocolSelect", "false")).booleanValue();
196 authorizedSend
= Boolean
.valueOf(getParam("authorizedSend", "false")).booleanValue();
198 headerListRows
= Integer
.parseInt(getParam("headerListRows", "5"));
199 } catch (NumberFormatException e
){
201 if(headerListRows
<2 || headerListRows
>20){
206 public void initApplication(){
207 ServerHost
= ("mail");
209 ServerPort
= ("110");
211 User
= (System
.getProperty("user.name"));
213 for (int i
= 0; i
< argv
.length
; i
++) {
214 if (argv
[i
].toLowerCase().equals("-pophost") ||
215 argv
[i
].toLowerCase().equals("-serverhost")) {
216 ServerHost
= (argv
[++i
]);
217 } else if (argv
[i
].toLowerCase().equals("-smtphost")) {
218 SmtpHost
= (argv
[++i
]);
219 } else if (argv
[i
].toLowerCase().equals("-popport") ||
220 argv
[i
].toLowerCase().equals("-serverport")) {
221 ServerPort
= (argv
[++i
]);
222 } else if (argv
[i
].toLowerCase().equals("-smtpport")) {
223 SmtpPort
= (argv
[++i
]);
224 } else if (argv
[i
].toLowerCase().equals("-user")) {
226 } else if (argv
[i
].toLowerCase().equals("-maildomain")) {
227 MailDomain
= (argv
[++i
]);
228 } else if (argv
[i
].toLowerCase().equals("-mailaddress")) {
229 MailAddress
= (argv
[++i
]);
230 } else if (argv
[i
].toLowerCase().equals("-password")) {
231 Password
= (argv
[++i
]);
232 } else if (argv
[i
].toLowerCase().equals("-showfontchoice")) {
233 showFontChoice
= true;
234 } else if (argv
[i
].toLowerCase().equals("-authorizedsend")) {
235 authorizedSend
= true;
236 } else if (argv
[i
].toLowerCase().equals("-novice")) {
238 } else if (argv
[i
].toLowerCase().equals("-headerlistrows")) {
240 headerListRows
= Integer
.parseInt(argv
[++i
]);
241 } catch(NumberFormatException e
){
243 if(headerListRows
<2 || headerListRows
>20){
246 } else if (argv
[i
].toLowerCase().equals("-protocolselect")) {
247 protocolSelect
= true;
249 System
.err
.println("usage: java mumail.MUMail [-smtphost <SMTP Server>] |");
250 System
.err
.println(" [-serverhost <Mail Server>] |");
251 System
.err
.println(" [-smtpport <SMTP Port>] |");
252 System
.err
.println(" [-serverport <Mail Port>] |");
253 System
.err
.println(" [-user <User Name>] |");
254 System
.err
.println(" [-password <Password>] |");
255 System
.err
.println(" [-from <my address>] |");
256 System
.err
.println(" [-maildomain <domain part of email adress>] |");
257 System
.err
.println(" [-headerListRows <number>] |");
258 System
.err
.println(" [-showFontChoice] |");
259 System
.err
.println(" [-authorizedSend] |");
260 System
.err
.println(" [-novice]");
261 System
.err
.println(" [-protocolSelect]");
267 public void showPanel(String s
){
268 //System.out.println("showPanel("+s+")");
269 ((CardLayout
)getLayout()).show(this, s
);
272 public void showLastPanel(){
273 ((CardLayout
)getLayout()).previous(this);
276 public void newMessagePanel(String s
){
277 messp
= new MessagePanel(s
, this);
278 add(MESSAGE_PANEL
, messp
);
279 showPanel(MESSAGE_PANEL
);
282 /*public void newMailPanel() throws IOException {
283 mp = new MailPanel(mq, this);
285 showPanel(MAIL_PANEL);
289 public void newSendMailPanel(boolean reply
){
292 String User
= lp
.getUser();
294 if(MailAddress
.equals("")){
295 if (MailDomain
.equals("")) {
296 Domain
= lp
.getServerHost();
297 int i
= Domain
.indexOf(".");
299 if (Domain
.equals("") || Domain
.equals("localhost")) {
302 Domain
= "@" + Domain
;
305 Domain
= "@" + Domain
.substring(i
+ 1);
308 Domain
= "@" + MailDomain
;
310 User
= User
+ Domain
;
317 smp
= new SendMailPanel(mp
.mo
, User
, this);
320 smp
= new SendMailPanel(User
, this);
322 //CardLayout)getLayout()).addLayoutComponent(smp, SENDMAIL_PANEL);
323 add(SENDMAIL_PANEL
, smp
);
324 showPanel(SENDMAIL_PANEL
);
327 public void Connect(){
328 setCursor(new Cursor(Cursor
.WAIT_CURSOR
));
330 MailClient mc
= factory
.getMailClientByProtocolName(lp
.getProtocol());
331 System
.err
.println(mc
);
332 mq
= new MailQueue(mc
, lp
.getServerHost(), java
.lang
.Integer
.parseInt(lp
.getServerPort()), lp
.getUser(), lp
.getPassword());
333 mq
.addPropertyChangeListener(this);
336 mp
= new MailPanel(mq
, this);
338 showStatus("connected to " + lp
.getServerHost() + " as " + lp
.getUser());
341 showPanel(MAIL_PANEL
);
343 } catch (java
.lang
.Exception e2
) {
344 //System.err.println(e2);
345 //e2.printStackTrace();
346 newMessagePanel(e2
.getMessage());
348 setCursor(new Cursor(Cursor
.DEFAULT_CURSOR
));
351 public void propertyChange(PropertyChangeEvent propertyChangeEvent
) {
352 if (propertyChangeEvent
.getSource() == mq
) {
353 if (propertyChangeEvent
.getPropertyName().equals(mq
.pn_Connected
)) {
358 public void actionPerformed(ActionEvent e
) {
359 // confirm message panel
360 if (e
.getActionCommand().equals("OK")){
366 if ((e
.getActionCommand().equals("Connect"))||(e
.getSource()==lp
.PasswordTF
)){
371 if (e
.getActionCommand().equals("Connection")) {
372 if (mq
.isConnected()) {
377 } catch(IOException exep
) {
378 exep
.printStackTrace();
384 if (e
.getActionCommand().equals("Close")) {
385 setCursor(new Cursor(Cursor
.WAIT_CURSOR
));
390 showStatus("MUMail login");
393 showPanel(LOGIN_PANEL
);
394 setCursor(new Cursor(Cursor
.DEFAULT_CURSOR
));
398 if (e
.getActionCommand().equals("Reply")){
399 newSendMailPanel(true);
402 // from mail panel AND!!! login panel
403 if (e
.getActionCommand().equals("Send")){
404 newSendMailPanel(false);
407 // from sendmailpanel, means send mail now
408 if (e
.getActionCommand().equals("SendMail")){
410 sm
= new SmtpClient(lp
.getSmtpHost(), java
.lang
.Integer
.parseInt(lp
.getSmtpPort()));
411 sm
.submitMail(smp
.From
.getText(), smp
.To
.getText(), smp
.Subject
.getText(), smp
.Text
.getText(), smp
.getEncoding());
415 } catch (java
.lang
.Exception exep
) {
417 newMessagePanel(exep
.getMessage());
418 //System.err.println(exep);
419 //exep.printStackTrace();
423 // from sendmailpanel
424 if (e
.getActionCommand().equals("Cancel")){
431 if (e
.getActionCommand().equals(mumail
.gui
.LoginPanel
.homepage
)){
433 getAppletContext().showDocument(new URL(Homepage
));
435 catch (MalformedURLException excep
){
440 if (e
.getActionCommand().equals("Exit")){
445 if (e
.getActionCommand().equals("Exit2")) {
446 setCursor(new Cursor(Cursor
.WAIT_CURSOR
));
448 setCursor(new Cursor(Cursor
.DEFAULT_CURSOR
));
453 public String
[][] getParameterInfo() {
455 {"ServerHost", "String", ""},
456 {"SmtpHost", "String", ""},
457 {"ServerPort", "String", ""},
458 {"SmtpPort", "String", ""},
459 {"User", "String", ""},
460 {"Password", "String", ""},
461 {"MailDomain", "String", ""},
462 {"showFontChoice", "booelan", ""},
463 {"novice", "boolean", ""},
464 {"authorizedSend", "boolean", ""},
465 {"headerListRows", "Integer", ""},
466 {"protocolSelect", "boolean", ""},
471 public String
getAppletInfo() {
472 return ID
+ " Copyright 1997 - 2001 by Uli Luckas <luckas@cs.tu-berlin.de>\n" +
473 " Mark T\u00fcmpfel <marktop@cs.tu-berlin.de>\n" +
474 "Homepage: "+Homepage
+"\n"+
475 "MUMail is free software under the terms of GNU General Public License\n" +
476 "and comes with ABSOLUTELY NO WARRANTY.\n";
479 public Dimension
getPreferredSize(){
480 return new Dimension(600,440);