camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1340747 - in /camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail: MailConfiguration.java MailConsumer.java
Date Sun, 20 May 2012 14:52:18 GMT
Author: davsclaus
Date: Sun May 20 14:52:17 2012
New Revision: 1340747

URL: http://svn.apache.org/viewvc?rev=1340747&view=rev
Log:
Added copyTo option. Allow to override delete and copyTo options using headers. Thanks to
Benoit and Daniel for the patches.

Modified:
    camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
    camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java

Modified: camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java?rev=1340747&r1=1340746&r2=1340747&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
(original)
+++ camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
Sun May 20 14:52:17 2012
@@ -48,6 +48,7 @@ public class MailConfiguration implement
     private String from = MailConstants.MAIL_DEFAULT_FROM;
     private String folderName = MailConstants.MAIL_DEFAULT_FOLDER;
     private boolean delete;
+    private String copyTo;
     private boolean unseen = true;
     private boolean ignoreUriScheme;
     private Map<Message.RecipientType, String> recipients = new HashMap<Message.RecipientType,
String>();
@@ -475,4 +476,12 @@ public class MailConfiguration implement
     public void setSslContextParameters(SSLContextParameters sslContextParameters) {
         this.sslContextParameters = sslContextParameters;
     }
+
+    public String getCopyTo() {
+        return copyTo;
+    }
+
+    public void setCopyTo(String copyTo) {
+        this.copyTo = copyTo;
+    }
 }

Modified: camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java?rev=1340747&r1=1340746&r2=1340747&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
(original)
+++ camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
Sun May 20 14:52:17 2012
@@ -275,7 +275,26 @@ public class MailConsumer extends Schedu
                 }
             }
 
-            if (getEndpoint().getConfiguration().isDelete()) {
+            org.apache.camel.Message in = exchange.getIn();
+            MailConfiguration config = getEndpoint().getConfiguration();
+            // header values override configuration values
+            String copyTo = in.getHeader("copyTo", config.getCopyTo(), String.class);
+            boolean delete = in.getHeader("delete", config.isDelete(), boolean.class);
+
+            // Copy message into different imap folder if asked
+            if (config.getProtocol().equals(MailUtils.PROTOCOL_IMAP) || config.getProtocol().equals(MailUtils.PROTOCOL_IMAPS))
{
+                if (copyTo != null) {
+                    LOG.trace("IMAP message needs to be copied to {}", copyTo);
+                    Folder destFolder = store.getFolder(copyTo);
+                    if (!destFolder.exists()) {
+                        destFolder.create(Folder.HOLDS_MESSAGES);
+                    }
+                    folder.copyMessages(new Message[]{mail}, destFolder);
+                    LOG.trace("IMAP message {} copied to {}", mail, copyTo);
+                }
+            }
+
+            if (delete) {
                 LOG.trace("Exchange processed, so flagging message as DELETED");
                 mail.setFlag(Flags.Flag.DELETED, true);
             } else {
@@ -283,8 +302,7 @@ public class MailConsumer extends Schedu
                 mail.setFlag(Flags.Flag.SEEN, true);
             }
         } catch (MessagingException e) {
-            LOG.warn("Error occurred during flagging message as DELETED/SEEN", e);
-            exchange.setException(e);
+            getExceptionHandler().handleException("Error occurred during committing mail
message: " + mail, exchange, e);
         }
     }
 



Mime
View raw message