diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 125b5b23..89e83500 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -1664,16 +1664,16 @@ public abstract class ExchangeSession { } /** - * Get current folder messages imap uids + * Get current folder messages imap uids and flags * * @return imap uid list */ - public List getImapUidList() { - ArrayList imapUidList = new ArrayList(); + public TreeMap getImapFlagMap() { + TreeMap imapFlagMap = new TreeMap(); for (ExchangeSession.Message message : messages) { - imapUidList.add(message.getImapUid()); + imapFlagMap.put(message.getImapUid(), message.getImapFlags()); } - return imapUidList; + return imapFlagMap; } /** diff --git a/src/java/davmail/imap/ImapConnection.java b/src/java/davmail/imap/ImapConnection.java index cdcb0cf3..b42004e7 100644 --- a/src/java/davmail/imap/ImapConnection.java +++ b/src/java/davmail/imap/ImapConnection.java @@ -517,9 +517,9 @@ public class ImapConnection extends AbstractConnection { while (in.available() == 0) { if (++count >= imapIdleDelay) { count = 0; - List previousImapUidList = currentFolder.getImapUidList(); + TreeMap previousImapFlagMap = currentFolder.getImapFlagMap(); if (session.refreshFolder(currentFolder)) { - handleRefresh(previousImapUidList, currentFolder.getImapUidList()); + handleRefresh(previousImapFlagMap, currentFolder.getImapFlagMap()); } } // sleep 1 second @@ -542,9 +542,9 @@ public class ImapConnection extends AbstractConnection { } else if ("noop".equalsIgnoreCase(command) || "check".equalsIgnoreCase(command)) { if (currentFolder != null) { DavGatewayTray.debug(new BundleMessage("LOG_IMAP_COMMAND", command, currentFolder.folderPath)); - List previousImapUidList = currentFolder.getImapUidList(); + TreeMap previousImapFlagMap = currentFolder.getImapFlagMap(); if (session.refreshFolder(currentFolder)) { - handleRefresh(previousImapUidList, currentFolder.getImapUidList()); + handleRefresh(previousImapFlagMap, currentFolder.getImapFlagMap()); } } sendClient(commandId + " OK " + command + " completed"); @@ -691,16 +691,21 @@ public class ImapConnection extends AbstractConnection { * @param imapUidList uid list after refresh * @throws IOException on error */ - private void handleRefresh(List previousImapUidList, List imapUidList) throws IOException { - // + private void handleRefresh(TreeMap previousImapFlagMap, TreeMap imapFlagMap) throws IOException { + // send deleted message expunge notification int index = 1; - for (long previousImapUid : previousImapUidList) { - if (!imapUidList.contains(previousImapUid)) { + for (long previousImapUid : previousImapFlagMap.keySet()) { + if (!imapFlagMap.keySet().contains(previousImapUid)) { sendClient("* " + index + " EXPUNGE"); } else { + // send updated flags + if (!previousImapFlagMap.get(previousImapUid).equals(imapFlagMap.get(previousImapUid))) { + sendClient("* " + index + " FETCH (UID "+previousImapUid+" FLAGS ("+imapFlagMap.get(previousImapUid)+"))"); + } index++; } } + sendClient("* " + currentFolder.count() + " EXISTS"); sendClient("* " + currentFolder.recent + " RECENT"); }