📄 mujmail.java
字号:
/*
MujMail - Simple mail client for J2ME
Copyright (C) 2003 Petr Spatka <petr.spatka@centrum.cz>
Copyright (C) 2005 Pavel Machek <pavel@ucw.cz>
Copyright (C) 2006 Nguyen Son Tung <n.sontung@gmail.com>
Copyright (C) 2006 Martin Stefan <martin.stefan@centrum.cz>
Copyright (C) 2008 David Hauzar <david.hauzar.mujmail@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package mujmail;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Alert;
import mujmail.account.AccountSettings;
import mujmail.account.MailAccount;
//#ifdef MUJMAIL_SYNC
import mujmail.account.MailAccountPrimary;
//#endif
import mujmail.protocols.SMTP;
import mujmail.threading.Algorithm;
import mujmail.util.Functions;
//#ifdef MUJMAIL_SEARCH
import mujmail.search.SearchBox;
//#endif
//#ifdef MUJMAIL_SYNC
import mujmail.account.Sync;
//#endif
//#ifdef MUJMAIL_USR_FOLDERS
import mujmail.mailboxes.BoxList;
//#endif
//#ifdef MUJMAIL_DEBUG_CONSOLE
import mujmail.debug.DebugConsole;
//#endif
public class MujMail extends MIDlet implements CommandListener {
/** Flag signals if we want to print debug prints */
private static final boolean DEBUG = false;
public static final String VERSION = "v1.08.08";
public static final int BUILD = 20090402;
public static Properties props;
//private Lang language = new Lang();
private MyDisplay myDisplay = new MyDisplay(this);
public MyAlert alert = new MyAlert(this);
private Settings settings = new Settings(this);
private final AccountSettings accountSettings = new AccountSettings(this);
private AddressBook addressBook = new AddressBook(this);
final OutBox outBox;
final PersistentBox sentBox;
//#ifdef MUJMAIL_SEARCH
final private SearchBox searchBox;
//#endif
private final InBox inBox;
final OutBox draft;
private final Trash trash;
//#ifdef MUJMAIL_SYNC
private final Sync sync;
//#endif
public MailForm mailForm = new MailForm(this);
public SendMail sendMail = new SendMail(this);
About about = new About(this);
//private Debug debug = null;
private Hashtable/*<String, MailAccountPrimar>*/ mailAccounts;
ClearDBSelect clearDBSelect;
private Menu menu = null;
private boolean initialised = false;
//#ifdef MUJMAIL_USR_FOLDERS
private BoxList userMailBoxes;
//#endif
Displayable lastDisplay; //last screen displayed before the application goes minimized, paused..
private MailDBSeen mailDBSeen;
private MailDBManager mailDBManager;
public static MujMail mujmail; //to get pointer to mujmail easier from anywhere
/**
* Represents the Display object. Provides more functionality than
* javax.microedition.lcdui.Display.
*
* @see javax.microedition.lcdui.Display
*
*/
public static class MyDisplay {
private final Display display;
private boolean settingCurrEnabled = true;
/**
* Creates new instance of MyDisplay.
* @param middlet the midlet that display object will be created.
*/
public MyDisplay(MIDlet middlet) {
display = Display.getDisplay(middlet);
}
/**
* Disables setting current screen. This means that calling
* {@link #setCurrent} will have no effect.
*/
public void disableSettingCurrent() {
settingCurrEnabled = false;
}
/**
* Enables setting current screen. This means that calling
* {@link #setCurrent} will set new screen as current.
*/
public void enableSettingCurrent() {
settingCurrEnabled = true;
}
/**
* Sets nextDisplayable as current screen.
*
* @param nextDisplayable Displayable object that will be setted as
* current screen.
* @see javax.microedition.lcdui.Display
*/
public void setCurrent(Displayable nextDisplayable) {
if (settingCurrEnabled) {
display.setCurrent(nextDisplayable);
}
}
/**
* Sets alert as current screen.
*
* @param alert the alert to be setted as current screen.
* @param nextDisplayable the Displayable object that will be setted
* as current screen after alert.
* @see javax.microedition.lcdui.Display
*/
public void setCurrent(Alert alert, Displayable nextDisplayable) {
if (settingCurrEnabled) display.setCurrent(alert, nextDisplayable);
}
/**
* Gets current screen.
* @return gets current screen.
* @see javax.microedition.lcdui.Display
*/
public Displayable getCurrent() {
return display.getCurrent();
}
}
public MujMail() {
if (DEBUG) { DebugConsole.printlnPersistent("MujMail() - start"); }
mujmail = this;
mailDBManager = new MailDBManager(); // Have to be created before any PersistentBox
mailDBSeen = new MailDBSeen(this);
outBox = new OutBox("OUTBOX", this, Lang.get(Lang.TB_OUTBOX));
sentBox = new PersistentBox("SENTBOX", this, Lang.get(Lang.TB_SENTBOX));
//#ifdef MUJMAIL_SEARCH
searchBox = new SearchBox(this);
//#endif
inBox = new InBox("INBOX", Lang.get(Lang.TB_INBOX));
draft = new OutBox("DRAFT", this, Lang.get(Lang.TB_DRAFT));
trash = new Trash("TRASH", this, Lang.get(Lang.TB_TRASH));
//#ifdef MUJMAIL_USR_FOLDERS
userMailBoxes = new BoxList(this);
//#endif
//#ifdef MUJMAIL_SYNC
sync = new Sync(this, new MailAccountPrimary(MailAccount.IMAP,
"login@mujmail.org",
true,
Settings.mujMailSrvAddr,
Short.parseShort(Settings.mujMailSrvPort),
Settings.mujMailSrvLogin,
Settings.mujMailSrvPasswd,
false,
(byte)0,
false,
false,
"",
""));
//#endif
mailAccounts = new Hashtable();
menu = new Menu(this);
clearDBSelect = new ClearDBSelect(this);
if (DEBUG) { DebugConsole.printlnPersistent("MujMail() - end"); };
}
public void pauseApp() {
lastDisplay = myDisplay.getCurrent();
}
public void destroyApp(boolean unconditional) {
initialised = false;
getInBox().clearLastSafeMail();
discServers(true);
notifyDestroyed();
}
public void startApp() {
if (DEBUG) { DebugConsole.printlnPersistent("MujMail.startApp - start"); };
if (!Settings.password.equals("")) {
EnterInitialPasswordForm initialPassword = new EnterInitialPasswordForm();
getDisplay().setCurrent(initialPassword);
} else {
myStartApplication();
}
if (DEBUG) { DebugConsole.printlnPersistent("MujMail.startApp - end"); };
}
/**
* The form for entering the password before starting the application.
* If the password is correct, starts the application.
* Allows user to clear all databases and than start the application without
* entering password.
*/
private class EnterInitialPasswordForm extends Form implements CommandListener {
private TextField passwordText;
private Command okCommand = new Command("OK", Command.OK, 0);
private Command cancelCommand = new Command("Exit", Command.EXIT, 1);
private Command clearAllDBCommand = new Command("Clear all databases", Command.ITEM, 2);
public EnterInitialPasswordForm() {
super("Enter password");
StringItem description = new StringItem("", "To start the application, enter the password or clear all databases with mails and settings.");
passwordText = new TextField("Password", "", 50, TextField.PASSWORD);
append(description);
append(passwordText);
addCommand(okCommand);
addCommand(cancelCommand);
addCommand(clearAllDBCommand);
setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
if (c == cancelCommand) {
destroyApp(true);
return;
}
if (c == okCommand) {
if (!Settings.password.equals(passwordText.getString())) {
return;
}
}
if (c == clearAllDBCommand) {
ClearDBSelect clearDB = new ClearDBSelect(mujmail);
clearDB.clearDataBases(true, true);
}
mainMenu();
// start the application
myStartApplication();
}
}
private void myStartApplication() {
if (DEBUG) { DebugConsole.printlnPersistent("MujMail.myStartApplication - start"); };
try {
boolean showAccountForm = false;
if (!initialised) {
//first run, initiation needed
initialised = true;
showAccountForm = getAccountSettings().getNumAccounts() > 0 ? false : true;
getSettings().initSortMode();
//#ifdef MUJMAIL_USR_FOLDERS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -