From ba7619b5cff0e42590996b6b4af649e5d00a157f Mon Sep 17 00:00:00 2001 From: mguessan Date: Tue, 9 Apr 2013 21:39:18 +0000 Subject: [PATCH] IMAP: exclude Mutt header request from size optimization git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2084 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/imap/ImapConnection.java | 4 ++- src/test/davmail/imap/TestImap.java | 37 +++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/java/davmail/imap/ImapConnection.java b/src/java/davmail/imap/ImapConnection.java index c211c53d..772fba7d 100644 --- a/src/java/davmail/imap/ImapConnection.java +++ b/src/java/davmail/imap/ImapConnection.java @@ -726,7 +726,9 @@ public class ImapConnection extends AbstractConnection { buffer.append(" FLAGS (").append(message.getImapFlags()).append(')'); } else if ("RFC822.SIZE".equals(param)) { int size; - if (parameters.indexOf("BODY.PEEK[HEADER.FIELDS (") >= 0) { + if (parameters.indexOf("BODY.PEEK[HEADER.FIELDS (") >= 0 + // exclude mutt header request + && parameters.indexOf("X-LABEL") < 0) { // Header request, send approximate size size = message.size; } else { diff --git a/src/test/davmail/imap/TestImap.java b/src/test/davmail/imap/TestImap.java index 2d93aa11..045fb242 100644 --- a/src/test/davmail/imap/TestImap.java +++ b/src/test/davmail/imap/TestImap.java @@ -19,6 +19,7 @@ package davmail.imap; import davmail.Settings; +import davmail.exchange.ExchangeSession; import javax.mail.MessagingException; import javax.mail.Session; @@ -26,6 +27,9 @@ import javax.mail.internet.MimeMessage; import javax.mail.util.SharedByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Locale; import java.util.Random; /** @@ -34,6 +38,14 @@ import java.util.Random; @SuppressWarnings({"JavaDoc", "UseOfSystemOutOrSystemErr"}) public class TestImap extends AbstractImapTestCase { + protected String getLastMonth() { + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -1); + SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH); + formatter.setTimeZone(ExchangeSession.GMT_TIMEZONE); + return formatter.format(calendar.getTime()); + } + public void testListFolders() throws IOException { writeLine(". LSUB \"\" \"*\""); assertEquals(". OK LSUB completed", readFullAnswer(".")); @@ -451,4 +463,29 @@ public class TestImap extends AbstractImapTestCase { assertEquals(". OK UID FETCH completed", readFullAnswer(".")); } + public void testFetchHeadersInboxMutt() throws IOException { + writeLine(". SELECT INBOX"); + assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer(".")); + writeLine(". UID SEARCH (SINCE \""+getLastMonth()+"\")"); + String messageLine = readLine(); + int uidIndex = messageLine.indexOf(" ", "* SEARCH".length()) + 1; + messageUid = messageLine.substring(uidIndex, messageLine.indexOf(' ', uidIndex)); + assertEquals(". OK SEARCH completed", readFullAnswer(".")); + System.out.println(messageUid); + writeLine(". UID FETCH "+messageUid+":* (UID FLAGS INTERNALDATE RFC822.SIZE BODY.PEEK[HEADER.FIELDS (DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL)])"); + assertEquals(". OK UID FETCH completed", readFullAnswer(".")); + } + + public void testFetchHeadersInboxOSX() throws IOException { + writeLine(". SELECT INBOX"); + assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer(".")); + writeLine(". UID SEARCH (SINCE \""+getLastMonth()+"\")"); + String messageLine = readLine(); + int uidIndex = messageLine.indexOf(" ", "* SEARCH".length()) + 1; + messageUid = messageLine.substring(uidIndex, messageLine.indexOf(' ', uidIndex)); + assertEquals(". OK SEARCH completed", readFullAnswer(".")); + System.out.println(messageUid); + writeLine(". UID FETCH "+messageUid+":* (INTERNALDATE UID RFC822.SIZE FLAGS BODY.PEEK[HEADER.FIELDS (date subject from to cc message-id in-reply-to references x-priority x-uniform-type-identifier x-universally-unique-identifier received-spf x-spam-status x-spam-flag)])"); + assertEquals(". OK UID FETCH completed", readFullAnswer(".")); + } }