Skip to content

Commit f6d18df

Browse files
committed
#283: fix for quoted-printable calendar attachments
1 parent f91d24d commit f6d18df

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

modules/simple-java-mail/src/main/java/org/simplejavamail/converter/internal/mimemessage/MimeMessageParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import javax.mail.internet.MimeUtility;
2727
import javax.mail.internet.ParseException;
2828
import javax.mail.util.ByteArrayDataSource;
29-
import javax.mail.util.SharedByteArrayInputStream;
3029
import java.io.IOException;
3130
import java.io.InputStream;
3231
import java.io.UnsupportedEncodingException;
@@ -142,7 +141,7 @@ private static void parseMimePartTree(@NotNull final MimePart currentPart, @NotN
142141
//noinspection RedundantCast
143142
parsedComponents.htmlContent.append((Object) parseContent(currentPart));
144143
} else if (isMimeType(currentPart, "text/calendar") && parsedComponents.calendarContent == null && !Part.ATTACHMENT.equalsIgnoreCase(disposition)) {
145-
final SharedByteArrayInputStream calendarContent = parseContent(currentPart);
144+
final InputStream calendarContent = parseContent(currentPart);
146145
try {
147146
parsedComponents.calendarContent = MiscUtil.readInputStreamToString(calendarContent, UTF_8);
148147
} catch (IOException e) {

modules/simple-java-mail/src/test/java/org/simplejavamail/converter/EmailConverterTest.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
import org.jetbrains.annotations.NotNull;
44
import org.junit.Test;
5+
import org.simplejavamail.api.email.CalendarMethod;
56
import org.simplejavamail.api.email.Email;
67
import org.simplejavamail.api.email.EmailAssert;
78
import org.simplejavamail.api.email.Recipient;
9+
import testutil.SecureTestDataHelper;
10+
import testutil.SecureTestDataHelper.PasswordsConsumer;
811

912
import java.io.File;
13+
import java.util.Properties;
1014

1115
import static demo.ResourceFolderHelper.determineResourceFolder;
1216
import static javax.mail.Message.RecipientType.CC;
@@ -16,15 +20,16 @@
1620

1721
public class EmailConverterTest {
1822

19-
private static final String RESOURCE_FOLDER = determineResourceFolder("simple-java-mail") + "/test/resources/test-messages";
23+
private static final String RESOURCES = determineResourceFolder("simple-java-mail") + "/test/resources";
24+
private static final String RESOURCE_TEST_MESSAGES = RESOURCES + "/test-messages";
2025

2126
@Test
2227
public void testOutlookBasicConversions() {
2328
final Recipient elias = new Recipient("Elias Laugher", "[email protected]", null);
2429
final Recipient sven = new Recipient("Sven Sielenkemper", "[email protected]", TO);
2530
final Recipient niklas = new Recipient("[email protected]", "[email protected]", CC);
2631

27-
@NotNull Email msg = EmailConverter.outlookMsgToEmail(new File(RESOURCE_FOLDER + "/simple email with TO and CC.msg"));
32+
@NotNull Email msg = EmailConverter.outlookMsgToEmail(new File(RESOURCE_TEST_MESSAGES + "/simple email with TO and CC.msg"));
2833
EmailAssert.assertThat(msg).hasFromRecipient(elias);
2934
EmailAssert.assertThat(msg).hasSubject("Test E-Mail");
3035
EmailAssert.assertThat(msg).hasOnlyRecipients(sven, niklas);
@@ -39,7 +44,7 @@ public void testOutlookUnicode() {
3944
final Recipient kalejs = new Recipient("[email protected]", "[email protected]", null);
4045
final Recipient dummy = new Recipient("[email protected]", "[email protected]", TO);
4146

42-
@NotNull Email msg = EmailConverter.outlookMsgToEmail(new File(RESOURCE_FOLDER + "/tst_unicode.msg"));
47+
@NotNull Email msg = EmailConverter.outlookMsgToEmail(new File(RESOURCE_TEST_MESSAGES + "/tst_unicode.msg"));
4348
EmailAssert.assertThat(msg).hasFromRecipient(kalejs);
4449
EmailAssert.assertThat(msg).hasSubject("Testcase");
4550
EmailAssert.assertThat(msg).hasOnlyRecipients(dummy);
@@ -65,12 +70,26 @@ public void testOutlookUnicode() {
6570
public void testOutlookUnsentDraft() {
6671
final Recipient time2talk = new Recipient("[email protected]", "[email protected]", TO);
6772

68-
@NotNull Email msg = EmailConverter.outlookMsgToEmail(new File(RESOURCE_FOLDER + "/unsent draft.msg"));
73+
@NotNull Email msg = EmailConverter.outlookMsgToEmail(new File(RESOURCE_TEST_MESSAGES + "/unsent draft.msg"));
6974
EmailAssert.assertThat(msg).hasFromRecipient(new Recipient(null, "[email protected]", null));
7075
EmailAssert.assertThat(msg).hasSubject("MSG Test File");
7176
EmailAssert.assertThat(msg).hasOnlyRecipients(time2talk);
7277
EmailAssert.assertThat(msg).hasNoAttachments();
7378
assertThat(msg.getPlainText()).isNotEmpty();
7479
assertThat(normalizeNewlines(msg.getHTMLText())).isNotEmpty();
7580
}
81+
82+
@Test
83+
public void testEmlWithQuotablePrintableCalendarAttachment()
84+
throws Exception {
85+
SecureTestDataHelper.runTestWithSecureTestData(new PasswordsConsumer() {
86+
@Override
87+
public void accept(final Properties passwords) {
88+
File file = new File(RESOURCES + "/secure-testdata/secure-testdata/calendar-quotable-printable-email/qp-calendar-multipart.eml");
89+
final Email email = EmailConverter.emlToEmail(file);
90+
assertThat(email.getCalendarMethod()).isEqualTo(CalendarMethod.REQUEST);
91+
assertThat(email.getCalendarText()).startsWith("BEGIN:VCALENDAR");
92+
}
93+
});
94+
}
7695
}

0 commit comments

Comments
 (0)