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 2016/05/05 16:18:52 UTC

[1/2] camel git commit: CAMEL-7536: Possible to use custom resolver for attachments to resolve what content-type-encoding to use. Thanks to Christoph Giera for the patch.

Repository: camel
Updated Branches:
  refs/heads/master 6035880f7 -> 78ab36d22


CAMEL-7536: Possible to use custom resolver for attachments to resolve what content-type-encoding to use. Thanks to Christoph Giera for the patch.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/144b07a5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/144b07a5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/144b07a5

Branch: refs/heads/master
Commit: 144b07a5777c2175595bb00eb7932ea66fc262f7
Parents: 6035880
Author: Claus Ibsen <da...@apache.org>
Authored: Thu May 5 18:16:00 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu May 5 18:18:10 2016 +0200

----------------------------------------------------------------------
 ...achmentsContentTransferEncodingResolver.java | 40 ++++++++++++++++++++
 .../camel/component/mail/MailBinding.java       | 22 +++++++++--
 .../camel/component/mail/MailConfiguration.java | 13 +++++++
 3 files changed, 71 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/144b07a5/components/camel-mail/src/main/java/org/apache/camel/component/mail/AttachmentsContentTransferEncodingResolver.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/AttachmentsContentTransferEncodingResolver.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/AttachmentsContentTransferEncodingResolver.java
new file mode 100644
index 0000000..4bcdf97
--- /dev/null
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/AttachmentsContentTransferEncodingResolver.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mail;
+
+import javax.mail.BodyPart;
+
+/**
+ * Resolver to determine Content-Transfer-Encoding for file attachments.
+ * <br/>
+ * Normally this will be determined automatically, this resolver can be used to
+ * override this behavior.
+ */
+public interface AttachmentsContentTransferEncodingResolver {
+
+    /**
+     * Resolves the content-transfer-encoding.
+     * <p/>
+     * Return <tt>null</tt> if you cannot resolve a content-transfer-encoding or
+     * want to rely on the mail provider to resolve it for you.
+     *
+     * @param messageBodyPart the body part
+     * @return the content-transfer-encoding or <tt>null</tt> to rely on the mail provider
+     */
+    String resolveContentTransferEncoding(BodyPart messageBodyPart);
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/144b07a5/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
index 9b46695..79f4066 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
@@ -446,13 +446,15 @@ public class MailBinding {
         multipart.setSubType("mixed");
         addBodyToMultipart(configuration, multipart, exchange);
         String partDisposition = configuration.isUseInlineAttachments() ? Part.INLINE : Part.ATTACHMENT;
+        AttachmentsContentTransferEncodingResolver contentTransferEncodingResolver = configuration.getAttachmentsContentTransferEncodingResolver();
         if (exchange.getIn().hasAttachments()) {
-            addAttachmentsToMultipart(multipart, partDisposition, exchange);
+            addAttachmentsToMultipart(multipart, partDisposition, contentTransferEncodingResolver, exchange);
         }
         return multipart;
     }
 
-    protected void addAttachmentsToMultipart(MimeMultipart multipart, String partDisposition, Exchange exchange) throws MessagingException {
+    protected void addAttachmentsToMultipart(MimeMultipart multipart, String partDisposition,
+                                             AttachmentsContentTransferEncodingResolver encodingResolver, Exchange exchange) throws MessagingException {
         LOG.trace("Adding attachments +++ start +++");
         int i = 0;
         for (Map.Entry<String, DataHandler> entry : exchange.getIn().getAttachments().entrySet()) {
@@ -494,6 +496,8 @@ public class MailBinding {
                         }
                     }
 
+                    // set Content-Transfer-Encoding using resolver if possible
+                    resolveContentTransferEncoding(encodingResolver, i, messageBodyPart);
                     // Set Disposition
                     messageBodyPart.setDisposition(partDisposition);
                     // Add part to multipart
@@ -509,6 +513,16 @@ public class MailBinding {
         LOG.trace("Adding attachments +++ done +++");
     }
 
+    protected void resolveContentTransferEncoding(AttachmentsContentTransferEncodingResolver resolver, int i, BodyPart messageBodyPart) throws MessagingException {
+        if (resolver != null) {
+            String contentTransferEncoding = resolver.resolveContentTransferEncoding(messageBodyPart);
+            LOG.trace("Attachment #{}: Using content transfer encoding resolver: {} resolved content transfer encoding as: {}", i, resolver, contentTransferEncoding);
+            if (contentTransferEncoding != null) {
+                messageBodyPart.setHeader("Content-Transfer-Encoding", contentTransferEncoding);
+            }
+        }
+    }
+
     protected void createMultipartAlternativeMessage(MimeMessage mimeMessage, MailConfiguration configuration, Exchange exchange)
         throws MessagingException, IOException {
 
@@ -541,8 +555,8 @@ public class MailBinding {
                 multipartAlternative.addBodyPart(related);
 
                 addBodyToMultipart(configuration, multipartRelated, exchange);
-
-                addAttachmentsToMultipart(multipartRelated, Part.INLINE, exchange);
+                AttachmentsContentTransferEncodingResolver resolver = configuration.getAttachmentsContentTransferEncodingResolver();
+                addAttachmentsToMultipart(multipartRelated, Part.INLINE, resolver, exchange);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/144b07a5/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
index a34449f..93b7a94 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
@@ -113,6 +113,8 @@ public class MailConfiguration implements Cloneable {
     private SSLContextParameters sslContextParameters;
     @UriParam(label = "advanced", prefix = "mail.", multiValue = true)
     private Properties additionalJavaMailProperties;
+    @UriParam(label = "advanced")
+    private AttachmentsContentTransferEncodingResolver attachmentsContentTransferEncodingResolver;
 
     public MailConfiguration() {
     }
@@ -726,4 +728,15 @@ public class MailConfiguration implements Cloneable {
     public void setHandleFailedMessage(boolean handleFailedMessage) {
         this.handleFailedMessage = handleFailedMessage;
     }
+
+    public AttachmentsContentTransferEncodingResolver getAttachmentsContentTransferEncodingResolver() {
+        return attachmentsContentTransferEncodingResolver;
+    }
+
+    /**
+     * To use a custom AttachmentsContentTransferEncodingResolver to resolve what content-type-encoding to use for attachments.
+     */
+    public void setAttachmentsContentTransferEncodingResolver(AttachmentsContentTransferEncodingResolver attachmentsContentTransferEncodingResolver) {
+        this.attachmentsContentTransferEncodingResolver = attachmentsContentTransferEncodingResolver;
+    }
 }


[2/2] camel git commit: Updated docs

Posted by da...@apache.org.
Updated docs


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/78ab36d2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/78ab36d2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/78ab36d2

Branch: refs/heads/master
Commit: 78ab36d22ac92fd2c5d0ede09366d695bdd255d0
Parents: 144b07a
Author: Claus Ibsen <da...@apache.org>
Authored: Thu May 5 18:18:43 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu May 5 18:18:43 2016 +0200

----------------------------------------------------------------------
 components/camel-mail/src/main/docs/imap.adoc  | 5 ++++-
 components/camel-mail/src/main/docs/imaps.adoc | 5 ++++-
 components/camel-mail/src/main/docs/pop3.adoc  | 5 ++++-
 components/camel-mail/src/main/docs/pop3s.adoc | 5 ++++-
 components/camel-mail/src/main/docs/smtp.adoc  | 5 ++++-
 components/camel-mail/src/main/docs/smtps.adoc | 5 ++++-
 6 files changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/78ab36d2/components/camel-mail/src/main/docs/imap.adoc
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/docs/imap.adoc b/components/camel-mail/src/main/docs/imap.adoc
index 1e1c401..d4078d4 100644
--- a/components/camel-mail/src/main/docs/imap.adoc
+++ b/components/camel-mail/src/main/docs/imap.adoc
@@ -18,8 +18,9 @@ The IMAP component supports 2 options which are listed below.
 
 
 
+
 // endpoint options: START
-The IMAP component supports 62 endpoint options which are listed below:
+The IMAP component supports 63 endpoint options which are listed below:
 
 [width="100%",cols="2s,1,1m,1m,5",options="header"]
 |=======================================================================
@@ -53,6 +54,7 @@ The IMAP component supports 62 endpoint options which are listed below:
 | javaMailSender | producer (advanced) |  | JavaMailSender | To use a custom org.apache.camel.component.mail.JavaMailSender for sending emails.
 | additionalJavaMailProperties | advanced |  | Properties | Sets additional java mail properties that will append/override any default properties that is set based on all the other options. This is useful if you need to add some special options but want to keep the others as is.
 | alternativeBodyHeader | advanced | CamelMailAlternativeBody | String | Specifies the key to an IN message header that contains an alternative email body. For example if you send emails in text/html format and want to provide an alternative mail body for non-HTML email clients set the alternative mail body with this key as a header.
+| attachmentsContentTransferEncodingResolver | advanced |  | AttachmentsContentTransferEncodingResolver | To use a custom AttachmentsContentTransferEncodingResolver to resolve what content-type-encoding to use for attachments.
 | binding | advanced |  | MailBinding | Sets the binding used to convert from a Camel message to and from a Mail message
 | connectionTimeout | advanced | 30000 | int | The connection timeout in milliseconds.
 | contentType | advanced | text/plain | String | The mail message content type. Use text/html for HTML mails.
@@ -89,3 +91,4 @@ The IMAP component supports 62 endpoint options which are listed below:
 |=======================================================================
 // endpoint options: END
 
+

http://git-wip-us.apache.org/repos/asf/camel/blob/78ab36d2/components/camel-mail/src/main/docs/imaps.adoc
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/docs/imaps.adoc b/components/camel-mail/src/main/docs/imaps.adoc
index 9d109e1..373bf47 100644
--- a/components/camel-mail/src/main/docs/imaps.adoc
+++ b/components/camel-mail/src/main/docs/imaps.adoc
@@ -18,8 +18,9 @@ The IMAPS component supports 2 options which are listed below.
 
 
 
+
 // endpoint options: START
-The IMAPS component supports 62 endpoint options which are listed below:
+The IMAPS component supports 63 endpoint options which are listed below:
 
 [width="100%",cols="2s,1,1m,1m,5",options="header"]
 |=======================================================================
@@ -53,6 +54,7 @@ The IMAPS component supports 62 endpoint options which are listed below:
 | javaMailSender | producer (advanced) |  | JavaMailSender | To use a custom org.apache.camel.component.mail.JavaMailSender for sending emails.
 | additionalJavaMailProperties | advanced |  | Properties | Sets additional java mail properties that will append/override any default properties that is set based on all the other options. This is useful if you need to add some special options but want to keep the others as is.
 | alternativeBodyHeader | advanced | CamelMailAlternativeBody | String | Specifies the key to an IN message header that contains an alternative email body. For example if you send emails in text/html format and want to provide an alternative mail body for non-HTML email clients set the alternative mail body with this key as a header.
+| attachmentsContentTransferEncodingResolver | advanced |  | AttachmentsContentTransferEncodingResolver | To use a custom AttachmentsContentTransferEncodingResolver to resolve what content-type-encoding to use for attachments.
 | binding | advanced |  | MailBinding | Sets the binding used to convert from a Camel message to and from a Mail message
 | connectionTimeout | advanced | 30000 | int | The connection timeout in milliseconds.
 | contentType | advanced | text/plain | String | The mail message content type. Use text/html for HTML mails.
@@ -89,3 +91,4 @@ The IMAPS component supports 62 endpoint options which are listed below:
 |=======================================================================
 // endpoint options: END
 
+

http://git-wip-us.apache.org/repos/asf/camel/blob/78ab36d2/components/camel-mail/src/main/docs/pop3.adoc
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/docs/pop3.adoc b/components/camel-mail/src/main/docs/pop3.adoc
index 66bcac6..29c5c1d 100644
--- a/components/camel-mail/src/main/docs/pop3.adoc
+++ b/components/camel-mail/src/main/docs/pop3.adoc
@@ -18,8 +18,9 @@ The POP3 component supports 2 options which are listed below.
 
 
 
+
 // endpoint options: START
-The POP3 component supports 62 endpoint options which are listed below:
+The POP3 component supports 63 endpoint options which are listed below:
 
 [width="100%",cols="2s,1,1m,1m,5",options="header"]
 |=======================================================================
@@ -53,6 +54,7 @@ The POP3 component supports 62 endpoint options which are listed below:
 | javaMailSender | producer (advanced) |  | JavaMailSender | To use a custom org.apache.camel.component.mail.JavaMailSender for sending emails.
 | additionalJavaMailProperties | advanced |  | Properties | Sets additional java mail properties that will append/override any default properties that is set based on all the other options. This is useful if you need to add some special options but want to keep the others as is.
 | alternativeBodyHeader | advanced | CamelMailAlternativeBody | String | Specifies the key to an IN message header that contains an alternative email body. For example if you send emails in text/html format and want to provide an alternative mail body for non-HTML email clients set the alternative mail body with this key as a header.
+| attachmentsContentTransferEncodingResolver | advanced |  | AttachmentsContentTransferEncodingResolver | To use a custom AttachmentsContentTransferEncodingResolver to resolve what content-type-encoding to use for attachments.
 | binding | advanced |  | MailBinding | Sets the binding used to convert from a Camel message to and from a Mail message
 | connectionTimeout | advanced | 30000 | int | The connection timeout in milliseconds.
 | contentType | advanced | text/plain | String | The mail message content type. Use text/html for HTML mails.
@@ -89,3 +91,4 @@ The POP3 component supports 62 endpoint options which are listed below:
 |=======================================================================
 // endpoint options: END
 
+

http://git-wip-us.apache.org/repos/asf/camel/blob/78ab36d2/components/camel-mail/src/main/docs/pop3s.adoc
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/docs/pop3s.adoc b/components/camel-mail/src/main/docs/pop3s.adoc
index 850425b..7b9269a 100644
--- a/components/camel-mail/src/main/docs/pop3s.adoc
+++ b/components/camel-mail/src/main/docs/pop3s.adoc
@@ -18,8 +18,9 @@ The POP3S component supports 2 options which are listed below.
 
 
 
+
 // endpoint options: START
-The POP3S component supports 62 endpoint options which are listed below:
+The POP3S component supports 63 endpoint options which are listed below:
 
 [width="100%",cols="2s,1,1m,1m,5",options="header"]
 |=======================================================================
@@ -53,6 +54,7 @@ The POP3S component supports 62 endpoint options which are listed below:
 | javaMailSender | producer (advanced) |  | JavaMailSender | To use a custom org.apache.camel.component.mail.JavaMailSender for sending emails.
 | additionalJavaMailProperties | advanced |  | Properties | Sets additional java mail properties that will append/override any default properties that is set based on all the other options. This is useful if you need to add some special options but want to keep the others as is.
 | alternativeBodyHeader | advanced | CamelMailAlternativeBody | String | Specifies the key to an IN message header that contains an alternative email body. For example if you send emails in text/html format and want to provide an alternative mail body for non-HTML email clients set the alternative mail body with this key as a header.
+| attachmentsContentTransferEncodingResolver | advanced |  | AttachmentsContentTransferEncodingResolver | To use a custom AttachmentsContentTransferEncodingResolver to resolve what content-type-encoding to use for attachments.
 | binding | advanced |  | MailBinding | Sets the binding used to convert from a Camel message to and from a Mail message
 | connectionTimeout | advanced | 30000 | int | The connection timeout in milliseconds.
 | contentType | advanced | text/plain | String | The mail message content type. Use text/html for HTML mails.
@@ -89,3 +91,4 @@ The POP3S component supports 62 endpoint options which are listed below:
 |=======================================================================
 // endpoint options: END
 
+

http://git-wip-us.apache.org/repos/asf/camel/blob/78ab36d2/components/camel-mail/src/main/docs/smtp.adoc
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/docs/smtp.adoc b/components/camel-mail/src/main/docs/smtp.adoc
index 91bcec1..a457122 100644
--- a/components/camel-mail/src/main/docs/smtp.adoc
+++ b/components/camel-mail/src/main/docs/smtp.adoc
@@ -18,8 +18,9 @@ The SMTP component supports 2 options which are listed below.
 
 
 
+
 // endpoint options: START
-The SMTP component supports 62 endpoint options which are listed below:
+The SMTP component supports 63 endpoint options which are listed below:
 
 [width="100%",cols="2s,1,1m,1m,5",options="header"]
 |=======================================================================
@@ -53,6 +54,7 @@ The SMTP component supports 62 endpoint options which are listed below:
 | javaMailSender | producer (advanced) |  | JavaMailSender | To use a custom org.apache.camel.component.mail.JavaMailSender for sending emails.
 | additionalJavaMailProperties | advanced |  | Properties | Sets additional java mail properties that will append/override any default properties that is set based on all the other options. This is useful if you need to add some special options but want to keep the others as is.
 | alternativeBodyHeader | advanced | CamelMailAlternativeBody | String | Specifies the key to an IN message header that contains an alternative email body. For example if you send emails in text/html format and want to provide an alternative mail body for non-HTML email clients set the alternative mail body with this key as a header.
+| attachmentsContentTransferEncodingResolver | advanced |  | AttachmentsContentTransferEncodingResolver | To use a custom AttachmentsContentTransferEncodingResolver to resolve what content-type-encoding to use for attachments.
 | binding | advanced |  | MailBinding | Sets the binding used to convert from a Camel message to and from a Mail message
 | connectionTimeout | advanced | 30000 | int | The connection timeout in milliseconds.
 | contentType | advanced | text/plain | String | The mail message content type. Use text/html for HTML mails.
@@ -89,3 +91,4 @@ The SMTP component supports 62 endpoint options which are listed below:
 |=======================================================================
 // endpoint options: END
 
+

http://git-wip-us.apache.org/repos/asf/camel/blob/78ab36d2/components/camel-mail/src/main/docs/smtps.adoc
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/docs/smtps.adoc b/components/camel-mail/src/main/docs/smtps.adoc
index 8bd2512..b26575b 100644
--- a/components/camel-mail/src/main/docs/smtps.adoc
+++ b/components/camel-mail/src/main/docs/smtps.adoc
@@ -18,8 +18,9 @@ The SMTPS component supports 2 options which are listed below.
 
 
 
+
 // endpoint options: START
-The SMTPS component supports 62 endpoint options which are listed below:
+The SMTPS component supports 63 endpoint options which are listed below:
 
 [width="100%",cols="2s,1,1m,1m,5",options="header"]
 |=======================================================================
@@ -53,6 +54,7 @@ The SMTPS component supports 62 endpoint options which are listed below:
 | javaMailSender | producer (advanced) |  | JavaMailSender | To use a custom org.apache.camel.component.mail.JavaMailSender for sending emails.
 | additionalJavaMailProperties | advanced |  | Properties | Sets additional java mail properties that will append/override any default properties that is set based on all the other options. This is useful if you need to add some special options but want to keep the others as is.
 | alternativeBodyHeader | advanced | CamelMailAlternativeBody | String | Specifies the key to an IN message header that contains an alternative email body. For example if you send emails in text/html format and want to provide an alternative mail body for non-HTML email clients set the alternative mail body with this key as a header.
+| attachmentsContentTransferEncodingResolver | advanced |  | AttachmentsContentTransferEncodingResolver | To use a custom AttachmentsContentTransferEncodingResolver to resolve what content-type-encoding to use for attachments.
 | binding | advanced |  | MailBinding | Sets the binding used to convert from a Camel message to and from a Mail message
 | connectionTimeout | advanced | 30000 | int | The connection timeout in milliseconds.
 | contentType | advanced | text/plain | String | The mail message content type. Use text/html for HTML mails.
@@ -89,3 +91,4 @@ The SMTPS component supports 62 endpoint options which are listed below:
 |=======================================================================
 // endpoint options: END
 
+