geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r569336 - in /geronimo/javamail/trunk: geronimo-javamail_1.3.1/geronimo-javamail_1.3.1_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/ geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronim...
Date Fri, 24 Aug 2007 10:34:45 GMT
Author: rickmcguire
Date: Fri Aug 24 03:34:43 2007
New Revision: 569336

URL: http://svn.apache.org/viewvc?rev=569336&view=rev
Log:
GERONIMO-3427 STMP login fails if server sends multiple lines of response back from initial
connection.

Improved version that always handles continuations. 


Modified:
    geronimo/javamail/trunk/geronimo-javamail_1.3.1/geronimo-javamail_1.3.1_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPReply.java
    geronimo/javamail/trunk/geronimo-javamail_1.3.1/geronimo-javamail_1.3.1_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java
    geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPReply.java
    geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java

Modified: geronimo/javamail/trunk/geronimo-javamail_1.3.1/geronimo-javamail_1.3.1_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPReply.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.3.1/geronimo-javamail_1.3.1_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPReply.java?rev=569336&r1=569335&r2=569336&view=diff
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.3.1/geronimo-javamail_1.3.1_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPReply.java
(original)
+++ geronimo/javamail/trunk/geronimo-javamail_1.3.1/geronimo-javamail_1.3.1_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPReply.java
Fri Aug 24 03:34:43 2007
@@ -19,6 +19,9 @@
 
 package org.apache.geronimo.javamail.transport.smtp;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * Util class to represent a reply from a SMTP server
  * 
@@ -34,6 +37,9 @@
     // the returned message text
     private final String message;
 
+    // additional returned lines from a continued response 
+    private List lines; 
+
     // indicates that this is a continuation response
     private boolean continued;
 
@@ -72,6 +78,40 @@
             throw new MalformedSMTPReplyException("error in parsing code", e);
         }
     }
+
+    /**
+     * Add a line to a continued response.  This will 
+     * update the continued status if the end of the 
+     * response is reached. 
+     * 
+     * @param line   The line to add.
+     */
+    public void addLine(String line) {
+        if (lines == null) {
+            lines = new ArrayList(); 
+            lines.add(message); 
+        }
+        // mark if we're still continued 
+        continued = line.charAt(3) == '-';
+        // add the line to the list 
+        lines.add(line.substring(4)); 
+    }
+    
+    /**
+     * Get the list of all of the lines associated with 
+     * this reply. 
+     * 
+     * @return A List containing all lines associated with this
+     *         reply.
+     */
+    public List getLines() {
+        if (lines == null) {
+            lines = new ArrayList(); 
+            lines.add(message); 
+        }
+        return lines;
+    }
+    
 
     /**
      * Return the code value associated with the reply.

Modified: geronimo/javamail/trunk/geronimo-javamail_1.3.1/geronimo-javamail_1.3.1_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.3.1/geronimo-javamail_1.3.1_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java?rev=569336&r1=569335&r2=569336&view=diff
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.3.1/geronimo-javamail_1.3.1_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java
(original)
+++ geronimo/javamail/trunk/geronimo-javamail_1.3.1/geronimo-javamail_1.3.1_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java
Fri Aug 24 03:34:43 2007
@@ -32,6 +32,7 @@
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.StringTokenizer;
 
 import javax.mail.Address;
@@ -1383,17 +1384,9 @@
      */
     protected boolean getWelcome() throws MessagingException {
         SMTPReply line = getReply();
-        // process any error now
-        if (line.isError()) {
-            return false; 
-        }
-        // Some servers send a multi-line welcome message.  Keep 
-        // reading lines until we hit the end of the response. 
-        while (line.isContinued()) {
-            line = getReply(); 
-        }
-        // this worked. 
-        return true; 
+        // just return the error status...we don't care about any of the 
+        // response information
+        return !line.isError();
     }
 
     /**
@@ -1733,6 +1726,11 @@
     protected SMTPReply getReply() throws MessagingException {
         try {
             lastServerResponse = new SMTPReply(receiveLine());
+            // if the first line we receive is a continuation, continue 
+            // reading lines until we reach the non-continued one. 
+            while (lastServerResponse.isContinued()) {
+                lastServerResponse.addLine(receiveLine()); 
+            }
         } catch (MalformedSMTPReplyException e) {
             throw new MessagingException(e.toString());
         } catch (MessagingException e) {
@@ -1881,29 +1879,24 @@
     protected boolean sendEhlo() throws MessagingException {
         sendLine("EHLO " + getLocalHost());
 
-        SMTPReply line = getReply();
+        SMTPReply reply = getReply();
 
         // we get a 250 code back. The first line is just a greeting, and
         // extensions are identifed on
         // continuations. If this fails, then we'll try once more with HELO to
         // establish bona fides.
-        if (line.getCode() != COMMAND_ACCEPTED) {
+        if (reply.getCode() != COMMAND_ACCEPTED) {
             return false;
         }
 
         // get a fresh extension mapping table.
         serverExtensionArgs = new HashMap();
 
+        List lines = reply.getLines(); 
         // process all of the continuation lines
-        while (line.isContinued()) {
-            // get the next line
-            line = getReply();
-            if (line.getCode() != COMMAND_ACCEPTED) {
-                // all EHLO failures go back to the HELO failback step.
-                return false;
-            }
+        for (int i = 1; i < lines.size(); i++) {
             // go process the extention
-            processExtension(line.getMessage());
+            processExtension((String)lines.get(i));
         }
         return true;
     }

Modified: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPReply.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPReply.java?rev=569336&r1=569335&r2=569336&view=diff
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPReply.java
(original)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPReply.java
Fri Aug 24 03:34:43 2007
@@ -18,6 +18,9 @@
  */
 
 package org.apache.geronimo.javamail.transport.smtp;
