📄 inbox.java
字号:
if (mailsOnServers == -1) {
syncOK = true;
mailsOnServers = 0; //initiate the counter and indicate that sync is running
//if (Settings.minInBoxDBSpace != -1 && Functions.spaceLeft(DBFile) * 1024 < Settings.minInBoxDBSpace) {
//deleteAllMailsFromBoxAndDB(true);
//}
retrieve();
} else if (!InProtocol.isBusyGlobal()) { //second run. downloading completed.
synchronized (storage) { //lock the storage to avoid from modifying
//content of servers inboxes and our inbox are the same
if (storage.getSize() == mailsOnServers) {
mailsOnServers = -1;
return;
}
//now, markAsDeleted all the mails that are not on servers but are stored in the phone
progress.setTitle(Lang.get(Lang.ALRT_SYNCHRONIZING) + Lang.get(Lang.ALRT_WAIT));
progress.updateProgress(0, 0);
MessageHeader message;
int toDelete = storage.getSize() - mailsOnServers;
MailAccount account;
Enumeration messages = storage.getEnumeration();
while ( messages.hasMoreElements() ) {
message = (MessageHeader) messages.nextElement();
account = (MailAccount) getMujMail().getMailAccounts().get(message.getAccountID());
//the mail is not on the servers anymore, only on the mobile from previous sessions
if (account != null && account.isActive() && !account.getProtocol().containsMail(message)) {
if (!message.deleted) {
++deleted;
message.deleted = true;
}
if (--toDelete == 0) {
break;
}
}
}
mailsOnServers = -1;
}
deleteMarkedFromBoxAndDB();//also markAsDeleted the mails that were marked in the inbox.
}
}
}
/**
* @return true if there is any account to retriveve by instance of box, false otherwise
*/
public boolean hasAccountToRetrieve() {
return accounts.size() > 0;
}
//#ifdef MUJMAIL_USR_FOLDERS
/** Persistently save (and actualize) set of accounts
* that should be retrived by instance of InBox */
public void saveBoxRetrieveAccounts(Vector/*<MailAccount>*/ newAccounts) {
if (accounts == null) {
return;
}
accounts = newAccounts;
RetrieveBoxAccountsTask saveTask = new RetrieveBoxAccountsTask(RetrieveBoxAccountsTask.ACCOUNTS_SAVE);
saveTask.start();
}
//#endif
/**
* Get list of accounts that retrieve this box
* @return Vector of accout to be retrieve by box
*/
public Vector/*<MailAccount>*/ getAccounts() {
return accounts;
}
/**
* Changes box to retrieve all active mail accounts.
* Note: Call if this folder is set (unset) as default mujMail Inbox folder.
*/
public void actualizeActiveAccountList() {
accounts.removeAllElements();
for (Enumeration e = getMujMail().getMailAccounts().elements(); e.hasMoreElements();) {
MailAccount account = (MailAccount) e.nextElement();
if (account.isActive()) {
accounts.addElement( account);
}
}
}
/**
* Retrieves new mails from all accounts.
* Starts retrieving mails in new thread. Does not retrieve mails from all
* accounts simultaneously, but serializes retrieving mails.
*/
public void retrieve() {
Thread thread = new Thread() {
public void run() {
if (!hasAccountToRetrieve()) {
getMujMail().alert.setAlert(this, null, Lang.get(Lang.ALRT_AS_NO_ACCOUNT_SET_ACTIVE), MyAlert.DEFAULT, AlertType.WARNING);
}
//if (Settings.minInBoxDBSpace != -1 && Functions.spaceLeft(DBFile) * 1024 < Settings.minInBoxDBSpace) {
//deleteAllMailsFromBoxAndDB(true);
//}
setNeedResort(true);
for (Enumeration e = accounts.elements(); e.hasMoreElements();) {
MailAccount account = (MailAccount) e.nextElement();
InProtocol.waitForNotBusyGlobal();
account.getProtocol().getNewMails(InBox.this);
}
}
};
thread.start();
}
//from one account
public void retrieveOne(String accountID) {
if (accountID != null && getMujMail().getMailAccounts().get(accountID) != null) {
MailAccount account = (MailAccount) getMujMail().getMailAccounts().get(accountID);
if (account.isActive()) {
//if (Settings.minInBoxDBSpace != -1 && Functions.spaceLeft(DBFile) * 1024 < Settings.minInBoxDBSpace) {
//deleteAllMailsFromBoxAndDB(true);
//}
setNeedResort(true);
account.getProtocol().getNewMails(this);
} else {
getMujMail().alert.setAlert(this, null, accountID + " " + Lang.get(Lang.INACTIVE), MyAlert.DEFAULT, AlertType.WARNING);
}
}
}
/** Try to found Mail account with which we download this email
*
* @param header Mail header which account we are interesting
* @return Mail account where email come from.
*/
private MailAccount findAccountForHeader(MessageHeader header) {
if (header == null) {
return null;
}
// First step look in accounts of this box
for(Enumeration e = getAccounts().elements(); e.hasMoreElements(); ) {
MailAccount account = (MailAccount)e.nextElement();
if (account.getEmail().equals(header.getAccountID())) {
// Found correct acocunt
return account;
}
}
// Second step (box settings changed or mail moved)
MailAccount account = (MailAccount) getMujMail().getMailAccounts().get(header.getAccountID());
if (account == null) { //all ready deleted account (account renamed, ...)
return null;
}
return account;
}
/**
* Downloads a body of the mail given by header.
* @param header the header of mail which body will be deleted
*/
public void getBody(MessageHeader header) {
MailAccount account = findAccountForHeader(header);
if (account == null) {
getMujMail().alert.setAlert(this, null, Lang.get(Lang.ALRT_AS_NONEXIST) + ": " + header.getAccountID(), MyAlert.DEFAULT, AlertType.WARNING);
synchronized (header) {
header.notify();
}
return;
}
if (Settings.safeMode) //we are reusing the lastSafeMail DBfile
{
clearLastSafeMail();
}
account.getProtocol().getBody(header, this);
}
/**
* Redownloads a mail.
* @param header identifies the mail which will be redownloaded
* @param mode value -1 for redownloading the whole mail
* higher values for a concrete bodypart
*/
public void regetBody(MessageHeader header, byte mode) {
MailAccount account = findAccountForHeader(header);
if (account == null) {
getMujMail().alert.setAlert(this, null, Lang.get(Lang.ALRT_AS_NONEXIST) + ": " + header.getAccountID(), MyAlert.DEFAULT, AlertType.WARNING);
if (mode != -1) { //if we just wanted to redownload a particular bodypart,
synchronized (header) {
header.notify();// then we should wake up the mailForm, which triggered this procedure
}
}
return;
}
if (Settings.safeMode) {
clearLastSafeMail();
}
account.getProtocol().regetBody(header, mode, this);
}
public void clearLastSafeMail() {
if (getLastSafeMail() != null) {
try {
mailDB.clearDb(false); // TODO Alf - work in no safe mode select? ... safe mode detection
} catch (Exception ex) {
}
getLastSafeMail().deleteAllBodyParts();
try {
getMailDB().saveHeader(getLastSafeMail()); //update new info that the mail no longer has some content
} catch (Exception ex) {
}
setLastSafeMail(null);
}
}
/**
* Delete all mails a databases that uses InBox.
* Note: Used if removing user mailbox from mujMail
*/
public void removeAllDBs() {
try {
mailDB.clearDb(true);
} catch (Exception ex) {
// Some deleting failed ... typically database was not created
if (DEBUG) { System.out.println("DEBUG InBox.removeAllDBs - cleardb problem"); ex.printStackTrace(); }
}
//#ifdef MUJMAIL_USR_FOLDERS
try {
// remove accounts database (acount list to retrieve)
RecordStore.deleteRecordStore(getDBFileName() + "_ACC");
} catch (Exception ex) {
if (DEBUG) { System.out.println("DEBUG InBox.removeAllDBs - accounts db problem"); ex.printStackTrace(); }
}
//#endif
}
public void deleteAllMailsFromBoxAndDB(boolean sure) {
super.deleteAllMailsFromBoxAndDB(sure);
if (sure) {
setLastSafeMail(null);
if ( msgIDs != null ) {
msgIDs.clear();
}
unreadMails = 0;
}
}
/**
* Deletes mails from inbox and from database.
* If Settings.moveToTrash is true and Settings.safeMode is false, moves
* mails to the thrash.
* If Settings.delMailFromServer is true, deletes mails from mails server
* as well.
*/
public void deleteMarkedFromBoxAndDB() {
MessageHeader header;
MailAccount account;
int x = 0;
//lets take all the mails that were marked as read
synchronized (storage) {
Enumeration messages = storage.getEnumeration();
while ( messages.hasMoreElements() ) {
header = (MessageHeader) messages.nextElement();
if (header.deleted) {
msgIDs.remove(header.getAccountID() + "@" + header.getMessageID());
if (header.readStatus == MessageHeader.NOT_READ) {
--unreadMails;
}
if (Settings.delMailFromServer) {
account = (MailAccount) getMujMail().getMailAccounts().get(header.getAccountID());
//get appropriate mailAccount
if (account != null && account.isActive()) {
account.getProtocol().addDeleted(header);
} //put them to apropriate servers list
}
++x;
}
if (x == deleted) //if we detected all deleted mails, we can end it here
{
break;
}
}
}
if (!isSyncRunning() && Settings.delMailFromServer) {
for (Enumeration e = getMujMail().getMailAccounts().elements(); e.hasMoreElements();) {
account = (MailAccount) e.nextElement();
if (account.isActive()) {
account.getProtocol().removeMsgs(this);
}
}
}
super.deleteMarkedFromBoxAndDB(); //markAsDeleted them from DB and storage vector
}
protected void hideButtons() {
if (InProtocol.isBusyGlobal()) {
addCommand(stop);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -