Skip to content

Commit

Permalink
#25: NPE on ClientSubmitTime when original message has not been sent yet
Browse files Browse the repository at this point in the history
  • Loading branch information
bbottema committed Jan 24, 2020
1 parent 58fece0 commit 84b6cda
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bbottema.rtftohtml.RTF2HTMLConverter;
import org.bbottema.rtftohtml.impl.RTF2HTMLConverterRFCCompliant;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.simplejavamail.outlookmessageparser.rtf.util.CharsetHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -828,10 +829,11 @@ private void setDate(final Date date) {
}

/**
* Bean getter for {@link #clientSubmitTime}.
* @return {@link #clientSubmitTime} or null in case this message has not been sent yet.
*/
@Nullable
public Date getClientSubmitTime() {
return (Date) clientSubmitTime.clone();
return clientSubmitTime != null ? (Date) clientSubmitTime.clone() : null;
}

private void setClientSubmitTime(final String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.simplejavamail.outlookmessageparser.TestUtils.normalizeText;

Expand All @@ -32,6 +33,7 @@ public void testRtfSent()
assertThat(msg.getBodyText()).isNotEmpty();
assertThat(msg.getBodyHTML()).isNull();
assertThat(msg.getBodyRTF()).isNotEmpty();
assertThat(msg.getClientSubmitTime()).isNotNull();
assertThat(normalizeText(msg.getBodyText())).isEqualTo("Dear BitDaddys Corp.,\n"
+ "\n"
+ "We have added your software to our approved list.\n"
Expand All @@ -58,6 +60,7 @@ public void testToAndCCAreSeparated_Single()
assertThat(msg.getBodyText()).isNotEmpty();
assertThat(msg.getBodyHTML()).isNull();
assertThat(msg.getBodyRTF()).isNotEmpty();
assertThat(msg.getClientSubmitTime()).isNotNull();
assertThat(normalizeText(msg.getBodyText())).isEqualTo("Just a test to get an email with one cc recipient.\n");
}

Expand All @@ -81,6 +84,7 @@ public void testToAndCCAreSeparated_Multiple()
assertThat(msg.getBodyText()).isNotEmpty();
assertThat(msg.getBodyHTML()).isNull();
assertThat(msg.getBodyRTF()).isNotEmpty();
assertThat(msg.getClientSubmitTime()).isNotNull();
assertThat(normalizeText(msg.getBodyText())).isEqualTo("Just a test to get an email with multiple to/cc/bcc recipients.\n\n \n\n");
}

Expand All @@ -94,6 +98,7 @@ public void testUnsentRtfDraft()
assertThat(msg.getBodyText()).isNotEmpty();
assertThat(msg.getBodyHTML()).isNull();
assertThat(msg.getBodyRTF()).isNotEmpty();
assertThat(msg.getClientSubmitTime()).isNull();
assertThat(normalizeText(msg.getBodyText())).isEqualTo("MSG test file\n"
+ "Purpose: Provide example of this file type\n"
+ "Document file type: MSG\n"
Expand Down Expand Up @@ -163,6 +168,7 @@ public void testHtmlMessageChain()
assertThat(msg.getBodyHTML()).isNull();
assertThat(msg.getConvertedBodyHTML()).isNotEmpty();
assertThat(msg.getBodyRTF()).isNotEmpty();
assertThat(msg.getClientSubmitTime()).isNotNull();
assertThat(normalizeText(msg.getBodyText())).isEqualTo("Another test email to obtain raw data for Jean-Philippe.\n"
+ "\n"
+ " \n"
Expand Down Expand Up @@ -236,6 +242,7 @@ public void testNestedRtfMsg()
assertThat(nestedMsg.getBodyText()).isNotEmpty();
assertThat(nestedMsg.getBodyHTML()).isNull();
assertThat(nestedMsg.getBodyRTF()).isNotEmpty();
assertThat(msg.getClientSubmitTime()).isNotNull();
assertThat(normalizeText(nestedMsg.getBodyText())).isEqualTo("Hello all,\n"
+ "\n"
+ " \n"
Expand Down Expand Up @@ -323,6 +330,7 @@ public void testFileAttachments()
assertThat(msg.getBodyText()).isNotEmpty();
assertThat(msg.getBodyHTML()).isNull();
assertThat(msg.getBodyRTF()).isNotEmpty();
assertThat(msg.getClientSubmitTime()).isNotNull();
assertThat(normalizeText(msg.getBodyText())).isEqualTo("Delivery is delayed to these recipients or groups:\n"
+ "\n"
+ "[email protected] ([email protected])\n"
Expand Down Expand Up @@ -423,6 +431,7 @@ public void testEmbeddedImage()
assertThat(msg.fetchCIDMap()).hasSize(1);
assertThat(msg.fetchCIDMap()).containsEntry("[email protected]", (OutlookFileAttachment) outlookAttachments.get(0));
assertThat(msg.fetchTrueAttachments()).isEmpty();
assertThat(msg.getClientSubmitTime()).isNotNull();
assertThat(normalizeText(msg.getBodyText())).contains("This should pass into the kayako\n"
+ "\n"
+ " \n"
Expand Down Expand Up @@ -486,6 +495,7 @@ public void testChineseMessage()
assertThat(msg.getConvertedBodyHTML()).isNotEmpty();
assertThat(msg.fetchCIDMap()).isEmpty();
assertThat(msg.fetchTrueAttachments()).isEmpty();
assertThat(msg.getClientSubmitTime()).isNull();
assertThat(normalizeText(msg.getBodyText())).isEqualTo(" \n" +
" \n" +
"Dears:\n" +
Expand Down Expand Up @@ -530,6 +540,7 @@ public void testUnicodeMessage()
assertThat(msg.getBodyHTML()).isNull();
assertThat(msg.fetchCIDMap()).isEmpty();
assertThat(msg.fetchTrueAttachments()).isEmpty();
assertThat(msg.getClientSubmitTime()).isNull();
assertThat(normalizeText(msg.getBodyText())).isEqualTo("-/-\n" +
"Char-å-Char\n" +
"-/-\n" +
Expand Down Expand Up @@ -561,6 +572,7 @@ public void testToCcBcc()
assertThat(msg.getBodyText()).isNotEmpty();
assertThat(msg.getBodyHTML()).isNull();
assertThat(msg.fetchCIDMap()).isEmpty();
assertThat(msg.getClientSubmitTime()).isNotNull();
assertThat(msg.fetchTrueAttachments()).isEmpty();
}

Expand Down Expand Up @@ -640,6 +652,7 @@ public void testMsgForwardDraftWithBothAttachmentsAndEmbeddedImage()
assertThat(msg.getConvertedBodyHTML()).contains("cid:image002.png");
assertThat(msg.getBodyText()).isNotEmpty();
assertThat(msg.getBodyHTML()).isNull();
assertThat(msg.getClientSubmitTime()).isNull();
assertThat(normalizeText(msg.getBodyText())).isEqualTo(" \n"
+ " \n"
+ "Van: Microsoft Outlook\n"
Expand Down Expand Up @@ -819,6 +832,7 @@ public void testHtmlTestWithReplyToAndAttachmentsPlusEmbeddedImage()
OutlookMessageAssert.assertThat(msg).hasOnlyToRecipients(createRecipient("Bottema, Benny", "[email protected]"));
OutlookMessageAssert.assertThat(msg).hasReplyToName("lollypop-replyto");
OutlookMessageAssert.assertThat(msg).hasReplyToEmail("[email protected]");
assertThat(msg.getClientSubmitTime()).isNotNull();
assertThat(normalizeText(msg.getBodyText())).isEqualTo("We should meet up!\n");
// Outlook overrode this value too OR converted the original HTML to RTF, from which OutlookMessageParser derived this HTML
assertThat(normalizeText(msg.getConvertedBodyHTML())).isEqualTo(
Expand Down Expand Up @@ -866,6 +880,6 @@ private static OutlookRecipient createRecipient(String toName, String toEmail) {
private static OutlookMessage parseMsgFile(String msgPath)
throws IOException {
InputStream resourceAsStream = OutlookMessageParser.class.getClassLoader().getResourceAsStream(msgPath);
return new OutlookMessageParser().parseMsg(resourceAsStream);
return new OutlookMessageParser().parseMsg(requireNonNull(resourceAsStream));
}
}

0 comments on commit 84b6cda

Please sign in to comment.