You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by un...@apache.org on 2005/06/17 13:46:09 UTC

svn commit: r191131 - /cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java

Author: unico
Date: Fri Jun 17 04:46:08 2005
New Revision: 191131

URL: http://svn.apache.org/viewcvs?rev=191131&view=rev
Log:
Make smtp port configurable

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java?rev=191131&r1=191130&r2=191131&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java Fri Jun 17 04:46:08 2005
@@ -188,6 +188,7 @@
     public static final String NAMESPACE                  = "http://apache.org/cocoon/transformation/sendmail";
     public static final String ELEMENT_SENDMAIL           = "sendmail";
     public static final String ELEMENT_SMTPHOST           = "smtphost";
+    public static final String ELEMENT_SMTPPORT           = "smtpport";
     public static final String ELEMENT_MAILFROM           = "from";
     public static final String ELEMENT_MAILTO             = "to";
     public static final String ELEMENT_REPLYTO            = "reply-to";
@@ -215,11 +216,13 @@
     protected static final int MODE_ATTACHMENT         = 6;
     protected static final int MODE_ATTACHMENT_CONTENT = 7;
     protected static final int MODE_REPLY_TO           = 8;
+    protected static final int MODE_SMTPPORT           = 8;
 
     /*
      * constants, related to parameter from request
      */
     public final static String PARAM_SMTPHOST    = "smtphost";
+    public final static String PARAM_SMTPPORT    = "smtpport";
     public final static String PARAM_FROM        = "from";
     public final static String PARAM_TO          = "to";
     public final static String PARAM_REPLY_TO    = "reply-to";
@@ -241,6 +244,7 @@
     protected String               bodyURI;
     protected String               bodyMimeType;
     protected String               mailHost;
+    protected int                  mailPort;
     protected String               fromAddress;
     protected AttachmentDescriptor attachmentDescriptor;
     protected int                  port;
@@ -249,6 +253,7 @@
     protected Message              smtpMessage;
 
     protected String defaultSmtpHost;
+    protected int defaultSmtpPort;
     protected String defaultFromAddress;
 
     protected boolean useExternalRequests = true;
@@ -268,6 +273,7 @@
     throws ConfigurationException {
         super.configure(configuration);
         this.defaultSmtpHost = configuration.getChild("smtphost").getValue("");
+        this.defaultSmtpPort = configuration.getChild("smtpport").getValueAsInteger(25);
         this.defaultFromAddress = configuration.getChild("from").getValue("");
         this.useExternalRequests = configuration.getChild("use-external-requests").getValueAsBoolean(this.useExternalRequests);
     }
@@ -281,13 +287,14 @@
         super.setup(resolver, objectModel, src, par);
 
         this.mailHost    = par.getParameter(PARAM_SMTPHOST, this.defaultSmtpHost);
+        this.mailPort    = par.getParameterAsInteger(PARAM_SMTPPORT, this.defaultSmtpPort);
         this.fromAddress = par.getParameter(PARAM_FROM, this.defaultFromAddress);
         this.port        = this.request.getServerPort();
         this.contextPath = this.request.getContextPath();
         this.sendPartial = par.getParameterAsBoolean(PARAM_SENDPARTIAL, true);
 
         if (getLogger().isDebugEnabled()) {
-            getLogger().debug("Using host " + mailHost + ", from address " + fromAddress);
+            getLogger().debug("Using host " + mailHost + " on port " + mailPort +  ", from address " + fromAddress);
         }
 
         this.attachments = new ArrayList();
@@ -314,6 +321,9 @@
         } else if (name.equals(ELEMENT_SMTPHOST)) {
             startTextRecording();
             this.mode = MODE_SMTPHOST;
+        } else if (name.equals(ELEMENT_SMTPPORT)) {
+            this.startTextRecording();
+            this.mode = MODE_SMTPPORT;
         } else if (name.equals(ELEMENT_MAILFROM)) {
             startTextRecording();
             this.mode = MODE_FROM;
@@ -370,6 +380,9 @@
         } else if (name.equals(ELEMENT_SMTPHOST) ) {
             this.mailHost = endTextRecording();
             this.mode     = MODE_NONE;
+        } else if (name.equals(ELEMENT_SMTPPORT) ) {
+            this.mailPort = Integer.parseInt(this.endTextRecording());
+            this.mode     = MODE_NONE;
         } else if (name.equals(ELEMENT_MAILFROM)) {
             this.fromAddress = endTextRecording();
             this.mode        = MODE_NONE;
@@ -429,6 +442,7 @@
         try {
             Properties props = new Properties();
             props.put("mail.smtp.host", this.mailHost);
+            props.put("mail.smtp.port", String.valueOf(this.mailPort));
 
             if (this.subject == null) {
 		        this.ignoreHooksCount++;
@@ -687,7 +701,8 @@
 	    this.body = null;
 	    this.bodyURI = null;
 	    this.mailHost = null;
-	    this.fromAddress = null;
+        this.mailPort = 0;
+        this.fromAddress = null;
 	    this.attachmentDescriptor = null;
 	    this.port = 0;
 	    this.contextPath = null;