Skip to content

Commit

Permalink
#235, #236: map message id and sent date from outlook messages as well
Browse files Browse the repository at this point in the history
  • Loading branch information
bbottema committed Nov 19, 2019
1 parent 775685c commit 553b83f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ private static EmailFromOutlookMessage buildEmailFromOutlookMessage(
checkNonEmptyArgument(outlookMessage, "outlookMessage");
String fromEmail = ofNullable(outlookMessage.getFromEmail()).orElse("[email protected]");
builder.from(outlookMessage.getFromName(), fromEmail);
builder.fixingMessageId(outlookMessage.getMessageId());
builder.fixingSentDate(ofNullable(outlookMessage.getClientSubmitTime()).orElse(outlookMessage.getDate())); // FIXME creation date?
if (!MiscUtil.valueNullOrEmpty(outlookMessage.getReplyToEmail())) {
builder.withReplyTo(outlookMessage.getReplyToName(), outlookMessage.getReplyToEmail());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ public void testSMIMEMessageFromOutlookMsgWithDefaultMergeBehavior() {
// verify msg that was sent with Outlook against eml that was received in Thunderbird
EmailPopulatingBuilder fromEmlBuilder = EmailConverter.emlToEmailBuilder(new File(RESOURCE_FOLDER + "/SMIME (signed and clear text).eml"));
Email emailExpectedFromEml = fromEmlBuilder
.clearId() // set by Outlook when sending, so is missing in the saved .msg from before sending
.clearSentDate() // same
.clearHeaders() // same
.clearHeaders() // set by Outlook when sending, so is missing in the saved .msg from before sending
.clearReplyTo() // same
.clearBounceTo() // same
.from(assumeNonNull(fromEmlBuilder.getFromRecipient()).getName(), "[email protected]")
Expand Down Expand Up @@ -156,9 +154,7 @@ public void testSMIMEMessageFromOutlookMsgWithNonMergingBehavior() {
// verify msg that was sent with Outlook against eml that was received in Thunderbird
EmailPopulatingBuilder fromEmlBuilder = EmailConverter.emlToEmailBuilder(new File(RESOURCE_FOLDER + "/SMIME (signed and clear text).eml"));
Email emailExpectedFromEml = fromEmlBuilder
.clearId() // set by Outlook when sending, so is missing in the saved .msg from before sending
.clearSentDate() // same
.clearHeaders() // same
.clearHeaders() // set by Outlook when sending, so is missing in the saved .msg from before sending
.clearReplyTo() // same
.clearBounceTo() // same
.from(assumeNonNull(fromEmlBuilder.getFromRecipient()).getName(), "[email protected]")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void createMailSession_StandardDummyMailWithIdAndSendDate()
@Test
public void createMailSession_OutlookMessageTest()
throws IOException, MessagingException, ExecutionException, InterruptedException {
Email email = assertSendingEmail(readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg"), false, false, false, false);
Email email = assertSendingEmail(readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg"), false, false, false, true);
verifyReceivedOutlookEmail(email, false, false);
}

Expand All @@ -115,7 +115,7 @@ public void createMailSession_OutlookMessageSmimeSignTest()
throws IOException, MessagingException, ExecutionException, InterruptedException {
EmailPopulatingBuilder builder = readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg");
builder.signWithSmime(new File(RESOURCES_PKCS + "/smime_keystore.pkcs12"), "letmein", "smime_test_user_alias", "letmein");
Email email = assertSendingEmail(builder, false, true, false, false);
Email email = assertSendingEmail(builder, false, true, false, true);
verifyReceivedOutlookEmail(email, true, false);

EmailAssert.assertThat(email).wasNotMergedWithSmimeSignedMessage();
Expand All @@ -135,7 +135,7 @@ public void createMailSession_OutlookMessageSmimeEncryptTest()
throws IOException, MessagingException, ExecutionException, InterruptedException {
EmailPopulatingBuilder builder = readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg");
builder.encryptWithSmime(new File(RESOURCES_PKCS + "/smime_test_user.pem.standard.crt"));
Email email = assertSendingEmail(builder, false, true, false, false);
Email email = assertSendingEmail(builder, false, true, false, true);
verifyReceivedOutlookEmail(email, false, true);

EmailAssert.assertThat(email).wasMergedWithSmimeSignedMessage();
Expand All @@ -154,7 +154,7 @@ public void createMailSession_OutlookMessageSmimeSignEncryptTest()
EmailPopulatingBuilder builder = readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg");
builder.signWithSmime(new File(RESOURCES_PKCS + "/smime_keystore.pkcs12"), "letmein", "smime_test_user_alias", "letmein");
builder.encryptWithSmime(new File(RESOURCES_PKCS + "/smime_test_user.pem.standard.crt"));
Email email = assertSendingEmail(builder, false, true, false, false);
Email email = assertSendingEmail(builder, false, true, false, true);
verifyReceivedOutlookEmail(email, true, true);

EmailAssert.assertThat(email).wasMergedWithSmimeSignedMessage();
Expand Down Expand Up @@ -230,7 +230,7 @@ private void verifyReceivedOutlookEmail(final Email email, final boolean smimeSi
}

private Email assertSendingEmail(final EmailPopulatingBuilder originalEmailPopulatingBuilder, boolean compensateForDresscodeAttachmentNameOverrideErasure, boolean skipChecksDueToSmime,
boolean async, final boolean fixedSentDate)
boolean async, final boolean sentDateWasFixed)
throws MessagingException, ExecutionException, InterruptedException {
Email originalEmail = originalEmailPopulatingBuilder.buildEmail();

Expand All @@ -250,12 +250,12 @@ private Email assertSendingEmail(final EmailPopulatingBuilder originalEmailPopul

Email receivedEmail = mimeMessageToEmail(receivedMimeMessage.getMimeMessage(), loadPkcs12KeyStore());

if (!fixedSentDate) {
if (!sentDateWasFixed) {
GregorianCalendar receiveWindowStart = new GregorianCalendar();
receiveWindowStart.add(Calendar.SECOND, -5);
assertThat(receivedEmail.getSentDate()).isBetween(receiveWindowStart.getTime(), new Date());
} else {
assertThat(receivedEmail.getSentDate()).isEqualTo(CUSTOM_SENT_DATE);
assertThat(receivedEmail.getSentDate()).isEqualTo(originalEmailPopulatingBuilder.getSentDate());
}

// ID will always be generated when sending: if set to a specific value, just assume the generated one
Expand Down Expand Up @@ -308,7 +308,7 @@ public void createMailSession_ReplyToMessage()

// send reply to initial mail
Email reply = EmailBuilder
.replyingToAll(assertSendingEmail(receivedEmailPopulatingBuilder, false, false, false, false))
.replyingToAll(assertSendingEmail(receivedEmailPopulatingBuilder, false, false, false, true))
.from("[email protected]")
.withPlainText("This is the reply")
.buildEmail();
Expand Down Expand Up @@ -340,7 +340,7 @@ public void createMailSession_ReplyToMessage_NotAll_AndCustomReferences()

// send reply to initial mail
Email reply = EmailBuilder
.replyingTo(assertSendingEmail(receivedEmailPopulatingBuilder, false, false, false, false))
.replyingTo(assertSendingEmail(receivedEmailPopulatingBuilder, false, false, false, true))
.from("Moo Shmoo", "[email protected]")
.withPlainText("This is the reply")
.buildEmail();
Expand Down

0 comments on commit 553b83f

Please sign in to comment.