From f1fa54311dd4be8648b8dd52e8a1385308738c00 Mon Sep 17 00:00:00 2001 From: mguessan Date: Tue, 8 Sep 2009 22:25:39 +0000 Subject: [PATCH] IMAP: fix BODYSTRUCTURE, build message on full buffer, do not rely on partial buffer (header, body, ...) git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@707 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/imap/ImapConnection.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/java/davmail/imap/ImapConnection.java b/src/java/davmail/imap/ImapConnection.java index 5cd50887..d2d2b892 100644 --- a/src/java/davmail/imap/ImapConnection.java +++ b/src/java/davmail/imap/ImapConnection.java @@ -501,9 +501,7 @@ public class ImapConnection extends AbstractConnection { bodystructure = true; } else { // thunderbird : send BODYSTRUCTURE - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - message.write(baos); - appendBodyStructure(buffer, baos); + appendBodyStructure(buffer, message); } } else if ("INTERNALDATE".equals(param) && message.date != null && message.date.length() > 0) { try { @@ -524,7 +522,7 @@ public class ImapConnection extends AbstractConnection { if (bodystructure) { bodystructure = false; // Apple Mail: need to build full bodystructure - appendBodyStructure(buffer, baos); + appendBodyStructure(buffer, message); } buffer.append(" RFC822.SIZE ").append(partOutputStream.size); if ("BODY.PEEK[HEADER]".equals(param)) { @@ -563,7 +561,7 @@ public class ImapConnection extends AbstractConnection { if (bodystructure) { bodystructure = false; // Apple Mail: need to build full bodystructure - appendBodyStructure(buffer, baos); + appendBodyStructure(buffer, message); } buffer.append(" RFC822.SIZE ").append(rfc822size).append(' '); if ("BODY.PEEK[TEXT]".equals(param)) { @@ -587,7 +585,10 @@ public class ImapConnection extends AbstractConnection { sendClient(buffer.toString()); } - protected void appendBodyStructure(StringBuilder buffer, ByteArrayOutputStream baos) throws IOException { + protected void appendBodyStructure(StringBuilder buffer, ExchangeSession.Message message) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + message.write(baos); + buffer.append(" BODYSTRUCTURE "); try { MimeMessage mimeMessage = new MimeMessage(null, new ByteArrayInputStream(baos.toByteArray()));