use of org.simplejavamail.api.email.Email in project simple-java-mail by bbottema.
the class TestSmimeSelfSigned method testSignedAndEncryptedMessageMsg.
@Test
public void testSignedAndEncryptedMessageMsg() {
Email emailParsedFromMsg = EmailConverter.outlookMsgToEmail(new File(RESOURCES_MESSAGES + "/S_MIME test message signed & encrypted.msg"), loadPkcs12KeyStore());
EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null));
EmailAssert.assertThat(emailParsedFromMsg).hasSubject("S/MIME test message signed & encrypted");
EmailAssert.assertThat(emailParsedFromMsg).hasOnlyRecipients(new Recipient("Benny Bottema", "benny@bennybottema.com", TO));
assertThat(normalizeNewlines(emailParsedFromMsg.getPlainText())).isEqualTo("This is an encrypted message, with one embedded image and one dummy \n" + "attachment.\n" + "\n" + "For testing purposes in the Simple Java Mail project.\n" + "\n");
assertThat(emailParsedFromMsg.getEmbeddedImages()).hasSize(1);
AttachmentResource embeddedImg = emailParsedFromMsg.getEmbeddedImages().get(0);
assertThat(embeddedImg.getName()).isEqualTo("part1.0B245DA7.F5872CD5@bennybottema.com");
assertThat(embeddedImg.getDataSource().getName()).isEqualTo("module_architecture.png");
assertThat(embeddedImg.getDataSource().getContentType()).isEqualTo("image/png");
assertThat(emailParsedFromMsg.getHTMLText()).contains(format("<img src=\"cid:%s\"", embeddedImg.getName()));
assertThat(emailParsedFromMsg.getAttachments()).hasSize(3);
assertThat(emailParsedFromMsg.getAttachments()).extracting("name").containsExactlyInAnyOrder("smime.p7m", "smime.p7s", "03-07-2005 errata SharnErrata.pdf");
assertThat(emailParsedFromMsg.getDecryptedAttachments()).hasSize(3);
assertThat(emailParsedFromMsg.getDecryptedAttachments()).extracting("name").containsExactlyInAnyOrder("smime.p7s", "signed-email.eml", "03-07-2005 errata SharnErrata.pdf");
EmailAssert.assertThat(emailParsedFromMsg).hasOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().smimeMode(SmimeMode.SIGNED_ENCRYPTED).smimeMime("application/pkcs7-mime").smimeType("enveloped-data").smimeName("smime.p7m").build());
EmailAssert.assertThat(emailParsedFromMsg.getSmimeSignedEmail()).hasOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().smimeMode(SmimeMode.SIGNED).smimeMime("multipart/signed").smimeProtocol("application/pkcs7-signature").smimeMicalg("sha-512").smimeSignatureValid(true).smimeSignedBy("Benny Bottema").build());
}
use of org.simplejavamail.api.email.Email in project simple-java-mail by bbottema.
the class MailerLiveTest method createMailSession_OutlookMessageDefaultSmimeSignTest.
@Test
public void createMailSession_OutlookMessageDefaultSmimeSignTest() throws IOException, MessagingException, ExecutionException, InterruptedException {
// override the default from the @Before test
mailer = MailerBuilder.withSMTPServer("localhost", SERVER_PORT).signByDefaultWithSmime(new File(RESOURCES_PKCS + "/smime_keystore.pkcs12"), "letmein", "smime_test_user_alias", "letmein").buildMailer();
EmailPopulatingBuilder builder = readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg");
Email email = assertSendingEmail(builder, false, true, false, true, false);
// verify that S/MIME was indeed only configured on the mailer instance
assertThat(mailer.getEmailGovernance().getPkcs12ConfigForSmimeSigning()).isNotNull();
assertThat(builder.getPkcs12ConfigForSmimeSigning()).isNull();
assertThat(email.getPkcs12ConfigForSmimeSigning()).isNull();
verifyReceivedOutlookEmail(email, true, false);
EmailAssert.assertThat(email).wasNotMergedWithSmimeSignedMessage();
EmailAssert.assertThat(email).hasOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().smimeMode(SmimeMode.SIGNED).smimeMime("multipart/signed").smimeProtocol("application/pkcs7-signature").smimeMicalg("sha-256").smimeSignedBy("Benny Bottema").smimeSignatureValid(true).build());
}
use of org.simplejavamail.api.email.Email in project simple-java-mail by bbottema.
the class MailerLiveTest method createMailSession_OutlookMessageSmimeSignTest.
@Test
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, true, false);
verifyReceivedOutlookEmail(email, true, false);
EmailAssert.assertThat(email).wasNotMergedWithSmimeSignedMessage();
EmailAssert.assertThat(email).hasOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().smimeMode(SmimeMode.SIGNED).smimeMime("multipart/signed").smimeProtocol("application/pkcs7-signature").smimeMicalg("sha-256").smimeSignedBy("Benny Bottema").smimeSignatureValid(true).build());
}
use of org.simplejavamail.api.email.Email in project simple-java-mail by bbottema.
the class MailerLiveTest method createMailSession_OutlookMessageTest.
@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, true, false);
verifyReceivedOutlookEmail(email, false, false);
}
use of org.simplejavamail.api.email.Email in project simple-java-mail by bbottema.
the class MailerLiveTest method testOutlookMessageWithNestedOutlookMessageAttachment.
@Test
public void testOutlookMessageWithNestedOutlookMessageAttachment() {
InputStream resourceAsStream = EmailHelper.class.getClassLoader().getResourceAsStream("test-messages/#298 Email with nested msg.msg");
Email email = EmailConverter.outlookMsgToEmail(checkNonEmptyArgument(resourceAsStream, "resourceAsStream"));
assertThat(email.getAttachments()).hasSize(2);
assertThat(email.getAttachments().get(1).getName()).isEqualTo("This msg file is an attachment.eml");
final InputStream emlInputstream = email.getAttachments().get(1).getDataSourceInputStream();
Email nestedEmail = EmailConverter.emlToEmail(emlInputstream);
EmailAssert.assertThat(nestedEmail).hasSubject("This msg file is an attachment");
assertThat(normalizeNewlines(nestedEmail.getPlainText())).isEqualTo("This is an email that will be attached to another email.\n");
EmailAssert.assertThat(nestedEmail).hasOnlyRecipients(new Recipient("atmcquillen@gmail.com", "atmcquillen@gmail.com", TO));
}
Aggregations