+ 
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Util class to represent a reply from a SMTP server
@@ -33,6 +36,9 @@
 
     // the returned message text
     private final String message;
+    
+    // additional returned lines from a continued response 
+    private List lines; 
 
     // indicates that this is a continuation response
     private boolean continued;
@@ -72,6 +78,40 @@
             throw new MalformedSMTPReplyException("error in parsing code", e);
         }
     }
+    
+    /**
+     * Add a line to a continued response.  This will 
+     * update the continued status if the end of the 
+     * response is reached. 
+     * 
+     * @param line   The line to add.
+     */
+    public void addLine(String line) {
+        if (lines == null) {
+            lines = new ArrayList(); 
+            lines.add(message); 
+        }
+        // mark if we're still continued 
+        continued = line.charAt(3) == '-';
+        // add the line to the list 
+        lines.add(line.substring(4)); 
+    }
+    
+    /**
+     * Get the list of all of the lines associated with 
+     * this reply. 
+     * 
+     * @return A List containing all lines associated with this
+     *         reply.
+     */
+    public List getLines() {
+        if (lines == null) {
+            lines = new ArrayList(); 
+            lines.add(message); 
+        }
+        return lines;
+    }
+    
 
     /**
      * Return the code value associated with the reply.

Modified: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java?rev=569336&r1=569335&r2=569336&view=diff
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java
(original)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java
Fri Aug 24 03:34:43 2007
@@ -32,6 +32,7 @@
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.StringTokenizer;
 
 import javax.mail.Address;
@@ -1381,17 +1382,9 @@
      */
     protected boolean getWelcome() throws MessagingException {
         SMTPReply line = getReply();
-        // process any error now
-        if (line.isError()) {
-            return false; 
-        }
-        // Some servers send a multi-line welcome message.  Keep 
-        // reading lines until we hit the end of the response. 
-        while (line.isContinued()) {
-            line = getReply(); 
-        }
-        // this worked. 
-        return true; 
+        // just return the error status...we don't care about any of the 
+        // response information
+        return !line.isError();
     }
 
     /**
@@ -1731,6 +1724,11 @@
     protected SMTPReply getReply() throws MessagingException {
         try {
             lastServerResponse = new SMTPReply(receiveLine());
+            // if the first line we receive is a continuation, continue 
+            // reading lines until we reach the non-continued one. 
+            while (lastServerResponse.isContinued()) {
+                lastServerResponse.addLine(receiveLine()); 
+            }
         } catch (MalformedSMTPReplyException e) {
             throw new MessagingException(e.toString());
         } catch (MessagingException e) {
@@ -1879,29 +1877,24 @@
     protected boolean sendEhlo() throws MessagingException {
         sendLine("EHLO " + getLocalHost());
 
-        SMTPReply line = getReply();
+        SMTPReply reply = getReply();
 
         // we get a 250 code back. The first line is just a greeting, and
         // extensions are identifed on
         // continuations. If this fails, then we'll try once more with HELO to
         // establish bona fides.
-        if (line.getCode() != COMMAND_ACCEPTED) {
+        if (reply.getCode() != COMMAND_ACCEPTED) {
             return false;
         }
 
         // get a fresh extension mapping table.
         serverExtensionArgs = new HashMap();
 
+        List lines = reply.getLines(); 
         // process all of the continuation lines
-        while (line.isContinued()) {
-            // get the next line
-            line = getReply();
-            if (line.getCode() != COMMAND_ACCEPTED) {
-                // all EHLO failures go back to the HELO failback step.
-                return false;
-            }
+        for (int i = 1; i < lines.size(); i++) {
             // go process the extention
-            processExtension(line.getMessage());
+            processExtension((String)lines.get(i));
         }
         return true;
     }



Mime
View raw message