Search in sources :

Example 26 with Recipient

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));
}
Also used : Email(org.simplejavamail.api.email.Email) Recipient(org.simplejavamail.api.email.Recipient) Test(org.junit.Test)

Example 27 with Recipient

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());
}
Also used : AttachmentResource(org.simplejavamail.api.email.AttachmentResource) Email(org.simplejavamail.api.email.Email) Recipient(org.simplejavamail.api.email.Recipient) File(java.io.File) Test(org.junit.Test)

Example 28 with Recipient

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());
}
Also used : AttachmentResource(org.simplejavamail.api.email.AttachmentResource) Email(org.simplejavamail.api.email.Email) Recipient(org.simplejavamail.api.email.Recipient) File(java.io.File) Test(org.junit.Test)

Example 29 with Recipient

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());
}
Also used : AttachmentResource(org.simplejavamail.api.email.AttachmentResource) Email(org.simplejavamail.api.email.Email) Recipient(org.simplejavamail.api.email.Recipient) File(java.io.File) Test(org.junit.Test)

Example 30 with Recipient

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));
}
Also used : Recipient(org.simplejavamail.api.email.Recipient) Test(org.junit.Test)

Aggregations

Recipient (org.simplejavamail.api.email.Recipient)56 Test (org.junit.Test)43 Email (org.simplejavamail.api.email.Email)31 File (java.io.File)10 AttachmentResource (org.simplejavamail.api.email.AttachmentResource)7 InternetAddress (jakarta.mail.internet.InternetAddress)4 NotNull (org.jetbrains.annotations.NotNull)4 EmailPopulatingBuilder (org.simplejavamail.api.email.EmailPopulatingBuilder)4 EmailConverter.mimeMessageToEmail (org.simplejavamail.converter.EmailConverter.mimeMessageToEmail)4 Address (jakarta.mail.Address)2 MimeMessage (jakarta.mail.internet.MimeMessage)2 InputStream (java.io.InputStream)2 Collection (java.util.Collection)2 Map (java.util.Map)2 HashedMap (org.apache.commons.collections4.map.HashedMap)2 Property (org.simplejavamail.config.ConfigLoader.Property)2 InternalEmailPopulatingBuilder (org.simplejavamail.email.internal.InternalEmailPopulatingBuilder)2 Test (org.testng.annotations.Test)2 EmailHelper (testutil.EmailHelper)2 MimeMessageAndEnvelope (testutil.testrules.MimeMessageAndEnvelope)2