camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/3] git commit: CAMEL-6905: Added peek option to camel-mail. To mark mail as peek for IMAP messages to avoid mail server eager mark the mail as SEEN in case we rollback. Thanks to Dan Ambrose for reporting.
Date Sat, 26 Oct 2013 14:06:21 GMT
CAMEL-6905: Added peek option to camel-mail. To mark mail as peek for IMAP messages to avoid
mail server eager mark the mail as SEEN in case we rollback. Thanks to Dan Ambrose for reporting.


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

Branch: refs/heads/camel-2.11.x
Commit: a01324c7404aa46b45c0701aeb98368017ff4585
Parents: f2e85bb
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Oct 26 16:05:18 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Oct 26 16:06:45 2013 +0200

----------------------------------------------------------------------
 .../camel/component/mail/MailConfiguration.java |  9 +++++++
 .../camel/component/mail/MailConsumer.java      | 26 +++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a01324c7/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 bb0d70e..29c5cca 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
@@ -63,6 +63,7 @@ public class MailConfiguration implements Cloneable {
     private boolean ignoreUnsupportedCharset;
     private boolean disconnect;
     private boolean closeFolder = true;
+    private boolean peek = true;
     private SSLContextParameters sslContextParameters;
 
     public MailConfiguration() {
@@ -493,4 +494,12 @@ public class MailConfiguration implements Cloneable {
     public void setCopyTo(String copyTo) {
         this.copyTo = copyTo;
     }
+
+    public boolean isPeek() {
+        return peek;
+    }
+
+    public void setPeek(boolean peek) {
+        this.peek = peek;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/a01324c7/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
index 829b57f..5bbba45 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
@@ -31,9 +31,9 @@ import javax.mail.Store;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.impl.ScheduledBatchPollingConsumer;
-import org.apache.camel.spi.Synchronization;
 import org.apache.camel.support.SynchronizationAdapter;
 import org.apache.camel.util.CastUtils;
+import org.apache.camel.util.IntrospectionSupport;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -180,6 +180,12 @@ public class MailConsumer extends ScheduledBatchPollingConsumer {
             // must use the original message in case we need to workaround a charset issue
when extracting mail content
             final Message mail = exchange.getIn(MailMessage.class).getOriginalMessage();
 
+            // need to call setPeek on java-mail to avoid the message being flagged eagerly
as SEEN on the server in case
+            // we process the message and rollback due an exception
+            if (getEndpoint().getConfiguration().isPeek()) {
+                peekMessage(mail);
+            }
+
             // add on completion to handle after work when the exchange is done
             exchange.addOnCompletion(new SynchronizationAdapter() {
                 public void onComplete(Exchange exchange) {
@@ -210,6 +216,19 @@ public class MailConsumer extends ScheduledBatchPollingConsumer {
         return total;
     }
 
+    private void peekMessage(Message mail) {
+        // this only applies to IMAP messages which has a setPeek method
+        if (mail.getClass().getName().startsWith("IMAP")) {
+            try {
+                LOG.trace("Calling setPeek(true) on mail message {}", mail);
+                IntrospectionSupport.setProperty(mail, "peek", true);
+            } catch (Throwable e) {
+                // ignore
+                LOG.trace("Error setting peak property to true on: " + mail + ". This exception
is ignored.", e);
+            }
+        }
+    }
+
     protected Queue<Exchange> createExchanges(Message[] messages) throws MessagingException
{
         Queue<Exchange> answer = new LinkedList<Exchange>();
 
@@ -222,6 +241,11 @@ public class MailConsumer extends ScheduledBatchPollingConsumer {
 
         for (int i = 0; i < count; i++) {
             Message message = messages[i];
+
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Mail #{} is of type: {} - {}", new Object[]{i, ObjectHelper.classCanonicalName(message),
message});
+            }
+
             if (!message.getFlags().contains(Flags.Flag.DELETED)) {
                 Exchange exchange = getEndpoint().createExchange(message);
                 if (getEndpoint().getConfiguration().isMapMailMessage()) {


Mime
View raw message