You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2023/04/04 02:45:53 UTC
[james-project] 05/09: [UPGRADE] Mime4J 0.8.9: dispose messages
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 3310c2685154ca06213416bea0b0348684d0822f
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Jan 12 10:36:01 2023 +0700
[UPGRADE] Mime4J 0.8.9: dispose messages
---
.../model/openjpa/AbstractJPAMailboxMessage.java | 6 +-
.../apache/james/mailbox/store/MessageStorer.java | 15 +-
.../store/mail/model/impl/MessageParser.java | 25 +++-
.../store/mail/model/impl/MessageParserTest.java | 157 +++++++++++----------
4 files changed, 116 insertions(+), 87 deletions(-)
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
index d8c40546db..2b9887f18b 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
@@ -529,12 +529,16 @@ public abstract class AbstractJPAMailboxMessage implements MailboxMessage {
public List<MessageAttachmentMetadata> getAttachments() {
try {
AtomicInteger counter = new AtomicInteger(0);
- return new MessageParser().retrieveAttachments(getFullContent())
+ MessageParser.ParsingResult parsingResult = new MessageParser().retrieveAttachments(getFullContent());
+ ImmutableList<MessageAttachmentMetadata> result = parsingResult
+ .getAttachments()
.stream()
.map(Throwing.<ParsedAttachment, MessageAttachmentMetadata>function(
attachmentMetadata -> attachmentMetadata.asMessageAttachment(generateFixedAttachmentId(counter.incrementAndGet()), getMessageId()))
.sneakyThrow())
.collect(ImmutableList.toImmutableList());
+ parsingResult.dispose();
+ return result;
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
index b612de7b45..bebe032181 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
@@ -119,25 +119,28 @@ public interface MessageStorer {
}
private Mono<List<MessageAttachmentMetadata>> storeAttachments(MessageId messageId, Content messageContent, Optional<Message> maybeMessage, MailboxSession session) {
- List<ParsedAttachment> attachments = extractAttachments(messageContent, maybeMessage);
+ MessageParser.ParsingResult attachments = extractAttachments(messageContent, maybeMessage);
return attachmentMapperFactory.getAttachmentMapper(session)
- .storeAttachmentsReactive(attachments, messageId);
+ .storeAttachmentsReactive(attachments.getAttachments(), messageId)
+ .doFinally(any -> attachments.dispose());
}
- private List<ParsedAttachment> extractAttachments(Content contentIn, Optional<Message> maybeMessage) {
+ private MessageParser.ParsingResult extractAttachments(Content contentIn, Optional<Message> maybeMessage) {
return maybeMessage.map(message -> {
try {
- return messageParser.retrieveAttachments(message);
+ return new MessageParser.ParsingResult(messageParser.retrieveAttachments(message), () -> {
+
+ });
} catch (Exception e) {
LOGGER.warn("Error while parsing mail's attachments: {}", e.getMessage(), e);
- return ImmutableList.<ParsedAttachment>of();
+ return MessageParser.ParsingResult.EMPTY;
}
}).orElseGet(() -> {
try (InputStream inputStream = contentIn.getInputStream()) {
return messageParser.retrieveAttachments(inputStream);
} catch (Exception e) {
LOGGER.warn("Error while parsing mail's attachments: {}", e.getMessage(), e);
- return ImmutableList.of();
+ return MessageParser.ParsingResult.EMPTY;
}
});
}
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
index 482685905b..9488adc510 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
@@ -54,6 +54,27 @@ import com.google.common.collect.ImmutableList;
import com.google.common.io.ByteSource;
public class MessageParser {
+ public static class ParsingResult {
+ public static final ParsingResult EMPTY = new ParsingResult(ImmutableList.of(), () -> {
+
+ });
+
+ private final List<ParsedAttachment> attachments;
+ private final Runnable dispose;
+
+ public ParsingResult(List<ParsedAttachment> attachments, Runnable dispose) {
+ this.attachments = attachments;
+ this.dispose = dispose;
+ }
+
+ public List<ParsedAttachment> getAttachments() {
+ return attachments;
+ }
+
+ public void dispose() {
+ dispose.run();
+ }
+ }
private static final String TEXT_MEDIA_TYPE = "text";
private static final String CONTENT_TYPE = "Content-Type";
@@ -81,12 +102,12 @@ public class MessageParser {
.unwrap();
}
- public List<ParsedAttachment> retrieveAttachments(InputStream fullContent) throws IOException {
+ public ParsingResult retrieveAttachments(InputStream fullContent) throws IOException {
DefaultMessageBuilder defaultMessageBuilder = new DefaultMessageBuilder();
defaultMessageBuilder.setMimeEntityConfig(MimeConfig.PERMISSIVE);
defaultMessageBuilder.setDecodeMonitor(DecodeMonitor.SILENT);
Message message = defaultMessageBuilder.parseMessage(fullContent);
- return retrieveAttachments(message);
+ return new ParsingResult(retrieveAttachments(message), message::dispose);
}
public List<ParsedAttachment> retrieveAttachments(Message message) throws IOException {
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
index e4af546c26..eff94b64a0 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
@@ -50,120 +50,120 @@ class MessageParserTest {
@Test
void getAttachmentsShouldBeEmptyWhenNoAttachment() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/noAttachment.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/noAttachment.eml"));
- assertThat(attachments).isEmpty();
+ assertThat(attachments.getAttachments()).isEmpty();
}
@Test
void getAttachmentsShouldIgnoreInlineWhenMixedMultipart() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/inlined-mixed.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/inlined-mixed.eml"));
- assertThat(attachments).hasSize(2);
+ assertThat(attachments.getAttachments()).hasSize(2);
}
@Test
void getAttachmentsShouldRetrieveAttachmentsWhenOneAttachment() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentAndSomeTextInlined.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentAndSomeTextInlined.eml"));
- assertThat(attachments).hasSize(1);
+ assertThat(attachments.getAttachments()).hasSize(1);
}
@Test
void getAttachmentsShouldRetrieveAttachmentNameWhenOne() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentAndSomeTextInlined.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentAndSomeTextInlined.eml"));
- assertThat(attachments).hasSize(1);
+ assertThat(attachments.getAttachments()).hasSize(1);
Optional<String> expectedName = Optional.of("exploits_of_a_mom.png");
- assertThat(attachments.get(0).getName()).isEqualTo(expectedName);
+ assertThat(attachments.getAttachments().get(0).getName()).isEqualTo(expectedName);
}
@Test
void getAttachmentsShouldRetrieveAttachmentNameWhenOneContainingNonASCIICharacters() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/messageWithNonASCIIFilenameAttachment.eml"));
- assertThat(attachments).hasSize(1);
- assertThat(attachments.get(0).getName()).contains("ديناصور.odt");
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/messageWithNonASCIIFilenameAttachment.eml"));
+ assertThat(attachments.getAttachments()).hasSize(1);
+ assertThat(attachments.getAttachments().get(0).getName()).contains("ديناصور.odt");
}
@Test
void getAttachmentsShouldRetrieveEmptyNameWhenNone() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentWithoutName.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentWithoutName.eml"));
- assertThat(attachments).hasSize(1);
- assertThat(attachments.get(0).getName()).isEqualTo(Optional.empty());
+ assertThat(attachments.getAttachments()).hasSize(1);
+ assertThat(attachments.getAttachments().get(0).getName()).isEqualTo(Optional.empty());
}
@Test
void getAttachmentsShouldNotFailWhenContentTypeIsNotHere() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentWithoutContentType.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentWithoutContentType.eml"));
- assertThat(attachments).hasSize(1);
- assertThat(attachments.get(0).getContentType())
+ assertThat(attachments.getAttachments()).hasSize(1);
+ assertThat(attachments.getAttachments().get(0).getContentType())
.isEqualTo(ContentType.of("application/octet-stream"));
}
@Test
void getAttachmentsShouldNotFailWhenContentTypeIsEmpty() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentWithEmptyContentType.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentWithEmptyContentType.eml"));
- assertThat(attachments).hasSize(1);
- assertThat(attachments.get(0).getContentType())
+ assertThat(attachments.getAttachments()).hasSize(1);
+ assertThat(attachments.getAttachments().get(0).getContentType())
.isEqualTo(ContentType.of("application/octet-stream"));
}
@Test
void getAttachmentsShouldRetrieveTheAttachmentContentTypeWhenOneAttachment() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentAndSomeTextInlined.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentAndSomeTextInlined.eml"));
- assertThat(attachments).hasSize(1);
- assertThat(attachments.get(0).getContentType())
+ assertThat(attachments.getAttachments()).hasSize(1);
+ assertThat(attachments.getAttachments().get(0).getContentType())
.isEqualTo(ContentType.of("application/octet-stream;\tname=\"exploits_of_a_mom.png\""));
}
@Test
void retrieveAttachmentsShouldNotFailOnMessagesWithManyHeaders() throws Exception {
- List<ParsedAttachment> messageAttachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/mailWithManyHeaders.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/mailWithManyHeaders.eml"));
- assertThat(messageAttachments).hasSize(1);
+ assertThat(attachments.getAttachments()).hasSize(1);
}
@Test
void retrieveAttachmentsShouldNotFailOnMessagesWithLongHeaders() throws Exception {
- List<ParsedAttachment> messageAttachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/mailWithLongHeaders.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/mailWithLongHeaders.eml"));
- assertThat(messageAttachments).hasSize(1);
+ assertThat(attachments.getAttachments()).hasSize(1);
}
@Test
void getAttachmentsShouldRetrieveTheAttachmentContentTypeWhenOneAttachmentWithSimpleContentType() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentWithSimpleContentType.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentWithSimpleContentType.eml"));
- assertThat(attachments).hasSize(1);
- assertThat(attachments.get(0).getContentType())
+ assertThat(attachments.getAttachments()).hasSize(1);
+ assertThat(attachments.getAttachments().get(0).getContentType())
.isEqualTo(ContentType.of("application/octet-stream"));
}
@Test
void getAttachmentsShouldReturnTheExpectedAttachment() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentAndSomeTextInlined.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentAndSomeTextInlined.eml"));
- ParsedAttachment attachment = attachments.get(0);
+ ParsedAttachment attachment = attachments.getAttachments().get(0);
assertThat(attachment.getContent().openStream())
.hasSameContentAs(ClassLoader.getSystemResourceAsStream("eml/gimp.png"));
}
@Test
void getAttachmentsShouldRetrieveAttachmentsWhenTwo() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"));
- assertThat(attachments).hasSize(2);
+ assertThat(attachments.getAttachments()).hasSize(2);
}
@Test
void retrieveAttachmentShouldUseFilenameAsNameWhenNoName() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/filenameOnly.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/filenameOnly.eml"));
- assertThat(attachments).hasSize(1)
+ assertThat(attachments.getAttachments()).hasSize(1)
.extracting(ParsedAttachment::getName)
.allMatch(Optional::isPresent)
.extracting(Optional::get)
@@ -172,9 +172,9 @@ class MessageParserTest {
@Test
void retrieveAttachmentShouldUseNameWhenBothNameAndFilename() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/filenameAndName.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/filenameAndName.eml"));
- assertThat(attachments).hasSize(1)
+ assertThat(attachments.getAttachments()).hasSize(1)
.extracting(ParsedAttachment::getName)
.allMatch(Optional::isPresent)
.extracting(Optional::get)
@@ -183,104 +183,104 @@ class MessageParserTest {
@Test
void getAttachmentsShouldRetrieveEmbeddedAttachmentsWhenSome() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/embeddedAttachmentWithInline.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/embeddedAttachmentWithInline.eml"));
- assertThat(attachments).hasSize(1);
+ assertThat(attachments.getAttachments()).hasSize(1);
}
@Test
void getAttachmentsShouldRetrieveInlineAttachmentsWhenSome() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/embeddedAttachmentWithAttachment.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/embeddedAttachmentWithAttachment.eml"));
- assertThat(attachments).hasSize(1);
+ assertThat(attachments.getAttachments()).hasSize(1);
}
@Test
void getAttachmentsShouldRetrieveTheAttachmentCIDWhenOne() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachment.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachment.eml"));
- assertThat(attachments).hasSize(1);
- assertThat(attachments.get(0).getCid()).isEqualTo(Optional.of(Cid.from("part1.37A15C92.A7C3488D@linagora.com")));
+ assertThat(attachments.getAttachments()).hasSize(1);
+ assertThat(attachments.getAttachments().get(0).getCid()).isEqualTo(Optional.of(Cid.from("part1.37A15C92.A7C3488D@linagora.com")));
}
@Test
void getAttachmentsShouldSetInlineWhenOneInlinedAttachment() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachment.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachment.eml"));
- assertThat(attachments).hasSize(1);
- assertThat(attachments.get(0).isInline()).isTrue();
+ assertThat(attachments.getAttachments()).hasSize(1);
+ assertThat(attachments.getAttachments().get(0).isInline()).isTrue();
}
@Test
void getAttachementsShouldRetrieveHtmlAttachementsWhenSome() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneHtmlAttachmentAndSomeTextInlined.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneHtmlAttachmentAndSomeTextInlined.eml"));
- assertThat(attachments).hasSize(1);
+ assertThat(attachments.getAttachments()).hasSize(1);
}
@Test
void getAttachementsShouldRetrieveAttachmentsWhenSomeAreInTheMultipartAlternative() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/invitationEmailFromOP.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/invitationEmailFromOP.eml"));
- assertThat(attachments).hasSize(6);
+ assertThat(attachments.getAttachments()).hasSize(6);
}
@Test
void getAttachmentsShouldNotConsiderUnknownContentDispositionAsAttachments() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/unknownDisposition.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/unknownDisposition.eml"));
- assertThat(attachments).hasSize(0);
+ assertThat(attachments.getAttachments()).hasSize(0);
}
@Test
void getAttachmentsShouldConsiderNoContentDispositionAsAttachmentsWhenCID() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/noContentDispositionWithCID.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/noContentDispositionWithCID.eml"));
- assertThat(attachments).hasSize(1);
+ assertThat(attachments.getAttachments()).hasSize(1);
}
@Test
void getAttachmentsShouldRetrieveAttachmentsWhenNoCidForInlined() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachmentWithNoCid.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachmentWithNoCid.eml"));
- assertThat(attachments).hasSize(1);
+ assertThat(attachments.getAttachments()).hasSize(1);
}
@Test
void getAttachmentsShouldRetrieveAttachmentsWhenEmptyCidForInlined() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachmentWithEmptyCid.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachmentWithEmptyCid.eml"));
- assertThat(attachments).hasSize(1);
+ assertThat(attachments.getAttachments()).hasSize(1);
}
@Test
void getAttachmentsShouldRetrieveAttachmentsWhenBlankCidForInlined() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachmentWithBlankCid.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachmentWithBlankCid.eml"));
- assertThat(attachments).hasSize(1);
+ assertThat(attachments.getAttachments()).hasSize(1);
}
@Test
void getAttachmentsShouldRetrieveAttachmentsWhenOneFailOnWrongContentDisposition() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/multiAttachmentsWithOneWrongContentDisposition.eml"));
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/multiAttachmentsWithOneWrongContentDisposition.eml"));
- assertThat(attachments).hasSize(2);
+ assertThat(attachments.getAttachments()).hasSize(2);
}
@Test
void getAttachmentsShouldRetrieveOneAttachmentWhenMessageWithAttachmentContentDisposition() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(
ClassLoader.getSystemResourceAsStream("eml/emailWithOnlyAttachment.eml"));
- assertThat(attachments).hasSize(1);
+ assertThat(attachments.getAttachments()).hasSize(1);
}
@Test
void getAttachmentsShouldRetrieveCharset() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(
ClassLoader.getSystemResourceAsStream("eml/charset.eml"));
- assertThat(attachments).hasSize(1)
+ assertThat(attachments.getAttachments()).hasSize(1)
.first()
.satisfies(attachment -> assertThat(attachment.getContentType())
.isEqualTo(ContentType.of("text/calendar; charset=\"iso-8859-1\"; method=COUNTER")));
@@ -288,10 +288,10 @@ class MessageParserTest {
@Test
void getAttachmentsShouldRetrieveAllPartsCharset() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(
ClassLoader.getSystemResourceAsStream("eml/charset2.eml"));
- assertThat(attachments).hasSize(2)
+ assertThat(attachments.getAttachments()).hasSize(2)
.extracting(ParsedAttachment::getContentType)
.containsOnly(ContentType.of("text/calendar; charset=\"iso-8859-1\"; method=COUNTER"),
ContentType.of("text/calendar; charset=\"iso-4444-5\"; method=COUNTER"));
@@ -299,19 +299,19 @@ class MessageParserTest {
@Test
void getAttachmentsShouldNotConsiderTextCalendarAsAttachmentsByDefault() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(
ClassLoader.getSystemResourceAsStream("eml/calendar.eml"));
- assertThat(attachments)
+ assertThat(attachments.getAttachments())
.isEmpty();
}
@Test
void getAttachmentsShouldConsiderTextCalendarAsAttachments() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(
ClassLoader.getSystemResourceAsStream("eml/calendar2.eml"));
- assertThat(attachments)
+ assertThat(attachments.getAttachments())
.hasSize(1)
.extracting(ParsedAttachment::getContentType)
.containsExactly(ContentType.of("text/calendar; charset=\"utf-8\"; method=COUNTER"));
@@ -319,10 +319,10 @@ class MessageParserTest {
@Test
void gpgSignatureShouldBeConsideredAsAnAttachment() throws Exception {
- List<ParsedAttachment> attachments = testee.retrieveAttachments(
+ MessageParser.ParsingResult attachments = testee.retrieveAttachments(
ClassLoader.getSystemResourceAsStream("eml/signedMessage.eml"));
- assertThat(attachments).hasSize(2)
+ assertThat(attachments.getAttachments()).hasSize(2)
.extracting(ParsedAttachment::getName)
.allMatch(Optional::isPresent)
.extracting(Optional::get)
@@ -348,7 +348,8 @@ class MessageParserTest {
.asMime4JMessageBuilder()
.build();
- List<ParsedAttachment> result = testee.retrieveAttachments(new ByteArrayInputStream(DefaultMessageWriter.asBytes(message)));
+ List<ParsedAttachment> result = testee.retrieveAttachments(new ByteArrayInputStream(DefaultMessageWriter.asBytes(message)))
+ .getAttachments();
assertThat(result).hasSize(1)
.allMatch(attachment -> attachment.getContentType().equals(ContentType.of("message/disposition-notification; charset=UTF-8")));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org