use of org.simplejavamail.api.email.Recipient in project simple-java-mail by bbottema.
the class MimeMessageParserTest method testSemiColonSeparatedToAddresses.
@Test
public // https://github.com/bbottema/simple-java-mail/issues/227
void testSemiColonSeparatedToAddresses() {
ConfigLoaderTestHelper.clearConfigProperties();
final Email initialEmail = EmailBuilder.startingBlank().from("lollypop", "lol.pop@somemail.com").to("C.Cane", "candycane@candyshop.org").withPlainText("We should meet up!").buildEmail();
String corruptedEML = EmailConverter.emailToEML(initialEmail).replace("To: \"C.Cane\" <candycane@candyshop.org>", "To: \"C.Cane\" <candycane@candyshop.org>;");
final Email fixedEmail = EmailConverter.emlToEmail(corruptedEML);
EmailAssert.assertThat(fixedEmail).hasOnlyRecipients(new Recipient("C.Cane", "candycane@candyshop.org", TO));
}
use of org.simplejavamail.api.email.Recipient in project simple-java-mail by bbottema.
the class TestSmimeSelfSigned method testEncryptedMessageEml.
@Test
public void testEncryptedMessageEml() {
Email emailParsedFromEml = EmailConverter.emlToEmail(new File(RESOURCES_MESSAGES + "/S_MIME test message encrypted.eml"), loadPkcs12KeyStore());
EmailAssert.assertThat(emailParsedFromEml).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null));
EmailAssert.assertThat(emailParsedFromEml).hasSubject("S/MIME test message encrypted");
EmailAssert.assertThat(emailParsedFromEml).hasOnlyRecipients(new Recipient("Benny Bottema", "benny@bennybottema.com", TO));
assertThat(normalizeNewlines(emailParsedFromEml.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(emailParsedFromEml.getEmbeddedImages()).hasSize(1);
AttachmentResource embeddedImg = emailParsedFromEml.getEmbeddedImages().get(0);
assertThat(embeddedImg.getName()).isEqualTo("part1.EDA02623.55A510EE@bennybottema.com");
assertThat(embeddedImg.getDataSource().getName()).isEqualTo("module_architecture.png");
assertThat(embeddedImg.getDataSource().getContentType()).isEqualTo("image/png");
assertThat(emailParsedFromEml.getHTMLText()).contains(format("<img src=\"cid:%s\"", embeddedImg.getName()));
assertThat(emailParsedFromEml.getAttachments()).hasSize(2);
assertThat(emailParsedFromEml.getAttachments()).extracting("name").containsExactlyInAnyOrder("smime.p7m", "03-07-2005 errata SharnErrata.pdf");
assertThat(emailParsedFromEml.getDecryptedAttachments()).hasSize(2);
assertThat(emailParsedFromEml.getDecryptedAttachments()).extracting("name").containsExactlyInAnyOrder("signed-email.eml", "03-07-2005 errata SharnErrata.pdf");
EmailAssert.assertThat(emailParsedFromEml).hasOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().smimeMode(SmimeMode.ENCRYPTED).smimeMime("application/pkcs7-mime").smimeType("enveloped-data").smimeName("smime.p7m").build());
}
use of org.simplejavamail.api.email.Recipient in project simple-java-mail by bbottema.
the class TestSmimeSelfSigned method testSignedMessageEml.
@Test
public void testSignedMessageEml() {
Email emailParsedFromEml = EmailConverter.emlToEmail(new File(RESOURCES_MESSAGES + "/S_MIME test message signed.eml"));
EmailAssert.assertThat(emailParsedFromEml).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null));
EmailAssert.assertThat(emailParsedFromEml).hasSubject("S/MIME test message signed");
EmailAssert.assertThat(emailParsedFromEml).hasOnlyRecipients(new Recipient("Benny Bottema", "benny@bennybottema.com", TO));
assertThat(normalizeNewlines(emailParsedFromEml.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(emailParsedFromEml.getEmbeddedImages()).hasSize(1);
AttachmentResource embeddedImg = emailParsedFromEml.getEmbeddedImages().get(0);
assertThat(embeddedImg.getName()).isEqualTo("part1.6C435E18.EC121991@bennybottema.com");
assertThat(embeddedImg.getDataSource().getName()).isEqualTo("module_architecture.png");
assertThat(embeddedImg.getDataSource().getContentType()).isEqualTo("image/png");
assertThat(emailParsedFromEml.getHTMLText()).contains(format("<img src=\"cid:%s\"", embeddedImg.getName()));
assertThat(emailParsedFromEml.getAttachments()).hasSize(2);
assertThat(emailParsedFromEml.getAttachments()).extracting("name").containsExactlyInAnyOrder("smime.p7s", "03-07-2005 errata SharnErrata.pdf");
assertThat(emailParsedFromEml.getDecryptedAttachments()).hasSize(2);
assertThat(emailParsedFromEml.getDecryptedAttachments()).extracting("name").containsExactlyInAnyOrder("smime.p7s", "03-07-2005 errata SharnErrata.pdf");
EmailAssert.assertThat(emailParsedFromEml).hasOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().smimeMode(SmimeMode.SIGNED).smimeMime("multipart/signed").smimeProtocol("application/pkcs7-signature").smimeMicalg("sha-512").smimeSignedBy("Benny Bottema").smimeSignatureValid(true).build());
}
use of org.simplejavamail.api.email.Recipient in project simple-java-mail by bbottema.
the class TestSmimeSelfSigned method testSignedMessageMsg.
@Test
public void testSignedMessageMsg() {
Email emailParsedFromMsg = EmailConverter.outlookMsgToEmail(new File(RESOURCES_MESSAGES + "/S_MIME test message signed.msg"));
EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null));
EmailAssert.assertThat(emailParsedFromMsg).hasSubject("S/MIME test message signed");
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.6C435E18.EC121991@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(2);
assertThat(emailParsedFromMsg.getAttachments()).extracting("name").containsExactlyInAnyOrder("smime.p7s", "03-07-2005 errata SharnErrata.pdf");
assertThat(emailParsedFromMsg.getDecryptedAttachments()).hasSize(2);
assertThat(emailParsedFromMsg.getDecryptedAttachments()).extracting("name").containsExactlyInAnyOrder("signed-email.eml", "03-07-2005 errata SharnErrata.pdf");
EmailAssert.assertThat(emailParsedFromMsg).hasOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().smimeMode(SmimeMode.SIGNED).smimeMime("multipart/signed").smimeProtocol("application/pkcs7-signature").smimeMicalg("sha-512").smimeSignedBy("Benny Bottema").smimeSignatureValid(true).build());
}
use of org.simplejavamail.api.email.Recipient in project simple-java-mail by bbottema.
the class MiscUtilTest method testAddRecipientByInternetAddress.
@Test
public void testAddRecipientByInternetAddress() {
assertThat(MiscUtil.interpretRecipient(null, false, "a@b.com", null)).isEqualTo(new Recipient(null, "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, " a@b.com ", null)).isEqualTo(new Recipient(null, "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, " <a@b.com> ", null)).isEqualTo(new Recipient(null, "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, " < a@b.com > ", null)).isEqualTo(new Recipient(null, "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, "moo <a@b.com>", null)).isEqualTo(new Recipient("moo", "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, "moo<a@b.com>", null)).isEqualTo(new Recipient("moo", "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, " moo< a@b.com > ", null)).isEqualTo(new Recipient("moo", "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, "\"moo\" <a@b.com>", null)).isEqualTo(new Recipient("moo", "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, "\"moo\"<a@b.com>", null)).isEqualTo(new Recipient("moo", "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, " \"moo\"< a@b.com > ", null)).isEqualTo(new Recipient("moo", "a@b.com", null));
assertThat(MiscUtil.interpretRecipient(null, false, " \" m oo \"< a@b.com > ", null)).isEqualTo(new Recipient(" m oo ", "a@b.com", null));
// next one is unparsable by InternetAddress#parse(), so it should be taken as is
assertThat(MiscUtil.interpretRecipient(null, false, " \" m oo \" a@b.com ", null)).isEqualTo(new Recipient(null, " \" m oo \" a@b.com ", null));
}
Aggregations