You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dk...@apache.org on 2011/07/07 21:02:09 UTC
svn commit: r1143979 - in /camel/branches/camel-2.7.x: ./
components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
Author: dkulp
Date: Thu Jul 7 19:02:09 2011
New Revision: 1143979
URL: http://svn.apache.org/viewvc?rev=1143979&view=rev
Log:
Merged revisions 1140096,1140102,1141783 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r1140096 | davsclaus | 2011-06-27 06:51:48 -0400 (Mon, 27 Jun 2011) | 1 line
CAMEL-3948: pop3 protocol now supports marking mails as SEEN/DELETED. Thanks to Donald for the patch.
........
r1140102 | davsclaus | 2011-06-27 06:59:00 -0400 (Mon, 27 Jun 2011) | 1 line
CAMEL-3948: Do not set rsetbeforequit property on mail configuration as its essentially enables reset on quit, which means it will undo all changes.
........
r1141783 | ningjiang | 2011-06-30 23:02:30 -0400 (Thu, 30 Jun 2011) | 1 line
CAMEL-3948 applied the last piece of patch
........
Modified:
camel/branches/camel-2.7.x/ (props changed)
camel/branches/camel-2.7.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
camel/branches/camel-2.7.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
Propchange: camel/branches/camel-2.7.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jul 7 19:02:09 2011
@@ -1 +1 @@
-/camel/trunk:1083696,1084150,1085905,1086231,1087276,1087612,1087856,1088583,1088916-1088917,1089275,1090166,1090960-1090969,1091518,1091771,1091799,1092068,1092577,1092667,1093978,1094156,1095405,1095469,1095471,1095475-1095476,1097909,1097912,1097978,1098630,1099417,1100975,1102162,1102181,1104076,1124497,1127744,1127988,1131411,1134252,1134501,1135223,1135364,1136290,1138285,1139163,1143925
+/camel/trunk:1083696,1084150,1085905,1086231,1087276,1087612,1087856,1088583,1088916-1088917,1089275,1090166,1090960-1090969,1091518,1091771,1091799,1092068,1092577,1092667,1093978,1094156,1095405,1095469,1095471,1095475-1095476,1097909,1097912,1097978,1098630,1099417,1100975,1102162,1102181,1104076,1124497,1127744,1127988,1131411,1134252,1134501,1135223,1135364,1136290,1138285,1139163,1140096-1140102,1141783,1143925
Propchange: camel/branches/camel-2.7.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-2.7.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java?rev=1143979&r1=1143978&r2=1143979&view=diff
==============================================================================
--- camel/branches/camel-2.7.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java (original)
+++ camel/branches/camel-2.7.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java Thu Jul 7 19:02:09 2011
@@ -166,7 +166,6 @@ public class MailConfiguration implement
} else {
properties.put("mail." + protocol + ".auth", "false");
}
- properties.put("mail." + protocol + ".rsetbeforequit", "true");
properties.put("mail.transport.protocol", protocol);
properties.put("mail.store.protocol", protocol);
properties.put("mail.host", host);
Modified: camel/branches/camel-2.7.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java?rev=1143979&r1=1143978&r2=1143979&view=diff
==============================================================================
--- camel/branches/camel-2.7.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java (original)
+++ camel/branches/camel-2.7.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java Thu Jul 7 19:02:09 2011
@@ -16,12 +16,14 @@
*/
package org.apache.camel.component.mail;
+import java.util.Enumeration;
import java.util.LinkedList;
import java.util.Queue;
-
+import java.util.UUID;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.FolderNotFoundException;
+import javax.mail.Header;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Store;
@@ -43,10 +45,9 @@ import org.springframework.mail.javamail
/**
* A {@link org.apache.camel.Consumer Consumer} which consumes messages from JavaMail using a
* {@link javax.mail.Transport Transport} and dispatches them to the {@link Processor}
- *
- * @version
*/
public class MailConsumer extends ScheduledPollConsumer implements BatchConsumer, ShutdownAware {
+ public static final String POP3_UID = "CamelPop3Uid";
public static final long DEFAULT_CONSUMER_DELAY = 60 * 1000L;
private static final transient Logger LOG = LoggerFactory.getLogger(MailConsumer.class);
@@ -241,6 +242,16 @@ public class MailConsumer extends Schedu
Message message = messages[i];
if (!message.getFlags().contains(Flags.Flag.DELETED)) {
Exchange exchange = getEndpoint().createExchange(message);
+
+ // If the protocol is POP3 we need to remember the uid on the exchange
+ // so we can find the mail message again later to be able to delete it
+ if (getEndpoint().getConfiguration().getProtocol().startsWith("pop3")) {
+ String uid = generatePop3Uid(message);
+ if (uid != null) {
+ exchange.setProperty(POP3_UID, uid);
+ LOG.trace("POP3 mail message using uid {}", uid);
+ }
+ }
answer.add(exchange);
} else {
if (LOG.isDebugEnabled()) {
@@ -271,11 +282,40 @@ public class MailConsumer extends Schedu
*/
protected void processCommit(Message mail, Exchange exchange) {
try {
+ // ensure folder is open
+ if (!folder.isOpen()) {
+ folder.open(Folder.READ_WRITE);
+ }
+
+ // If the protocol is POP3, the message needs to be synced with the folder via the UID.
+ // Otherwise setting the DELETE/SEEN flag won't delete the message.
+ String uid = (String) exchange.removeProperty(POP3_UID);
+ if (uid != null) {
+ int count = folder.getMessageCount();
+ Message found = null;
+ LOG.trace("Looking for POP3Message with UID {} from folder with {} mails", uid, count);
+ for (int i = 1; i <= count; ++i) {
+ Message msg = folder.getMessage(i);
+ if (uid.equals(generatePop3Uid(msg))) {
+ LOG.debug("Found POP3Message with UID {} from folder with {} mails", uid, count);
+ found = msg;
+ break;
+ }
+ }
+
+ if (found == null) {
+ boolean delete = getEndpoint().getConfiguration().isDelete();
+ LOG.warn("POP3message not found in folder. Message cannot be marked as " + (delete ? "DELETED" : "SEEN"));
+ } else {
+ mail = found;
+ }
+ }
+
if (getEndpoint().getConfiguration().isDelete()) {
- LOG.debug("Exchange processed, so flagging message as DELETED");
+ LOG.trace("Exchange processed, so flagging message as DELETED");
mail.setFlag(Flags.Flag.DELETED, true);
} else {
- LOG.debug("Exchange processed, so flagging message as SEEN");
+ LOG.trace("Exchange processed, so flagging message as SEEN");
mail.setFlag(Flags.Flag.SEEN, true);
}
} catch (MessagingException e) {
@@ -299,6 +339,37 @@ public class MailConsumer extends Schedu
}
}
+ /**
+ * Generates an UID of the POP3Message
+ *
+ * @param message the POP3Message
+ * @return the generated uid
+ */
+ protected String generatePop3Uid(Message message) {
+ String uid = null;
+
+ // create an UID based on message headers on the POP3Message, that ought to be unique
+ StringBuilder buffer = new StringBuilder();
+ try {
+ Enumeration it = message.getAllHeaders();
+ while (it.hasMoreElements()) {
+ Header header = (Header) it.nextElement();
+ buffer.append(header.getName())
+ .append("=")
+ .append(header.getValue())
+ .append("\n");
+ }
+ if (buffer.length() > 0) {
+ LOG.debug("Generating UID from the following:\n" + buffer);
+ uid = UUID.nameUUIDFromBytes(buffer.toString().getBytes()).toString();
+ }
+ } catch (MessagingException e) {
+ LOG.warn("Cannot reader headers from mail message. This exception will be ignored.", e);
+ }
+
+ return uid;
+ }
+
private void ensureIsConnected() throws MessagingException {
MailConfiguration config = getEndpoint().getConfiguration();
@@ -340,4 +411,5 @@ public class MailConsumer extends Schedu
public MailEndpoint getEndpoint() {
return (MailEndpoint) super.getEndpoint();
}
+
}