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 2008/05/03 15:39:46 UTC
svn commit: r653079 - in /activemq/camel/trunk/components/camel-mail/src:
main/java/org/apache/camel/component/mail/
test/java/org/apache/camel/component/mail/
Author: davsclaus
Date: Sat May 3 06:39:45 2008
New Revision: 653079
URL: http://svn.apache.org/viewvc?rev=653079&view=rev
Log:
CAMEL-492
- camel mail now support To, CC and BCC recipients
Added:
activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRecipientsTest.java (with props)
Modified:
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailUtils.java
Modified: activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java?rev=653079&r1=653078&r2=653079&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java (original)
+++ activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java Sat May 3 06:39:45 2008
@@ -46,14 +46,21 @@
try {
appendHeadersFromCamel(mimeMessage, exchange, exchange.getIn());
- String destination = endpoint.getConfiguration().getDestination();
- if (destination != null) {
- mimeMessage.setRecipients(Message.RecipientType.TO, destination);
+ // set the recipients (receives) of the mail
+ Map<Message.RecipientType, String> recipients = endpoint.getConfiguration().getRecipients();
+ if (recipients.containsKey(Message.RecipientType.TO)) {
+ mimeMessage.setRecipients(Message.RecipientType.TO, recipients.get(Message.RecipientType.TO));
}
- // must have a destination otherwise we do not know where to send the mail
+ if (recipients.containsKey(Message.RecipientType.CC)) {
+ mimeMessage.setRecipients(Message.RecipientType.CC, recipients.get(Message.RecipientType.CC));
+ }
+ if (recipients.containsKey(Message.RecipientType.BCC)) {
+ mimeMessage.setRecipients(Message.RecipientType.BCC, recipients.get(Message.RecipientType.BCC));
+ }
+
+ // must have at least one recipients otherwise we do not know where to send the mail
if (mimeMessage.getAllRecipients() == null) {
- throw new IllegalArgumentException("The MineMessage does not have any recipients set. "
- + "Add a destination (Recipient.TO) to the MailConfiguration.");
+ throw new IllegalArgumentException("The mail message does not have any recipients set.");
}
if (empty(mimeMessage.getFrom())) {
Modified: activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java?rev=653079&r1=653078&r2=653079&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java (original)
+++ activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java Sat May 3 06:39:45 2008
@@ -59,7 +59,7 @@
@Override
protected Endpoint<MailExchange> createEndpoint(String uri, String remaining, Map parameters) throws Exception {
- MailConfiguration config = getConfiguration().copy();
+ MailConfiguration config = new MailConfiguration();
config.configure(new URI(uri));
// lets make sure we copy the configuration as each endpoint can customize its own version
Modified: activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java?rev=653079&r1=653078&r2=653079&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java (original)
+++ activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java Sat May 3 06:39:45 2008
@@ -18,10 +18,12 @@
import java.net.URI;
import java.util.Properties;
+import java.util.Map;
+import java.util.HashMap;
import javax.mail.Session;
+import javax.mail.Message;
-import org.apache.camel.RuntimeCamelException;
import org.springframework.mail.javamail.JavaMailSenderImpl;
/**
@@ -29,7 +31,7 @@
*
* @version $Revision$
*/
-public class MailConfiguration implements Cloneable {
+public class MailConfiguration {
public static final String DEFAULT_FOLDER_NAME = "INBOX";
public static final String DEFAULT_FROM = "camel@localhost";
@@ -43,26 +45,15 @@
private Session session;
private String defaultEncoding;
private String from = DEFAULT_FROM;
- private String destination;
private String folderName = DEFAULT_FOLDER_NAME;
private boolean deleteProcessedMessages = true;
private boolean ignoreUriScheme;
private boolean processOnlyUnseenMessages;
+ private Map<Message.RecipientType, String> recipients = new HashMap<Message.RecipientType, String>();
public MailConfiguration() {
}
- /**
- * Returns a copy of this configuration
- */
- public MailConfiguration copy() {
- try {
- return (MailConfiguration)clone();
- } catch (CloneNotSupportedException e) {
- throw new RuntimeCamelException(e);
- }
- }
-
public void configure(URI uri) {
String value = uri.getHost();
if (value != null) {
@@ -82,7 +73,8 @@
// set default destination to userInfo@host for backwards compatibility
// can be overridden by URI parameters
- setDestination(userInfo + "@" + host);
+ String address = userInfo + "@" + host;
+ recipients.put(Message.RecipientType.TO, address);
}
int port = uri.getPort();
@@ -188,19 +180,32 @@
public void setUsername(String username) {
this.username = username;
- if (destination == null) {
+ if (! recipients.containsKey(Message.RecipientType.TO)) {
// set default destination to username@host for backwards compatibility
// can be overridden by URI parameters
- setDestination(username + "@" + host);
+ String address = username + "@" + host;
+ recipients.put(Message.RecipientType.TO, address);
}
}
+ /**
+ * Gets the destination (recipient <tt>To</tt> email address).
+ *
+ * @deprecated use {@link #getRecipients()}
+ */
public String getDestination() {
- return destination;
+ // for backwards compatibility
+ return recipients.get(Message.RecipientType.TO);
}
+ /**
+ * Sets the destination (recipient <tt>To</tt> email address).
+ *
+ * @deprecated use {@link #setTo(String)}
+ */
public void setDestination(String destination) {
- this.destination = destination;
+ // for backwards compatibility
+ recipients.put(Message.RecipientType.TO, destination);
}
public String getFrom() {
@@ -242,4 +247,30 @@
public void setProcessOnlyUnseenMessages(boolean processOnlyUnseenMessages) {
this.processOnlyUnseenMessages = processOnlyUnseenMessages;
}
+
+ /**
+ * Sets the <tt>To</tt> email address. Separate multiple email addresses with comma.
+ */
+ public void setTo(String address) {
+ recipients.put(Message.RecipientType.TO, address);
+ }
+
+ /**
+ * Sets the <tt>CC</tt> email address. Separate multiple email addresses with comma.
+ */
+ public void setCC(String address) {
+ recipients.put(Message.RecipientType.CC, address);
+ }
+
+ /**
+ * Sets the <tt>BCC</tt> email address. Separate multiple email addresses with comma.
+ */
+ public void setBCC(String address) {
+ recipients.put(Message.RecipientType.BCC, address);
+ }
+
+ public Map<Message.RecipientType, String> getRecipients() {
+ return recipients;
+ }
+
}
Modified: activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailUtils.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailUtils.java?rev=653079&r1=653078&r2=653079&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailUtils.java (original)
+++ activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailUtils.java Sat May 3 06:39:45 2008
@@ -111,7 +111,6 @@
}
}
- // TODO: Maybe we need to get the subject from the header properties
String subject = message.getSubject();
if (subject != null) {
sb.append(", subject=[").append(subject).append("]");
Added: activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRecipientsTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRecipientsTest.java?rev=653079&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRecipientsTest.java (added)
+++ activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRecipientsTest.java Sat May 3 06:39:45 2008
@@ -0,0 +1,81 @@
+/**
+ * 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.Message;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.jvnet.mock_javamail.Mailbox;
+
+/**
+ * Unit test for recipients (To, CC, BCC)
+ */
+public class MailRecipientsTest extends ContextTestSupport {
+
+ public void testMultiRecipients() throws Exception {
+ sendBody("direct:a", "Camel does really rock");
+
+ Mailbox inbox = Mailbox.get("camel@riders.org");
+ Message msg = inbox.get(0);
+ assertEquals("james@apache.org", msg.getFrom()[0].toString());
+ assertEquals("camel@riders.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
+ assertEquals("easy@riders.org", msg.getRecipients(Message.RecipientType.TO)[1].toString());
+ assertEquals("me@you.org", msg.getRecipients(Message.RecipientType.CC)[0].toString());
+ assertEquals("someone@somewhere.org", msg.getRecipients(Message.RecipientType.BCC)[0].toString());
+
+ inbox = Mailbox.get("easy@riders.org");
+ msg = inbox.get(0);
+ assertEquals("james@apache.org", msg.getFrom()[0].toString());
+ assertEquals("camel@riders.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
+ assertEquals("easy@riders.org", msg.getRecipients(Message.RecipientType.TO)[1].toString());
+ assertEquals("me@you.org", msg.getRecipients(Message.RecipientType.CC)[0].toString());
+ assertEquals("someone@somewhere.org", msg.getRecipients(Message.RecipientType.BCC)[0].toString());
+
+ inbox = Mailbox.get("me@you.org");
+ msg = inbox.get(0);
+ assertEquals("james@apache.org", msg.getFrom()[0].toString());
+ assertEquals("camel@riders.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
+ assertEquals("easy@riders.org", msg.getRecipients(Message.RecipientType.TO)[1].toString());
+ assertEquals("me@you.org", msg.getRecipients(Message.RecipientType.CC)[0].toString());
+ assertEquals("someone@somewhere.org", msg.getRecipients(Message.RecipientType.BCC)[0].toString());
+
+ inbox = Mailbox.get("someone@somewhere.org");
+ msg = inbox.get(0);
+ assertEquals("james@apache.org", msg.getFrom()[0].toString());
+ assertEquals("camel@riders.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
+ assertEquals("easy@riders.org", msg.getRecipients(Message.RecipientType.TO)[1].toString());
+ assertEquals("me@you.org", msg.getRecipients(Message.RecipientType.CC)[0].toString());
+ assertEquals("someone@somewhere.org", msg.getRecipients(Message.RecipientType.BCC)[0].toString());
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ // START SNIPPET: e1
+ // all the recipients of this mail are:
+ // To: camel@riders.org , easy@riders.org
+ // CC: me@you.org
+ // BCC: someone@somewhere.org
+ String recipients = "&To=camel@riders.org,easy@riders.org&CC=me@you.org&BCC=someone@somewhere.org";
+
+ from("direct:a").to("smtp:james@mymailserver.com?password=secret&From=james@apache.org" + recipients);
+ // END SNIPPET: e1
+ }
+ };
+ }
+}
Propchange: activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRecipientsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRecipientsTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date