IMAP: implement Recent flag on new messages based on read flag and creation/modification date

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1658 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2011-04-08 13:55:20 +00:00
parent 8c8ff42010
commit 54fcff3739
4 changed files with 29 additions and 3 deletions

View File

@ -708,6 +708,7 @@ public abstract class ExchangeSession {
IMAP_MESSAGE_ATTRIBUTES.add("read");
IMAP_MESSAGE_ATTRIBUTES.add("deleted");
IMAP_MESSAGE_ATTRIBUTES.add("date");
IMAP_MESSAGE_ATTRIBUTES.add("lastmodified");
}
protected static final Set<String> UID_MESSAGE_ATTRIBUTES = new HashSet<String>();
@ -1397,6 +1398,10 @@ public abstract class ExchangeSession {
* Next IMAP uid
*/
public int uidNext;
/**
* recent count
*/
public int recent;
/**
* Folder message list, empty before loadMessages call.
*/
@ -1429,6 +1434,12 @@ public abstract class ExchangeSession {
public void loadMessages() throws IOException {
messages = ExchangeSession.this.searchMessages(folderPath, null);
fixUids(messages);
recent = 0;
for (Message message:messages) {
if (message.recent) {
recent++;
}
}
}
/**
@ -1587,6 +1598,10 @@ public abstract class ExchangeSession {
* Message flag: flagged.
*/
public boolean flagged;
/**
* Message flag: recent.
*/
public boolean recent;
/**
* Message flag: draft.
*/
@ -1658,6 +1673,9 @@ public abstract class ExchangeSession {
if (deleted) {
buffer.append("\\Deleted ");
}
if (recent) {
buffer.append("\\Recent ");
}
if (flagged) {
buffer.append("\\Flagged ");
}

View File

@ -1761,6 +1761,9 @@ public class DavExchangeSession extends ExchangeSession {
message.date = convertDateFromExchange(getPropertyIfExists(properties, "date"));
message.deleted = "1".equals(getPropertyIfExists(properties, "deleted"));
String lastmodified = convertDateFromExchange(getPropertyIfExists(properties, "lastmodified"));
message.recent = !message.read && lastmodified != null && lastmodified.equals(message.date);
if (LOGGER.isDebugEnabled()) {
StringBuilder buffer = new StringBuilder();
buffer.append("Message");

View File

@ -489,6 +489,9 @@ public class EwsExchangeSession extends ExchangeSession {
message.date = convertDateFromExchange(response.get(Field.get("date").getResponseName()));
message.deleted = "1".equals(response.get(Field.get("deleted").getResponseName()));
String lastmodified = convertDateFromExchange(response.get(Field.get("lastmodified").getResponseName()));
message.recent = !message.read && lastmodified != null && lastmodified.equals(message.date);
if (LOGGER.isDebugEnabled()) {
StringBuilder buffer = new StringBuilder();
buffer.append("Message");

View File

@ -217,7 +217,7 @@ public class ImapConnection extends AbstractConnection {
currentFolder = session.getFolder(folderName);
currentFolder.loadMessages();
sendClient("* " + currentFolder.count() + " EXISTS");
sendClient("* " + currentFolder.count() + " RECENT");
sendClient("* " + currentFolder.recent + " RECENT");
sendClient("* OK [UIDVALIDITY 1]");
if (currentFolder.count() == 0) {
sendClient("* OK [UIDNEXT 1]");
@ -544,7 +544,7 @@ public class ImapConnection extends AbstractConnection {
answer.append("MESSAGES ").append(folder.count()).append(' ');
}
if ("RECENT".equalsIgnoreCase(token)) {
answer.append("RECENT ").append(folder.count()).append(' ');
answer.append("RECENT ").append(folder.recent).append(' ');
}
if ("UIDNEXT".equalsIgnoreCase(token)) {
if (folder.count() == 0) {
@ -649,7 +649,7 @@ public class ImapConnection extends AbstractConnection {
}
}
sendClient("* " + currentFolder.count() + " EXISTS");
sendClient("* " + currentFolder.count() + " RECENT");
sendClient("* " + currentFolder.recent + " RECENT");
}
private void handleFetch(ExchangeSession.Message message, int currentIndex, String parameters) throws IOException, MessagingException {
@ -1394,6 +1394,8 @@ public class ImapConnection extends AbstractConnection {
}
if (!properties.isEmpty()) {
session.updateMessage(message, properties);
// message is no longer recent
message.recent = false;
}
}