You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2024/06/25 09:10:38 UTC
(camel) 02/02: CAMEL-20907: camel-mail - PollEnrich should work with stream caching to ignore if folder is not open.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch msc
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 42ebca7c135009da18fcca259709dcf9e0de5e38
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Jun 25 11:10:14 2024 +0200
CAMEL-20907: camel-mail - PollEnrich should work with stream caching to ignore if folder is not open.
---
.../camel/component/mail/MailConverters.java | 35 ++++++++++++++--------
.../mail/MailAttachmentPollEnrichTest.java | 8 ++++-
2 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
index 0abdeadd5ba..846c8f18168 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
@@ -80,21 +80,30 @@ public final class MailConverters {
*/
@Converter
public static String toString(Multipart multipart) throws MessagingException, IOException {
- int size = multipart.getCount();
- for (int i = 0; i < size; i++) {
- BodyPart part = multipart.getBodyPart(i);
- Object content = part.getContent();
- while (content instanceof MimeMultipart) {
- if (multipart.getCount() < 1) {
- break;
+ try {
+ int size = multipart.getCount();
+ for (int i = 0; i < size; i++) {
+ BodyPart part = multipart.getBodyPart(i);
+ Object content = part.getContent();
+ while (content instanceof MimeMultipart) {
+ if (multipart.getCount() < 1) {
+ break;
+ }
+ part = ((MimeMultipart) content).getBodyPart(0);
+ content = part.getContent();
+ }
+ // Perform a case-insensitive "startsWith" check that works for different locales
+ String prefix = "text";
+ if (part.getContentType().regionMatches(true, 0, prefix, 0, prefix.length())) {
+ return part.getContent().toString();
}
- part = ((MimeMultipart) content).getBodyPart(0);
- content = part.getContent();
}
- // Perform a case insensitive "startsWith" check that works for different locales
- String prefix = "text";
- if (part.getContentType().regionMatches(true, 0, prefix, 0, prefix.length())) {
- return part.getContent().toString();
+ } catch (MessagingException e) {
+ Throwable cause = e.getCause();
+ if (cause != null && "Folder is not Open".equals(cause.getMessage())) {
+ // ignore if folder is not open and we cannot read the mail
+ } else {
+ throw e;
}
}
return null;
diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailAttachmentPollEnrichTest.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailAttachmentPollEnrichTest.java
index ae81d4f7eb9..d6f93411dda 100644
--- a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailAttachmentPollEnrichTest.java
+++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailAttachmentPollEnrichTest.java
@@ -107,13 +107,19 @@ public class MailAttachmentPollEnrichTest extends CamelTestSupport {
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
- from("direct:start").streamCache("false")
+ from("direct:start")
.pollEnrich(james.uriPrefix(Protocol.pop3) + "&initialDelay=100&delay=100", 5000)
.process(e -> {
AttachmentMessage attachmentMessage = e.getIn(AttachmentMessage.class);
Map<String, DataHandler> attachments = attachmentMessage.getAttachments();
assertEquals(1, attachments.size());
assertEquals("logo.jpeg", attachments.keySet().iterator().next());
+
+ DataHandler dh = attachments.values().iterator().next();
+ byte[] data = context.getTypeConverter().convertTo(byte[].class, e, dh.getInputStream());
+ assertNotNull(data);
+ // should be logo that are 10.000 bytes or longer
+ assertTrue(data.length > 10000, "Should be 10000 bytes or more");
})
.to("mock:result");
}