Search in sources :

Example 1 with AttachmentResource

use of org.simplejavamail.email.AttachmentResource in project simple-java-mail by bbottema.

the class MimeMessageHelperTest method determineResourceName3.

@Test
public void determineResourceName3() throws IOException {
    AttachmentResource resource3 = new AttachmentResource("the resource", getDataSource(null));
    assertThat(MimeMessageHelper.determineResourceName(resource3, false)).isEqualTo("the resource");
    assertThat(MimeMessageHelper.determineResourceName(resource3, true)).isEqualTo("the resource");
}
Also used : AttachmentResource(org.simplejavamail.email.AttachmentResource) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with AttachmentResource

use of org.simplejavamail.email.AttachmentResource in project simple-java-mail by bbottema.

the class MimeMessageHelperTest method determineResourceName2.

@Test
public void determineResourceName2() throws IOException {
    AttachmentResource resource2 = new AttachmentResource(null, getDataSource("blahblah.txt"));
    assertThat(MimeMessageHelper.determineResourceName(resource2, false)).isEqualTo("blahblah");
    assertThat(MimeMessageHelper.determineResourceName(resource2, true)).isEqualTo("blahblah.txt");
}
Also used : AttachmentResource(org.simplejavamail.email.AttachmentResource) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with AttachmentResource

use of org.simplejavamail.email.AttachmentResource in project simple-java-mail by bbottema.

the class MailerLiveTest method createMailSession_OutlookMessageTest.

@Test
public void createMailSession_OutlookMessageTest() throws IOException, MessagingException {
    Email email = assertSendingEmail(readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg"));
    // Google SMTP overrode this, Outlook recognized it as: Benny Bottema <b.bottema@gmail.com>; on behalf of; lollypop <b.bottema@projectnibble.org>
    EmailAssert.assertThat(email).hasFromRecipient(new Recipient("lollypop", "b.bottema@projectnibble.org", null));
    EmailAssert.assertThat(email).hasSubject("hey");
    // Outlook overrode this when saving the .email to match the mail account
    EmailAssert.assertThat(email).hasRecipients(new Recipient("Bottema, Benny", "benny.bottema@aegon.nl", TO));
    EmailAssert.assertThat(email).hasReplyToRecipient(new Recipient("lollypop-replyto", "lo.pop.replyto@somemail.com", null));
    assertThat(normalizeText(email.getPlainText())).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(email.getHTMLText())).contains("<html><body style=\"font-family:'Courier',monospace;font-size:10pt;\">   <br/>      <br/> <b>   We should meet up! <br/>  </b>   <br/>  <img src=\"cid:thumbsup\"> <br/> ");
    // the RTF was probably created by Outlook based on the HTML when the message was saved
    assertThat(email.getAttachments()).hasSize(2);
    assertThat(email.getEmbeddedImages()).hasSize(1);
    AttachmentResource attachment1 = email.getAttachments().get(0);
    AttachmentResource attachment2 = email.getAttachments().get(1);
    AttachmentResource embeddedImg = email.getEmbeddedImages().get(0);
    // Outlook overrode dresscode.txt, presumably because it was more than 8 character long??
    assertAttachmentMetadata(attachment1, "text/plain", "dresscode.txt");
    assertAttachmentMetadata(attachment2, "text/plain", "location.txt");
    assertAttachmentMetadata(embeddedImg, "image/png", "thumbsup");
    assertThat(normalizeText(attachment1.readAllData())).isEqualTo("Black Tie Optional");
    assertThat(normalizeText(attachment2.readAllData())).isEqualTo("On the moon!");
}
Also used : AttachmentResource(org.simplejavamail.email.AttachmentResource) EmailConverter.mimeMessageToEmail(org.simplejavamail.converter.EmailConverter.mimeMessageToEmail) Email(org.simplejavamail.email.Email) Recipient(org.simplejavamail.email.Recipient) Test(org.junit.Test)

Example 4 with AttachmentResource

use of org.simplejavamail.email.AttachmentResource in project simple-java-mail by bbottema.

the class MimeMessageHelperTest method determineResourceName1.

@Test
public void determineResourceName1() throws IOException {
    AttachmentResource resource1 = new AttachmentResource(null, getDataSource("blahblah"));
    assertThat(MimeMessageHelper.determineResourceName(resource1, false)).isEqualTo("blahblah");
    assertThat(MimeMessageHelper.determineResourceName(resource1, true)).isEqualTo("blahblah");
}
Also used : AttachmentResource(org.simplejavamail.email.AttachmentResource) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with AttachmentResource

use of org.simplejavamail.email.AttachmentResource in project simple-java-mail by bbottema.

the class MimeMessageHelperTest method determineResourceName6.

@Test
public void determineResourceName6() throws IOException {
    AttachmentResource resource6 = new AttachmentResource("the resource.txt", getDataSource("blahblah.txt"));
    assertThat(MimeMessageHelper.determineResourceName(resource6, false)).isEqualTo("the resource.txt");
    assertThat(MimeMessageHelper.determineResourceName(resource6, true)).isEqualTo("the resource.txt");
}
Also used : AttachmentResource(org.simplejavamail.email.AttachmentResource) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

AttachmentResource (org.simplejavamail.email.AttachmentResource)9 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 Recipient (org.simplejavamail.email.Recipient)2 Map (java.util.Map)1 EmailConverter.mimeMessageToEmail (org.simplejavamail.converter.EmailConverter.mimeMessageToEmail)1 Email (org.simplejavamail.email.Email)1