From d3aa6871249da3ae93bbb14f0fd6369427a34430 Mon Sep 17 00:00:00 2001 From: mguessan Date: Fri, 27 Mar 2009 09:07:03 +0000 Subject: [PATCH] IMAP: refactor BODYSTRUCTURE generation git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@479 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/imap/ImapConnection.java | 43 +++++++++++------------ 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/java/davmail/imap/ImapConnection.java b/src/java/davmail/imap/ImapConnection.java index 25999dc6..d58fb341 100644 --- a/src/java/davmail/imap/ImapConnection.java +++ b/src/java/davmail/imap/ImapConnection.java @@ -609,31 +609,30 @@ public class ImapConnection extends AbstractConnection { buffer.append(" ()"); } } - // body id - if (bodyPart.getContentID() == null) { - buffer.append(" NIL"); - } else { - buffer.append(" \"").append(bodyPart.getContentID()).append("\""); - } - if (bodyPart.getDescription() == null) { - buffer.append(" NIL"); - } else { - buffer.append(" \"").append(bodyPart.getDescription()).append("\""); - } - if (bodyPart.getHeader("Content-Transfer-Encoding") == null) { - buffer.append(" NIL"); - } else { - buffer.append(" \"").append(bodyPart.getEncoding().toUpperCase()).append("\""); - } - buffer.append(' ').append(bodyPart.getSize()); - if (bodyPart.getLineCount() < 0) { - buffer.append(" NIL"); - } else { - buffer.append(' ').append(bodyPart.getLineCount()).append('"'); - } + appendBodyStructureValue(buffer, bodyPart.getContentID()); + appendBodyStructureValue(buffer, bodyPart.getDescription()); + appendBodyStructureValue(buffer, bodyPart.getEncoding()); + appendBodyStructureValue(buffer, bodyPart.getSize()); + appendBodyStructureValue(buffer, bodyPart.getLineCount()); buffer.append(')'); } + protected void appendBodyStructureValue(StringBuilder buffer, String value) throws IOException, MessagingException { + if (value == null) { + buffer.append(" NIL"); + } else { + buffer.append(" \"").append(value.toUpperCase()).append("\""); + } + } + + protected void appendBodyStructureValue(StringBuilder buffer, int value) throws IOException, MessagingException { + if (value < 0) { + buffer.append(" NIL"); + } else { + buffer.append(' ').append(value); + } + } + static final class SearchConditions { Boolean flagged = null; Boolean answered = null;