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 2009/06/18 07:47:50 UTC
svn commit: r785915 - in /camel/trunk/components/camel-mail/src:
main/java/org/apache/camel/component/mail/
test/java/org/apache/camel/component/mail/
Author: davsclaus
Date: Thu Jun 18 05:47:49 2009
New Revision: 785915
URL: http://svn.apache.org/viewvc?rev=785915&view=rev
Log:
CAMEL-1727: alternative body header should not be included in mime mail as header also.
Modified:
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailContentTypeResolverTest.java
camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeTest.java
Modified: camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java?rev=785915&r1=785914&r2=785915&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java (original)
+++ camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java Thu Jun 18 05:47:49 2009
@@ -71,8 +71,8 @@
throws MessagingException, IOException {
// camel message headers takes presedence over endpoint configuration
- if (hasRecipientHeaders(exchange.getIn())) {
- setRecipientFromCamelMessage(mimeMessage, exchange, exchange.getIn());
+ if (hasRecipientHeaders(exchange)) {
+ setRecipientFromCamelMessage(mimeMessage, exchange);
} else {
// fallback to endpoint configuration
setRecipientFromEndpointConfiguration(mimeMessage, endpoint);
@@ -84,7 +84,7 @@
}
// append the rest of the headers (no recipients) that could be subject, reply-to etc.
- appendHeadersFromCamelMessage(mimeMessage, exchange, exchange.getIn());
+ appendHeadersFromCamelMessage(mimeMessage, endpoint.getConfiguration(), exchange);
if (empty(mimeMessage.getFrom())) {
// lets default the address to the endpoint destination
@@ -93,7 +93,7 @@
}
// if there is an alternativebody provided, set up a mime multipart alternative message
- if (hasAlternativeBody(endpoint.getConfiguration(), exchange.getIn())) {
+ if (hasAlternativeBody(endpoint.getConfiguration(), exchange)) {
createMultipartAlternativeMessage(mimeMessage, endpoint.getConfiguration(), exchange);
} else {
if (exchange.getIn().hasAttachments()) {
@@ -125,7 +125,9 @@
return contentType;
}
- protected String populateContentOnMimeMessage(MimeMessage part, MailConfiguration configuration, Exchange exchange) throws MessagingException, IOException {
+ protected String populateContentOnMimeMessage(MimeMessage part, MailConfiguration configuration, Exchange exchange)
+ throws MessagingException, IOException {
+
String contentType = determineContentType(configuration, exchange);
if (LOG.isTraceEnabled()) {
@@ -142,7 +144,9 @@
return contentType;
}
- protected String populateContentOnBodyPart(BodyPart part, MailConfiguration configuration, Exchange exchange) throws MessagingException, IOException {
+ protected String populateContentOnBodyPart(BodyPart part, MailConfiguration configuration, Exchange exchange)
+ throws MessagingException, IOException {
+
String contentType = determineContentType(configuration, exchange);
if (LOG.isTraceEnabled()) {
@@ -174,11 +178,10 @@
/**
* Appends the Mail headers from the Camel {@link MailMessage}
*/
- protected void appendHeadersFromCamelMessage(MimeMessage mimeMessage, Exchange exchange,
- org.apache.camel.Message camelMessage)
+ protected void appendHeadersFromCamelMessage(MimeMessage mimeMessage, MailConfiguration configuration, Exchange exchange)
throws MessagingException {
- for (Map.Entry<String, Object> entry : camelMessage.getHeaders().entrySet()) {
+ for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
String headerName = entry.getKey();
Object headerValue = entry.getValue();
if (headerValue != null) {
@@ -190,6 +193,12 @@
continue;
}
+ // alternative body should also be skipped
+ if (headerName.equalsIgnoreCase(configuration.getAlternativeBodyHeader())) {
+ // skip alternative body
+ continue;
+ }
+
// Mail messages can repeat the same header...
if (ObjectConverter.isCollection(headerValue)) {
Iterator iter = ObjectHelper.createIterator(headerValue);
@@ -205,11 +214,8 @@
}
}
- private void setRecipientFromCamelMessage(MimeMessage mimeMessage, Exchange exchange,
- org.apache.camel.Message camelMessage)
- throws MessagingException {
-
- for (Map.Entry<String, Object> entry : camelMessage.getHeaders().entrySet()) {
+ private void setRecipientFromCamelMessage(MimeMessage mimeMessage, Exchange exchange) throws MessagingException {
+ for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
String headerName = entry.getKey();
Object headerValue = entry.getValue();
if (headerValue != null && isRecipientHeader(headerName)) {
@@ -248,8 +254,8 @@
/**
* Appends the Mail attachments from the Camel {@link MailMessage}
*/
- protected void appendAttachmentsFromCamel(MimeMessage mimeMessage, MailConfiguration configuration,
- Exchange exchange) throws MessagingException, IOException {
+ protected void appendAttachmentsFromCamel(MimeMessage mimeMessage, MailConfiguration configuration, Exchange exchange)
+ throws MessagingException, IOException {
// Put parts in message
mimeMessage.setContent(createMixedMultipartAttachments(configuration, exchange));
@@ -322,14 +328,17 @@
LOG.trace("Adding attachments +++ done +++");
}
- protected void createMultipartAlternativeMessage(MimeMessage mimeMessage, MailConfiguration configuration,
- Exchange exchange) throws MessagingException, IOException {
+ protected void createMultipartAlternativeMessage(MimeMessage mimeMessage, MailConfiguration configuration, Exchange exchange)
+ throws MessagingException, IOException {
MimeMultipart multipartAlternative = new MimeMultipart("alternative");
mimeMessage.setContent(multipartAlternative);
BodyPart plainText = new MimeBodyPart();
- plainText.setText(getAlternativeBody(configuration, exchange.getIn()));
+ plainText.setText(getAlternativeBody(configuration, exchange));
+ // remove the header with the alternative mail now that we got it
+ // otherwise it might end up twice in the mail reader
+ exchange.getIn().removeHeader(configuration.getAlternativeBodyHeader());
multipartAlternative.addBodyPart(plainText);
// if there are no attachments, add the body to the same mulitpart message
@@ -355,7 +364,6 @@
addAttachmentsToMultipart(multipartRelated, Part.INLINE, exchange);
}
}
-
}
protected void addBodyToMultipart(MailConfiguration configuration, MimeMultipart activeMultipart, Exchange exchange)
@@ -408,8 +416,8 @@
/**
* Does the given camel message contain any To, CC or BCC header names?
*/
- private static boolean hasRecipientHeaders(org.apache.camel.Message camelMessage) {
- for (String key : camelMessage.getHeaders().keySet()) {
+ private static boolean hasRecipientHeaders(Exchange exchange) {
+ for (String key : exchange.getIn().getHeaders().keySet()) {
if (isRecipientHeader(key)) {
return true;
}
@@ -417,13 +425,13 @@
return false;
}
- protected static boolean hasAlternativeBody(MailConfiguration configuration, org.apache.camel.Message camelMessage) {
- return getAlternativeBody(configuration, camelMessage) != null;
+ protected static boolean hasAlternativeBody(MailConfiguration configuration, Exchange exchange) {
+ return getAlternativeBody(configuration, exchange) != null;
}
- protected static String getAlternativeBody(MailConfiguration configuration, org.apache.camel.Message camelMessage) {
+ protected static String getAlternativeBody(MailConfiguration configuration, Exchange exchange) {
String alternativeBodyHeader = configuration.getAlternativeBodyHeader();
- return camelMessage.getHeader(alternativeBodyHeader, java.lang.String.class);
+ return exchange.getIn().getHeader(alternativeBodyHeader, java.lang.String.class);
}
/**
Modified: camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailContentTypeResolverTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailContentTypeResolverTest.java?rev=785915&r1=785914&r2=785915&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailContentTypeResolverTest.java (original)
+++ camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailContentTypeResolverTest.java Thu Jun 18 05:47:49 2009
@@ -53,7 +53,7 @@
producer.process(exchange);
// need some time for the mail to arrive on the inbox (consumed and sent to the mock)
- Thread.sleep(1000);
+ Thread.sleep(4000);
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
Modified: camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeTest.java?rev=785915&r1=785914&r2=785915&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeTest.java (original)
+++ camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeTest.java Thu Jun 18 05:47:49 2009
@@ -58,7 +58,6 @@
producer.process(exchange);
producer.stop();
-
}
private void verifyTheRecivedEmail(String expectString) throws Exception {
@@ -67,6 +66,8 @@
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
+ // this header should be removed
+ mock.message(0).header(MailConstants.MAIL_ALTERNATIVE_BODY).isNull();
Exchange out = mock.assertExchangeReceived(0);
mock.assertIsSatisfied();
@@ -86,8 +87,6 @@
assertNotNull("Should not have null attachments", attachments);
assertEquals(1, attachments.size());
assertEquals("multipart body should have 2 parts", 2, out.getIn().getBody(MimeMultipart.class).getCount());
-
-
}
@Test