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
= 0;
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.cs.tu-berlin.de/~marktop/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 Password
= "";
61 public static boolean novice
= false;
62 public static boolean showFontChoice
= false;
63 public static boolean authorizedSend
= false;
64 public static int headerListRows
= 5;
65 public static boolean protocolSelect
= false;
75 boolean inSplash
= false;
78 MailClientFactory factory
;
80 public static boolean applet
= true;
82 public static void main(String
[] argv
) {
84 MUMail app
= new MUMail();
90 Frame f
= new Frame ("MUMail");
91 f
.addWindowListener(new WindowAdapter() {
92 public void windowClosing(WindowEvent event
) {
97 Insets i
= f
.getInsets();
98 f
.setSize(app
.getPreferredSize().width
+i
.right
+i
.left
, app
.getPreferredSize().height
+i
.bottom
+i
.top
);
99 f
.setBackground(Color
.lightGray
);
108 //System.setErr(System.out);
109 System
.out
.println(getAppletInfo());
110 setLayout(new CardLayout(0,0));
114 String name
= "MUMail.gif";
115 timer
= new Timer(5000, new TimerAdapter(){
116 public void timerAlarm() {
117 switchFromSplashToLogin();
121 image
= getImage(getCodeBase(), name
);
124 image
= java
.awt
.Toolkit
.getDefaultToolkit().getImage(name
);
126 splash
= new SplashPanel(image
, timer
);
127 //((CardLayout)getLayout()).addLayoutComponent(splash, SPLASH_PANEL);
128 add(SPLASH_PANEL
, splash
);
129 splash
.addMouseListener(new MouseAdapter(){
130 public void mouseClicked(MouseEvent e
){
134 switchFromSplashToLogin();
137 showPanel(SPLASH_PANEL
);
140 // init textfields in login panel
149 factory
= new MailClientFactory("mumail.net.Pop3Client:mumail.net.Imap4Client");
150 lp
= new LoginPanel(ServerHost
, ServerPort
, SmtpHost
, SmtpPort
, User
, Password
, this, factory
);
151 add(LOGIN_PANEL
, lp
);
155 public void switchFromSplashToLogin(){
158 boolean allParametersThere
= ! (lp
.getPassword().equals("") || lp
.getUser().equals("") || lp
.getServerHost().equals("") || lp
.getSmtpHost().equals("") || lp
.getServerPort().equals("") || lp
.getSmtpPort().equals(""));
159 if(allParametersThere
){
163 showPanel(LOGIN_PANEL
);
169 public synchronized void stop() {
173 private String
getParam(String Param
, String Default
){
174 String dummy
= getParameter(Param
);
181 public void initApplet(){
182 ServerHost
= (getParam("ServerHost", getCodeBase().getHost()));
183 SmtpHost
= (getParam("SmtpHost", ServerHost
));
184 ServerPort
= (getParam("ServerPort", "110"));
185 SmtpPort
= (getParam("SmtpPort", "25"));
186 User
= (getParam("User", ""));
187 MailDomain
= (getParam("MailDomain", ""));
188 Password
= (getParam("Password", ""));
189 showFontChoice
= Boolean
.valueOf(getParam("showFontChoice", "false")).booleanValue();
190 novice
= Boolean
.valueOf(getParam("novice", "false")).booleanValue();
191 protocolSelect
= Boolean
.valueOf(getParam("protocolSelect", "false")).booleanValue();
192 authorizedSend
= Boolean
.valueOf(getParam("authorizedSend", "false")).booleanValue();
194 headerListRows
= Integer
.parseInt(getParam("headerListRows", "5"));
195 } catch (NumberFormatException e
){
197 if(headerListRows
<2 || headerListRows
>20){
202 public void initApplication(){
203 ServerHost
= ("mail");
205 ServerPort
= ("110");
207 User
= (System
.getProperty("user.name"));
209 for (int i
= 0; i
< argv
.length
; i
++) {
210 if (argv
[i
].toLowerCase().equals("-pophost") ||
211 argv
[i
].toLowerCase().equals("-serverhost")) {
212 ServerHost
= (argv
[++i
]);
213 } else if (argv
[i
].toLowerCase().equals("-smtphost")) {
214 SmtpHost
= (argv
[++i
]);
215 } else if (argv
[i
].toLowerCase().equals("-popport") ||
216 argv
[i
].toLowerCase().equals("-serverport")) {
217 ServerPort
= (argv
[++i
]);
218 } else if (argv
[i
].toLowerCase().equals("-smtpport")) {
219 SmtpPort
= (argv
[++i
]);
220 } else if (argv
[i
].toLowerCase().equals("-user")) {
222 } else if (argv
[i
].toLowerCase().equals("-maildomain")) {
223 MailDomain
= (argv
[++i
]);
224 } else if (argv
[i
].toLowerCase().equals("-password")) {
225 Password
= (argv
[++i
]);
226 } else if (argv
[i
].toLowerCase().equals("-showfontchoice")) {
227 showFontChoice
= true;
228 } else if (argv
[i
].toLowerCase().equals("-authorizedsend")) {
229 authorizedSend
= true;
230 } else if (argv
[i
].toLowerCase().equals("-novice")) {
232 } else if (argv
[i
].toLowerCase().equals("-headerlistrows")) {
234 headerListRows
= Integer
.parseInt(argv
[++i
]);
235 } catch(NumberFormatException e
){
237 if(headerListRows
<2 || headerListRows
>20){
240 } else if (argv
[i
].toLowerCase().equals("-protocolselect")) {
241 protocolSelect
= true;
243 System
.err
.println("usage: java mumail.MUMail [-smtphost <SMTP Server>] |");
244 System
.err
.println(" [-serverhost <Mail Server>] |");
245 System
.err
.println(" [-smtpport <SMTP Port>] |");
246 System
.err
.println(" [-serverport <Mail Port>] |");
247 System
.err
.println(" [-user <User Name>] |");
248 System
.err
.println(" [-password <Password>] |");
249 System
.err
.println(" [-from <my address>] |");
250 System
.err
.println(" [-maildomain <domain part of email adress>] |");
251 System
.err
.println(" [-headerListRows <number>] |");
252 System
.err
.println(" [-showFontChoice] |");
253 System
.err
.println(" [-authorizedSend] |");
254 System
.err
.println(" [-novice]");
255 System
.err
.println(" [-protocolSelect]");
261 public void showPanel(String s
){
262 //System.out.println("showPanel("+s+")");
263 ((CardLayout
)getLayout()).show(this, s
);
266 public void showLastPanel(){
267 ((CardLayout
)getLayout()).previous(this);
270 public void newMessagePanel(String s
){
271 messp
= new MessagePanel(s
, this);
272 add(MESSAGE_PANEL
, messp
);
273 showPanel(MESSAGE_PANEL
);
276 /*public void newMailPanel() throws IOException {
277 mp = new MailPanel(mq, this);
279 showPanel(MAIL_PANEL);
283 public void newSendMailPanel(boolean reply
){
286 String User
= lp
.getUser();
288 if (MailDomain
.equals("")) {
289 Domain
= lp
.getServerHost();
290 int i
= Domain
.indexOf(".");
292 if (Domain
.equals("") || Domain
.equals("localhost")) {
295 Domain
= "@" + Domain
;
298 Domain
= "@" + Domain
.substring(i
+ 1);
301 Domain
= "@" + MailDomain
;
303 User
= User
+ Domain
;
306 smp
= new SendMailPanel(mp
.mo
, User
, this);
309 smp
= new SendMailPanel(User
, this);
311 //CardLayout)getLayout()).addLayoutComponent(smp, SENDMAIL_PANEL);
312 add(SENDMAIL_PANEL
, smp
);
313 showPanel(SENDMAIL_PANEL
);
316 public void Connect(){
317 setCursor(new Cursor(Cursor
.WAIT_CURSOR
));
319 MailClient mc
= factory
.getMailClientByProtocolName(lp
.getProtocol());
320 System
.err
.println(mc
);
321 mq
= new MailQueue(mc
, lp
.getServerHost(), java
.lang
.Integer
.parseInt(lp
.getServerPort()), lp
.getUser(), lp
.getPassword());
322 mq
.addPropertyChangeListener(this);
325 mp
= new MailPanel(mq
, this);
327 showStatus("connected to " + lp
.getServerHost() + " as " + lp
.getUser());
330 showPanel(MAIL_PANEL
);
332 } catch (java
.lang
.Exception e2
) {
333 //System.err.println(e2);
334 //e2.printStackTrace();
335 newMessagePanel(e2
.getMessage());
337 setCursor(new Cursor(Cursor
.DEFAULT_CURSOR
));
340 public void propertyChange(PropertyChangeEvent propertyChangeEvent
) {
341 if (propertyChangeEvent
.getSource() == mq
) {
342 if (propertyChangeEvent
.getPropertyName() == mq
.pn_Connected
) {
347 public void actionPerformed(ActionEvent e
) {
348 // confirm message panel
349 if (e
.getActionCommand().equals("OK")){
355 if ((e
.getActionCommand().equals("Connect"))||(e
.getSource()==lp
.PasswordTF
)){
360 if (e
.getActionCommand().equals("Connection")) {
361 if (mq
.isConnected()) {
366 } catch(IOException exep
) {
367 exep
.printStackTrace();
373 if (e
.getActionCommand().equals("Close")) {
374 setCursor(new Cursor(Cursor
.WAIT_CURSOR
));
379 showStatus("MUMail login");
382 showPanel(LOGIN_PANEL
);
383 setCursor(new Cursor(Cursor
.DEFAULT_CURSOR
));
387 if (e
.getActionCommand().equals("Reply")){
388 newSendMailPanel(true);
391 // from mail panel AND!!! login panel
392 if (e
.getActionCommand().equals("Send")){
393 newSendMailPanel(false);
396 // from sendmailpanel, means send mail now
397 if (e
.getActionCommand().equals("SendMail")){
399 sm
= new SmtpClient(lp
.getSmtpHost(), java
.lang
.Integer
.parseInt(lp
.getSmtpPort()));
400 sm
.submitMail(smp
.From
.getText(), smp
.To
.getText(), smp
.Subject
.getText(), smp
.Text
.getText(), smp
.getEncoding());
404 } catch (java
.lang
.Exception exep
) {
406 newMessagePanel(exep
.getMessage());
407 //System.err.println(exep);
408 //exep.printStackTrace();
412 // from sendmailpanel
413 if (e
.getActionCommand().equals("Cancel")){
420 if (e
.getActionCommand().equals(mumail
.gui
.LoginPanel
.homepage
)){
422 getAppletContext().showDocument(new URL(Homepage
));
424 catch (MalformedURLException excep
){
429 if (e
.getActionCommand().equals("Exit")){
434 if (e
.getActionCommand().equals("Exit2")) {
435 setCursor(new Cursor(Cursor
.WAIT_CURSOR
));
437 setCursor(new Cursor(Cursor
.DEFAULT_CURSOR
));
442 public String
[][] getParameterInfo() {
444 {"ServerHost", "String", ""},
445 {"SmtpHost", "String", ""},
446 {"ServerPort", "String", ""},
447 {"SmtpPort", "String", ""},
448 {"User", "String", ""},
449 {"Password", "String", ""},
450 {"MailDomain", "String", ""},
451 {"showFontChoice", "booelan", ""},
452 {"novice", "boolean", ""},
453 {"authorizedSend", "boolean", ""},
454 {"headerListRows", "Integer", ""},
455 {"protocolSelect", "boolean", ""},
460 public String
getAppletInfo() {
461 return ID
+ " Copyright 1997 - 2001 by Uli Luckas <luckas@cs.tu-berlin.de>\n" +
462 " Mark T\u00fcmpfel <marktop@cs.tu-berlin.de>\n" +
463 "Homepage: "+Homepage
+"\n"+
464 "MUMail is free software under the terms of GNU General Public License\n" +
465 "and comes with ABSOLUTELY NO WARRANTY.\n";
468 public Dimension
getPreferredSize(){
469 return new Dimension(600,440);