1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-14 03:32:22 -05:00

IMAP: update message flag only if changed to avoid unneeded message uid bump, may fix Evolution and Apple Mail constant reload issue

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@800 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-10-29 12:56:37 +00:00
parent 51c843de93
commit 24d7399555

View File

@ -925,16 +925,16 @@ public class ImapConnection extends AbstractConnection {
StringTokenizer flagtokenizer = new StringTokenizer(flags); StringTokenizer flagtokenizer = new StringTokenizer(flags);
while (flagtokenizer.hasMoreTokens()) { while (flagtokenizer.hasMoreTokens()) {
String flag = flagtokenizer.nextToken(); String flag = flagtokenizer.nextToken();
if ("\\Seen".equals(flag)) { if ("\\Seen".equals(flag) && message.read) {
properties.put("read", "0"); properties.put("read", "0");
message.read = false; message.read = false;
} else if ("\\Flagged".equals(flag)) { } else if ("\\Flagged".equals(flag) && message.flagged) {
properties.put("flagged", "0"); properties.put("flagged", "0");
message.flagged = false; message.flagged = false;
} else if ("\\Deleted".equals(flag)) { } else if ("\\Deleted".equals(flag) && message.deleted) {
properties.put("deleted", null); properties.put("deleted", null);
message.deleted = false; message.deleted = false;
} else if ("Junk".equals(flag)) { } else if ("Junk".equals(flag) && message.junk) {
properties.put("junk", "0"); properties.put("junk", "0");
message.junk = false; message.junk = false;
} }
@ -943,56 +943,100 @@ public class ImapConnection extends AbstractConnection {
StringTokenizer flagtokenizer = new StringTokenizer(flags); StringTokenizer flagtokenizer = new StringTokenizer(flags);
while (flagtokenizer.hasMoreTokens()) { while (flagtokenizer.hasMoreTokens()) {
String flag = flagtokenizer.nextToken(); String flag = flagtokenizer.nextToken();
if ("\\Seen".equals(flag)) { if ("\\Seen".equals(flag) && !message.read) {
properties.put("read", "1"); properties.put("read", "1");
message.read = true; message.read = true;
} else if ("\\Deleted".equals(flag)) { } else if ("\\Deleted".equals(flag) && !message.deleted) {
message.deleted = true; message.deleted = true;
properties.put("deleted", "1"); properties.put("deleted", "1");
} else if ("\\Flagged".equals(flag)) { } else if ("\\Flagged".equals(flag) && !message.flagged) {
properties.put("flagged", "2"); properties.put("flagged", "2");
message.flagged = true; message.flagged = true;
} else if ("\\Answered".equals(flag)) { } else if ("\\Answered".equals(flag) && !message.answered) {
properties.put("answered", "102"); properties.put("answered", "102");
message.answered = true; message.answered = true;
} else if ("$Forwarded".equals(flag)) { } else if ("$Forwarded".equals(flag) && !message.forwarded) {
properties.put("forwarded", "104"); properties.put("forwarded", "104");
message.forwarded = true; message.forwarded = true;
} else if ("Junk".equals(flag)) { } else if ("Junk".equals(flag) && !message.junk) {
properties.put("junk", "1"); properties.put("junk", "1");
message.junk = true; message.junk = true;
} }
} }
} else if ("FLAGS".equalsIgnoreCase(action) || "FLAGS.SILENT".equalsIgnoreCase(action)) { } else if ("FLAGS".equalsIgnoreCase(action) || "FLAGS.SILENT".equalsIgnoreCase(action)) {
properties.put("read", "0"); // flag list with default values
message.read = false; boolean read = false;
properties.put("flagged", "0"); boolean deleted = false;
message.flagged = false; boolean junk = false;
properties.put("junk", "0"); boolean flagged = false;
message.junk = false; boolean answered = false;
properties.put("deleted", null); boolean forwarded = false;
message.deleted = false; // set flags from new flag list
StringTokenizer flagtokenizer = new StringTokenizer(flags); StringTokenizer flagtokenizer = new StringTokenizer(flags);
while (flagtokenizer.hasMoreTokens()) { while (flagtokenizer.hasMoreTokens()) {
String flag = flagtokenizer.nextToken(); String flag = flagtokenizer.nextToken();
if ("\\Seen".equals(flag)) { if ("\\Seen".equals(flag)) {
properties.put("read", "1"); read = true;
message.read = true;
} else if ("\\Deleted".equals(flag)) { } else if ("\\Deleted".equals(flag)) {
message.deleted = true; deleted = true;
properties.put("deleted", "1");
} else if ("\\Flagged".equals(flag)) { } else if ("\\Flagged".equals(flag)) {
properties.put("flagged", "2"); flagged = true;
message.flagged = true;
} else if ("\\Answered".equals(flag)) { } else if ("\\Answered".equals(flag)) {
properties.put("answered", "102"); answered = true;
message.answered = true;
} else if ("$Forwarded".equals(flag)) { } else if ("$Forwarded".equals(flag)) {
properties.put("forwarded", "104"); forwarded = true;
message.forwarded = true;
} else if ("Junk".equals(flag)) { } else if ("Junk".equals(flag)) {
junk = true;
}
}
if (read != message.read) {
message.read = read;
if (message.read) {
properties.put("read", "1");
} else {
properties.put("read", "0");
}
}
if (deleted != message.deleted) {
message.deleted = deleted;
if (message.deleted) {
properties.put("deleted", "1");
} else {
properties.put("deleted", null);
}
}
if (flagged != message.flagged) {
message.flagged = flagged;
if (message.flagged) {
properties.put("flagged", "2");
} else {
properties.put("flagged", "0");
}
}
if (answered != message.answered) {
message.answered = answered;
if (message.answered) {
properties.put("answered", "102");
} else if (!forwarded) {
// remove property only if not forwarded
properties.put("answered", null);
}
}
if (forwarded != message.forwarded) {
message.forwarded = forwarded;
if (message.forwarded) {
properties.put("forwarded", "104");
} else if (!answered) {
// remove property only if not answered
properties.put("forwarded", null);
}
}
if (junk != message.junk) {
message.junk = junk;
if (message.junk) {
properties.put("junk", "1"); properties.put("junk", "1");
message.junk = true; } else {
properties.put("junk", "0");
} }
} }
} }