Search in sources :

Example 1 with NamedDataSource

use of org.simplejavamail.internal.util.NamedDataSource in project simple-java-mail by bbottema.

the class MimeMessageParserTest method getBodyPartFromDatasource.

private static BodyPart getBodyPartFromDatasource(final AttachmentResource attachmentResource, final String dispositionType) throws MessagingException {
    final BodyPart attachmentPart = new MimeBodyPart();
    // setting headers isn't working nicely using the javax mail API, so let's do that manually
    final String resourceName = "htgfiytityf.txt";
    final String fileName = "proper-name.txt";
    attachmentPart.setDataHandler(new DataHandler(new NamedDataSource(fileName, attachmentResource.getDataSource())));
    attachmentPart.setFileName(fileName);
    final String contentType = attachmentResource.getDataSource().getContentType();
    ParameterList pl = new ParameterList();
    pl.set("filename", fileName);
    pl.set("name", fileName);
    attachmentPart.setHeader("Content-Type", contentType + pl);
    attachmentPart.setHeader("Content-ID", format("<%s>", resourceName));
    attachmentPart.setDisposition(dispositionType);
    return attachmentPart;
}
Also used : BodyPart(jakarta.mail.BodyPart) MimeBodyPart(jakarta.mail.internet.MimeBodyPart) ParameterList(jakarta.mail.internet.ParameterList) DataHandler(jakarta.activation.DataHandler) MimeBodyPart(jakarta.mail.internet.MimeBodyPart) NamedDataSource(org.simplejavamail.internal.util.NamedDataSource)

Example 2 with NamedDataSource

use of org.simplejavamail.internal.util.NamedDataSource in project simple-java-mail by bbottema.

the class NamedDataSourceTest method outputStreamWillBeTheSame1.

@Test
public void outputStreamWillBeTheSame1() throws Exception {
    DataSource testDataSource = new NamedDataSource("newName", dataSource);
    testDataSource.getOutputStream();
    verify(dataSource).getOutputStream();
}
Also used : NamedDataSource(org.simplejavamail.internal.util.NamedDataSource) NamedDataSource(org.simplejavamail.internal.util.NamedDataSource) DataSource(jakarta.activation.DataSource) Test(org.junit.Test)

Example 3 with NamedDataSource

use of org.simplejavamail.internal.util.NamedDataSource in project simple-java-mail by bbottema.

the class NamedDataSourceTest method renameWillWork.

@Test
public void renameWillWork() {
    DataSource testDataSource = new NamedDataSource("newName", dataSource);
    assertThat(testDataSource.getName()).isEqualTo("newName");
    verifyZeroInteractions(dataSource);
}
Also used : NamedDataSource(org.simplejavamail.internal.util.NamedDataSource) NamedDataSource(org.simplejavamail.internal.util.NamedDataSource) DataSource(jakarta.activation.DataSource) Test(org.junit.Test)

Example 4 with NamedDataSource

use of org.simplejavamail.internal.util.NamedDataSource in project simple-java-mail by bbottema.

the class NamedDataSourceTest method contentTypeStreamWillBeTheSame1.

@Test
public void contentTypeStreamWillBeTheSame1() {
    DataSource testDataSource = new NamedDataSource("newName", dataSource);
    testDataSource.getContentType();
    verify(dataSource).getContentType();
}
Also used : NamedDataSource(org.simplejavamail.internal.util.NamedDataSource) NamedDataSource(org.simplejavamail.internal.util.NamedDataSource) DataSource(jakarta.activation.DataSource) Test(org.junit.Test)

Example 5 with NamedDataSource

use of org.simplejavamail.internal.util.NamedDataSource in project simple-java-mail by bbottema.

the class EmailTest method testEqualsEmail_EqualityEmbeddedImages.

@Test
public void testEqualsEmail_EqualityEmbeddedImages() throws IOException {
    assertEmailEqual(b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").buildEmail(), b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").buildEmail(), true);
    assertEmailEqual(b().withEmbeddedImage(null, new NamedDataSource("n1", new ByteArrayDataSource("data", "image/png"))).buildEmail(), b().withEmbeddedImage(null, new NamedDataSource("n1", new ByteArrayDataSource("data", "image/png"))).buildEmail(), true);
    assertEmailEqual(b().withEmbeddedImage("name", new ByteArrayDataSource("data", "image/png")).buildEmail(), b().withEmbeddedImage("name", new ByteArrayDataSource("data", "image/png")).buildEmail(), true);
    assertEmailEqual(b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").withEmbeddedImage("name2", new byte[] { 'b' }, "image/bmp").buildEmail(), b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").withEmbeddedImage("name2", new byte[] { 'b' }, "image/bmp").buildEmail(), true);
    assertEmailEqual(b().withEmbeddedImage(null, new NamedDataSource("n1", new ByteArrayDataSource("data", "image/png"))).buildEmail(), b().withEmbeddedImage(null, new NamedDataSource("n2", new ByteArrayDataSource("data", "image/png"))).buildEmail(), false);
    assertEmailEqual(b().withEmbeddedImage(null, new NamedDataSource("n1", new ByteArrayDataSource("data", "image/png"))).buildEmail(), b().withEmbeddedImage(null, new NamedDataSource("n1", new ByteArrayDataSource("data", "image/jpg"))).buildEmail(), false);
    assertEmailEqual(b().withEmbeddedImage("name", new ByteArrayDataSource("data", "image/png")).buildEmail(), b().withEmbeddedImage("nameOther", new ByteArrayDataSource("data", "image/png")).buildEmail(), false);
    assertEmailEqual(b().withEmbeddedImage("name", new ByteArrayDataSource("data", "image/png")).buildEmail(), b().withEmbeddedImage("name", new ByteArrayDataSource("data", "image/jpg")).buildEmail(), false);
    assertEmailEqual(b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").withEmbeddedImage("name2", new byte[] { 'b' }, "image/bmp").buildEmail(), b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").buildEmail(), false);
    assertEmailEqual(b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").withEmbeddedImage("name2", new byte[] { 'b' }, "image/bmp").buildEmail(), b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").withEmbeddedImage("name3", new byte[] { 'b' }, "image/bmp").buildEmail(), false);
    assertEmailEqual(b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").buildEmail(), b().buildEmail(), false);
}
Also used : NamedDataSource(org.simplejavamail.internal.util.NamedDataSource) ByteArrayDataSource(jakarta.mail.util.ByteArrayDataSource) Test(org.junit.Test)

Aggregations

NamedDataSource (org.simplejavamail.internal.util.NamedDataSource)10 DataSource (jakarta.activation.DataSource)6 Test (org.junit.Test)6 ByteArrayDataSource (jakarta.mail.util.ByteArrayDataSource)4 DataHandler (jakarta.activation.DataHandler)2 BodyPart (jakarta.mail.BodyPart)2 MimeBodyPart (jakarta.mail.internet.MimeBodyPart)2 ParameterList (jakarta.mail.internet.ParameterList)2 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 NotNull (org.jetbrains.annotations.NotNull)1 MiscUtil.tryResolveUrlDataSource (org.simplejavamail.internal.util.MiscUtil.tryResolveUrlDataSource)1