1
0
mirror of https://github.com/moparisthebest/davmail synced 2025-01-12 05:58:48 -05:00

IMAP: improve BODYSTRUCTURE implementation, make it recursive

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1444 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-09-14 13:42:48 +00:00
parent c404972d37
commit 0d29cee702
2 changed files with 31 additions and 17 deletions

View File

@ -938,23 +938,7 @@ public class ImapConnection extends AbstractConnection {
MimeMessage mimeMessage = message.getMimeMessage();
Object mimeBody = mimeMessage.getContent();
if (mimeBody instanceof MimeMultipart) {
buffer.append('(');
MimeMultipart multiPart = (MimeMultipart) mimeBody;
for (int i = 0; i < multiPart.getCount(); i++) {
MimeBodyPart bodyPart = (MimeBodyPart) multiPart.getBodyPart(i);
appendBodyStructure(buffer, bodyPart);
}
int slashIndex = multiPart.getContentType().indexOf('/');
if (slashIndex < 0) {
throw new DavMailException("EXCEPTION_INVALID_CONTENT_TYPE", multiPart.getContentType());
}
int semiColonIndex = multiPart.getContentType().indexOf(';');
if (semiColonIndex < 0) {
buffer.append(" \"").append(multiPart.getContentType().substring(slashIndex + 1).toUpperCase()).append("\")");
} else {
buffer.append(" \"").append(multiPart.getContentType().substring(slashIndex + 1, semiColonIndex).trim().toUpperCase()).append("\")");
}
appendBodyStructure(buffer, (MimeMultipart) mimeBody);
} else {
// no multipart, single body
appendBodyStructure(buffer, mimeMessage);
@ -970,6 +954,31 @@ public class ImapConnection extends AbstractConnection {
}
}
protected void appendBodyStructure(StringBuilder buffer, MimeMultipart multiPart) throws IOException, MessagingException {
buffer.append('(');
for (int i = 0; i < multiPart.getCount(); i++) {
MimeBodyPart bodyPart = (MimeBodyPart) multiPart.getBodyPart(i);
Object mimeBody = bodyPart.getContent();
if (mimeBody instanceof MimeMultipart) {
appendBodyStructure(buffer, (MimeMultipart) mimeBody);
} else {
// no multipart, single body
appendBodyStructure(buffer, bodyPart);
}
}
int slashIndex = multiPart.getContentType().indexOf('/');
if (slashIndex < 0) {
throw new DavMailException("EXCEPTION_INVALID_CONTENT_TYPE", multiPart.getContentType());
}
int semiColonIndex = multiPart.getContentType().indexOf(';');
if (semiColonIndex < 0) {
buffer.append(" \"").append(multiPart.getContentType().substring(slashIndex + 1).toUpperCase()).append("\")");
} else {
buffer.append(" \"").append(multiPart.getContentType().substring(slashIndex + 1, semiColonIndex).trim().toUpperCase()).append("\")");
}
}
protected void appendBodyStructure(StringBuilder buffer, MimePart bodyPart) throws IOException, MessagingException {
String contentType = bodyPart.getContentType();
int slashIndex = contentType.indexOf('/');

View File

@ -98,6 +98,11 @@ public class TestImap extends AbstractDavMailTestCase {
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
}
public void testFetchBodyStructure() throws IOException {
writeLine(". UID FETCH 1:* (FLAGS BODYSTRUCTURE)");
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
}
public void testUidSearchUnDeleted() throws IOException {
writeLine(". UID SEARCH UNDELETED");
assertEquals(". OK SEARCH completed", readFullAnswer("."));