📄 mailsynclistener.java
字号:
public void endReceiving() {
Log.debug(this, "End receiving");
toReceive = 0;
}
public void itemDeleted(Object item) {
Log.debug(this, "Item deleted");
String key = (String) item;
//if message is in inbox, we delete it.
UIController.getInboxMessageList().deleteMessage(key);
}
public void itemUpdated(Object item, Object update) {
Log.debug(this, "Item updated by msgFlagsUpdated");
// In some case the source does not perform the update and passes over
// a null update object. In these cases we do not have to update
// anything, so we ignore this event
if (update == null) {
return;
}
String key = (String) item;
MessageFlags newFlags = (MessageFlags) update;
//if message is in inbox, we update the flags
UIController.getInboxMessageList().updateMessageFlags(key, newFlags);
}
public void itemUpdated(Object item) {
String key = (String) item;
String folder = MessageManager.getInstance().folderFromKey(key);
// We only update items in the INBOX
if (Store.INBOX.equals(folder)) {
//MessageFlags newMask = FlagQueue.get(key);
//if (newMask != null && (!newMask.isSet(MessageFlags.DELETED))) {
Store store = StoreFactory.getStore();
Folder inbox = store.getFolder(Store.INBOX);
MessageManager mm = MessageManager.getInstance();
Message msg = mm.getMessage(inbox, key);
if (msg != null) {
MessageFlags newFlags = msg.getFlags();
UIController.getInboxMessageList().updateMessageFlags(key,
newFlags);
} else {
Log.info("[MailSyncListener] Message not found: " +
"It could have been deleted");
}
}
/*if (Store.INBOX.equals(folder)) {
MessageFlags newMask = FlagQueue.get(key);
if (newMask != null && (!newMask.isSet(MessageFlags.DELETED))) {
Store store = StoreFactory.getStore();
Folder inbox = store.getFolder(Store.INBOX);
MessageManager mm = MessageManager.getInstance();
Message msg = mm.getMessage(inbox, key);
MessageFlags newFlags = msg.getFlags();
UIController.getInboxMessageList().updateMessageFlags(key,
newFlags);
}
}*/
}
public void startSending(int numNewItems, int numUpdItems, int numDelItems) {
Log.debug(this, "Start sending (" + numNewItems + "," + numUpdItems + "," + numDelItems + ")");
toSend = numNewItems;
//if we have something NEW to send. Other changes do not trigger the
//SENDING message. In the future we may display a send updates msg
if (toSend != 0 && firstSend) {
// The number of items to be sent does not correspond to the number
// of emails to be sent, but rather to the number of total changes.
// Since this number can be misleading, at the moment we just
// display a generic sending message
String userInfoMessage = Localization.getMessages().SENDING_DOTTED;
// TODO Is this really necessary? can we be outside a session???
UIController.enableSyncCommands(false);
UIController.updateInboxMessageList(userInfoMessage);
}
}
public void itemAddSent(Object item) {
// SyncItem syncItem = (SyncItem) item;
Log.debug(this, "New item sent");
String msg;
if (toSend > 0) {
// If the overall number of new items to send is known we show the
// it in the message
msg = Localization.getMessages().getSENDINGX_OF_Y(++sent, toSend);
} else {
msg = Localization.getMessages().getSENDINGX(++sent);
}
UIController.updateInboxMessageList(msg);
}
public void endSending() {
Log.debug(this, "End sending");
toSend = 0;
firstSend = false;
// TODO Why don't we re-enable the sync commands??? I think this must be
// consistent with the above
// We do not update the title here and wait for it to be rewritten at
// the beginning of the receving phase. This way we avoid an annoying
// transition Loading --> Inbox --> Loading and we keep the Loading.
}
public void dataReceived(String date, int size) {
Log.debug(this, "Data received");
// date like Thu, 03 May 2007 14:45:38 GMT
try {
if (!ConfigManager.getConfig().getTimeZoneUpdated()) {
Date gmtServerdate = MailDateFormatter.parseRfc2822Date(date);
Date deviceDate = new Date();
int millisServerDate = (int) gmtServerdate.getTime();
int millisDeviceDate = (int) deviceDate.getTime();
int hourServer = (int) (millisServerDate / 3600000); //60*60*1000
int hourDevice = (int) (millisDeviceDate / 3600000); //60*60*1000
int hourDiff = hourDevice - hourServer;
int minServer = (int) (millisServerDate / 60000); //60*60*1000
int minDevice = (int) (millisDeviceDate / 60000); //60*60*1000
int minDiff = minDevice - minServer - (hourDiff * 60);
StringBuffer offset = new StringBuffer();
offset.append((hourDiff > 0) ? "+" : "-");
int mathHourDiff = (Math.abs(hourDiff));
offset.append((mathHourDiff <= 9) ? "0" + mathHourDiff : "" + mathHourDiff);
int mathMinDiff = (Math.abs(minDiff));
if (mathMinDiff <= 20 || mathMinDiff >= 55) {
offset.append("00");
} else if (mathMinDiff > 20 || mathMinDiff < 40) {
offset.append("30");
} else if (mathMinDiff >= 40 || mathMinDiff < 55) {
offset.append("45");
}
// Save the new config.
ConfigManager.getConfig().setTimeZone(offset.toString());
ConfigManager.saveConfig();
}
} catch (ConfigException cex) {
Log.error(this, "dataReceived - " + cex.toString());
} catch (IOException ioex) {
Log.error(this, "dataReceived - " + ioex.toString());
}
}
/**
* @return an error string based on the error status received
*/
private static String getErrorMessage(int status) {
Log.debug("Getting Error Message from error status: [" + status + "]");
String message;
switch (status) {
case SyncSource.STATUS_CONNECTION_ERROR:
message = Localization.getMessages().ACCOUNT_LISTENER_ERROR_CONNECTIONG;
break;
case SyncSource.STATUS_RECV_ERROR:
message = Localization.getMessages().ACCOUNT_LISTENER_ERROR_RECEIVING;
break;
case SyncSource.STATUS_SEND_ERROR:
message = Localization.getMessages().ACCOUNT_LISTENER_ERROR_SENDING;
break;
case SyncSource.STATUS_SERVER_ERROR:
message = Localization.getMessages().ACCOUNT_LISTENER_ERROR_FROM_SERVER;
break;
default:
message = Localization.getMessages().ACCOUNT_LISTENER_ERROR_DEFAULT;
break;
}
return message;
}
/**
* This method does not belong to the SyncListener interface.
* A multi session is a concept introduced by the SyncClient which is able
* to perform the sync of multiple repositories.
*
* @param repositories repositories to be synchronized
*/
public void startMultiSession(boolean repositories[]) {
initializeSession();
multisession = true;
}
/**
* This method does not belong to the SyncListener interface.
* A multi session is a concept introduced by the SyncClient which is able
* to perform the sync of multiple repositories.
*
*/
public void endMultiSession() {
// At the end of the multisession we must reset the Inbox title with the
// number of new messages received
finalizeSession();
multisession = false;
}
private void finalizeSession() {
//String userInfoMessage;
if (status != SyncSource.STATUS_SUCCESS && status == SyncSource.STATUS_SEND_ERROR) {
//userInfoMessage = getErrorMessage(status);
UIController.showErrorAlert(getErrorMessage(status), UIController.getInboxMessageList());
}
//else {
// userInfoMessage = Localization.getMessages().getX_MESSAGES_RECEIVED(received);
//UIController.updateInboxMessageList(Localization.getMessages().getX_MESSAGES_RECEIVED(received));
//}
// Update the title
//UIController.updateInboxMessageList(userInfoMessage);
UIController.updateInboxMessageList(Localization.getMessages().getX_MESSAGES_RECEIVED(received));
UIController.enableSyncCommands(true);
}
private void init() {
received = 0;
sent = 0;
toReceive = ITEMS_NUMBER_UNKNOWN;
toSend = ITEMS_NUMBER_UNKNOWN;
alerted = false;
multisession = false;
firstSend = true;
isFirstMessageReceived = true;
}
public class SlowSyncPopupAction implements PopupAction {
private boolean okToSlowSync;
private boolean actionPerformed = false;
public SlowSyncPopupAction() {
}
public void cancel() {
okToSlowSync=false;
actionPerformed = true;
synchronized(this) {
this.notifyAll();
}
}
public void confirm() {
Log.info("User Confirmed slow sync action...");
okToSlowSync=true;
actionPerformed = true;
synchronized(this) {
this.notifyAll();
}
}
public boolean isOkToSlowSync() {
return okToSlowSync;
}
public boolean isActionPerformed() {
return actionPerformed;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -