Skip to content

Commit

Permalink
IMAP Content-Type differs POP3 and IMAP (fixes #706)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelmay committed Apr 13, 2024
1 parent 48ef91d commit 1464cc2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,22 +479,19 @@ String parseBodyStructure(boolean includeExtension) {
String fields = parseBodyFields();
StringBuilder buf = new StringBuilder();
buf.append(LB);
if (primaryType.equalsIgnoreCase("Text")) {
buf.append("\"TEXT\" \"");
buf.append(secondaryType.toUpperCase());
buf.append("\" ");
buf.append(fields);
buf.append(' ');
buf.append(lineCount);
if (primaryType.equalsIgnoreCase("TEXT")) {
buf.append('"').append(primaryType).append("\" \"")
.append(secondaryType).append("\" ")
.append(fields)
.append(' ')
.append(lineCount);

// is: * 1 FETCH (BODYSTRUCTURE ("Text" "plain" NIL NIL NIL NIL 4 -1))
// wants: * 1 FETCH (BODYSTRUCTURE ("text" "plain" NIL NIL NIL "8bit" 6 1 NIL NIL NIL))
// or: * 1 FETCH (BODYSTRUCTURE ("text" "plain" NIL NIL NIL "7bit" 28 1 NIL NIL NIL))

} else if (primaryType.equalsIgnoreCase(MESSAGE) && secondaryType.equalsIgnoreCase("rfc822")) {
buf.append("\"MESSAGE\" \"RFC822\" ");
buf.append(fields).append(SP);
// setupLogger(parts[0]); // reset transient logger
buf.append(parts[0].getEnvelope()).append(SP);
buf.append(parts[0].getBodyStructure(false)).append(SP);
buf.append(lineCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void fetchEmailWithInlineAttachment() throws MessagingException, IOExcep
assertThat(part.getCount()).isEqualTo(1);

final BodyPart bodyPart = part.getBodyPart(0);
assertThat(bodyPart.getContentType()).isEqualTo("TEXT/PLAIN; charset=us-ascii");
assertThat(bodyPart.getContentType()).isEqualTo("text/plain; charset=us-ascii");
assertThat(bodyPart.getDisposition()).isEqualTo("inline");
assertThat(bodyPart.getContent()).isEqualTo("This is some text to be displayed inline");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,20 @@ public void testTextPlainWithUTF8() throws MessagingException, IOException {

// QP-encoded
final BodyPart bodyPart0 = multipartReceived.getBodyPart(0);
assertThat(bodyPart0.getContentType()).isEqualTo("TEXT/JAVASCRIPT; charset=utf-8");
assertThat(bodyPart0.getContentType()).isEqualTo("text/javascript; charset=utf-8");
assertThat(textQP.getContent()).isEqualTo(EncodingUtil.toString((InputStream) bodyPart0.getContent(), StandardCharsets.UTF_8));

// 8-BIT-encoded
final BodyPart bodyPart1 = multipartReceived.getBodyPart(1);
assertThat(bodyPart1.getContentType()).isEqualTo("TEXT/HTML; charset=utf-8");
assertThat(bodyPart1.getContentType()).isEqualTo("text/html; charset=utf-8");
assertThat(bodyPart1.getContent()).isEqualTo(html.getContent()); // Fails

final BodyPart bodyPart2 = multipartReceived.getBodyPart(2);
assertThat(bodyPart2.getContentType()).isEqualTo("TEXT/PLAIN; charset=utf-8");
assertThat(bodyPart2.getContentType()).isEqualTo("text/plain; charset=utf-8");
assertThat(bodyPart2.getContent()).isEqualTo(text.getContent());

final BodyPart bodyPart3 = multipartReceived.getBodyPart(3);
assertThat(bodyPart3.getContentType()).isEqualTo("TEXT/PLAIN; charset=utf-8");
assertThat(bodyPart3.getContentType()).isEqualTo("text/plain; charset=utf-8");
assertThat(bodyPart3.getContent()).isEqualTo(text2QP.getContent());
} finally {
store.close();
Expand Down

0 comments on commit 1464cc2

Please sign in to comment.