You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by bi...@apache.org on 2020/04/16 15:14:57 UTC

[axis-axis2-java-transports] 12/46: committing some changes done to the trunk to branch

This is an automated email from the ASF dual-hosted git repository.

billblough pushed a commit to branch transport
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-transports.git

commit a87cb33ac0d1c2aa8b1e497d570a7d5a9746e128
Author: Amila Chinthaka Suriarachchi <am...@apache.org>
AuthorDate: Mon Nov 16 12:39:45 2009 +0000

    committing some changes done to the trunk to branch
---
 .../apache/axis2/transport/mail/MailConstants.java |  3 +-
 .../axis2/transport/mail/MailTransportSender.java  | 35 ++++++++++++++++------
 .../apache/axis2/transport/mail/WSMimeMessage.java | 15 ++++++++--
 3 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/1.0.0/modules/mail/src/main/java/org/apache/axis2/transport/mail/MailConstants.java b/1.0.0/modules/mail/src/main/java/org/apache/axis2/transport/mail/MailConstants.java
index 856d2b4..4b7ac55 100644
--- a/1.0.0/modules/mail/src/main/java/org/apache/axis2/transport/mail/MailConstants.java
+++ b/1.0.0/modules/mail/src/main/java/org/apache/axis2/transport/mail/MailConstants.java
@@ -93,6 +93,7 @@ public class MailConstants {
 
     // Custom headers
     /** @see org.apache.axis2.transport.mail.WSMimeMessage */
-    public static final String MAIL_HEADER_X_MESSAGE_ID= "X-Message-ID";
+    public static final String MAIL_HEADER_X_MESSAGE_ID = "X-Message-ID";
+    public static final String TRANSPORT_MAIL_CUSTOM_HEADERS  = "transport.mail.custom.headers";
     
 }
diff --git a/1.0.0/modules/mail/src/main/java/org/apache/axis2/transport/mail/MailTransportSender.java b/1.0.0/modules/mail/src/main/java/org/apache/axis2/transport/mail/MailTransportSender.java
index c1b2c36..249bf9c 100644
--- a/1.0.0/modules/mail/src/main/java/org/apache/axis2/transport/mail/MailTransportSender.java
+++ b/1.0.0/modules/mail/src/main/java/org/apache/axis2/transport/mail/MailTransportSender.java
@@ -25,10 +25,7 @@ import org.apache.axis2.transport.base.*;
 import org.apache.commons.logging.LogFactory;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.TransportOutDescription;
-import org.apache.axis2.description.Parameter;
-import org.apache.axis2.description.OutOnlyAxisOperation;
-import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.description.*;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.addressing.AddressingConstants;
 import org.apache.axis2.transport.OutTransportInfo;
@@ -194,7 +191,7 @@ public class MailTransportSender extends AbstractTransportSender
     private void waitForReply(MessageContext msgContext, String mailMessageID) throws AxisFault {
         // piggy back message constant is used to pass a piggy back
         // message context in asnych model
-        if (msgContext.getAxisOperation() instanceof OutOnlyAxisOperation &&
+        if (!(msgContext.getAxisOperation() instanceof OutInAxisOperation) &&
                 (msgContext.getProperty(org.apache.axis2.Constants.PIGGYBACK_MESSAGE) == null)) {
             return;
         }
@@ -252,7 +249,13 @@ public class MailTransportSender extends AbstractTransportSender
                     messageFormatter.getClass().getSimpleName());
         }
 
-        WSMimeMessage message = new WSMimeMessage(session);
+        WSMimeMessage message = null;
+        if (outInfo.getFromAddress() != null) {
+            message = new WSMimeMessage(session, outInfo.getFromAddress().getAddress());
+        } else {
+            message = new WSMimeMessage(session, "");
+        }
+        
         Map trpHeaders = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
         if (log.isDebugEnabled() && trpHeaders != null) {
             log.debug("Using transport headers: " + trpHeaders);
@@ -442,10 +445,24 @@ public class MailTransportSender extends AbstractTransportSender
             // always use quoted-printable transfer encoding. Note that JavaMail is a bit smarter
             // here because it can choose between 7bit and quoted-printable automatically, but it
             // needs to scan the entire content to determine this.
-            String contentType = dataHandler.getContentType().toLowerCase();
-            if (!contentType.startsWith("multipart/") && CommonUtils.isTextualPart(contentType)) {
-                mainPart.setHeader("Content-Transfer-Encoding", "quoted-printable");
+            if (msgContext.getOptions().getProperty("Content-Transfer-Encoding") != null) {
+                mainPart.setHeader("Content-Transfer-Encoding",
+                        (String) msgContext.getOptions().getProperty("Content-Transfer-Encoding"));
+            } else {
+                String contentType = dataHandler.getContentType().toLowerCase();
+                if (!contentType.startsWith("multipart/") && CommonUtils.isTextualPart(contentType)) {
+                    mainPart.setHeader("Content-Transfer-Encoding", "quoted-printable");
+                }
             }
+
+            //setting any custom headers defined by the user
+            if (msgContext.getOptions().getProperty(MailConstants.TRANSPORT_MAIL_CUSTOM_HEADERS) != null) {
+                Map customTransportHeaders = (Map) msgContext.getOptions().getProperty(MailConstants.TRANSPORT_MAIL_CUSTOM_HEADERS);
+                for (Object header : customTransportHeaders.keySet()) {
+                    mainPart.setHeader((String) header, (String) customTransportHeaders.get(header));
+                }
+            }
+
             
             log.debug("Sending message");
             Transport.send(message);
diff --git a/1.0.0/modules/mail/src/main/java/org/apache/axis2/transport/mail/WSMimeMessage.java b/1.0.0/modules/mail/src/main/java/org/apache/axis2/transport/mail/WSMimeMessage.java
index d2a4f4f..369b671 100644
--- a/1.0.0/modules/mail/src/main/java/org/apache/axis2/transport/mail/WSMimeMessage.java
+++ b/1.0.0/modules/mail/src/main/java/org/apache/axis2/transport/mail/WSMimeMessage.java
@@ -38,15 +38,24 @@ import javax.mail.Session;
  */
 public class WSMimeMessage extends MimeMessage {
     private long bytesSent = -1;
+    private String fromAddress;
 
-    WSMimeMessage(Session session) {
+
+    WSMimeMessage(Session session, String fromAddress) {
         super(session);
+        this.fromAddress = fromAddress;
     }
 
     @Override
     protected void updateMessageID() throws MessagingException {
-	    if (getHeader(MailConstants.MAIL_HEADER_MESSAGE_ID) == null) {
-            setHeader(MailConstants.MAIL_HEADER_MESSAGE_ID, UUIDGenerator.getUUID());    
+        // although MailConstants.MAIL_HEADER_X_MESSAGE_ID solves the gmail problem with axis2-axis2
+        // invocations it is not a generic solution.
+        // we can over come gmail problem by setting the message id as follows with a valid gmail address
+        // <xx...@gmail.com> this can be achived by appending from address at the end of uuid
+
+        if (getHeader(MailConstants.MAIL_HEADER_MESSAGE_ID) == null) {
+            String uuid = "<" + UUIDGenerator.getUUID().replaceAll(":",".") + fromAddress +">";
+            setHeader(MailConstants.MAIL_HEADER_MESSAGE_ID, uuid);
         }
     }