Repository: camel Updated Branches: refs/heads/camel-2.15.x e36c7bfcb -> 5d3f32913 refs/heads/camel-2.16.x 705fba25f -> 588cac7c3 refs/heads/master e9cac21a5 -> 1907750e7
CAMEL-9106: URI option mapMailMessage doesn't obey peek=true option. Thanks to Jussi Nupponen 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/1907750e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1907750e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1907750e Branch: refs/heads/master Commit: 1907750e7c4851fffe8b3ef1ab2fc6361d80aa08 Parents: e9cac21 Author: Claus Ibsen <davscl...@apache.org> Authored: Sat Jan 9 15:51:21 2016 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sat Jan 9 15:51:21 2016 +0100 ---------------------------------------------------------------------- .../camel/component/mail/MailConsumer.java | 14 ++--- .../component/mail/MapMailMessagesBugRoute.java | 55 ++++++++++++++++++++ 2 files changed, 62 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/1907750e/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 7ba9397..170b5ec 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 @@ -117,7 +117,13 @@ public class MailConsumer extends ScheduledBatchPollingConsumer { int count = folder.getMessageCount(); if (count > 0) { Message[] messages = retrieveMessages(); - + // 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()) { + for (Message message : messages) { + peekMessage(message); + } + } polledMessages = processBatch(CastUtils.cast(createExchanges(messages))); final MailBoxPostProcessAction postProcessor = getEndpoint().getPostProcessAction(); @@ -187,12 +193,6 @@ 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) { http://git-wip-us.apache.org/repos/asf/camel/blob/1907750e/components/camel-mail/src/test/java/org/apache/camel/component/mail/MapMailMessagesBugRoute.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MapMailMessagesBugRoute.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MapMailMessagesBugRoute.java new file mode 100644 index 0000000..1b22704 --- /dev/null +++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MapMailMessagesBugRoute.java @@ -0,0 +1,55 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 java.io.IOException; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.main.Main; + +/** + * CAMEL-9106 + */ +public class MapMailMessagesBugRoute extends RouteBuilder { + + public static void main(String... args) throws Exception { + Main main = new Main(); + main.enableHangupSupport(); + main.addRouteBuilder(new MapMailMessagesBugRoute()); + main.run(args); + } + + public void configure() { + // This is for Office365 host. Set your own host/username/password. + // When setting option mapMailMessage=true (the default) option peek=true fails with the SEEN flag. + // When setting option mapMailMessage=false option peek=true will work as supposed. + from("imaps://outlook.office365.com?peek=true&unseen=true&debugMode=true&username=<username>&password=<password>") + .process(new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + if (true) { + throw new IOException("This will cause messages to be marked SEEN even when peek=true."); + } + } + }) + .to("log:mail"); + } + +} +