geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r670717 - in /geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail: transport/smtp/SMTPTransport.java util/MIMEOutputStream.java
Date Mon, 23 Jun 2008 19:41:20 GMT
Author: rickmcguire
Date: Mon Jun 23 12:41:19 2008
New Revision: 670717

URL: http://svn.apache.org/viewvc?rev=670717&view=rev
Log:
GERONIMO-4135 Too many CRLF at the end of the message

Uncovered by the James test suite. 


Modified:
    geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_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/util/MIMEOutputStream.java

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=670717&r1=670716&r2=670717&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
Mon Jun 23 12:41:19 2008
@@ -1438,20 +1438,20 @@
             // The MIME output stream performs those two functions on behalf of
             // the content
             // writer.
-            OutputStream mimeOut = new MIMEOutputStream(outputStream);
+            MIMEOutputStream mimeOut = new MIMEOutputStream(outputStream);
 
             msg.writeTo(mimeOut);
-            mimeOut.flush();
+
+            // now to finish, we send a CRLF sequence, followed by a ".".
+            mimeOut.writeSMTPTerminator();           
+            // and flush the data to send it along 
+            mimeOut.flush();   
         } catch (IOException e) {
             throw new MessagingException(e.toString());
         } catch (MessagingException e) {
             throw new MessagingException(e.toString());
         }
 
-        // now to finish, we send a CRLF sequence, followed by a ".".
-        sendLine("");
-        sendLine(".");
-
         // use a longer time out here to give the server time to process the
         // data.
         try {

Modified: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/util/MIMEOutputStream.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/util/MIMEOutputStream.java?rev=670717&r1=670716&r2=670717&view=diff
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/util/MIMEOutputStream.java
(original)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/util/MIMEOutputStream.java
Mon Jun 23 12:41:19 2008
@@ -96,4 +96,37 @@
         // remember this last one for CRLF tracking purposes.
         lastWrite = ch;
     }
+    
+    
+    /**
+     * Force the stream to be terminated at a line break. 
+     * This is generally in preparation for the transport to 
+     * write out an end-of-data marker, which generally 
+     * needs to be preceded by a CRLF sequence. 
+     * 
+     * @exception IOException
+     */
+    public void forceTerminatingLineBreak() throws IOException {
+        if (!atLineBreak) {
+            out.write((byte) '\r');
+            out.write((byte) '\n');
+            // we've just taken a break;
+            atLineBreak = true;
+        }
+    }
+    
+    
+    /**
+     * Write out the SMTP terminator to the output stream. 
+     * This ensures that we don't write out an extra 
+     * CRLF if the data terminates with that value.  
+     * 
+     * @exception IOException
+     */
+    public void writeSMTPTerminator() throws IOException {
+        forceTerminatingLineBreak(); 
+        out.write('.'); 
+        out.write('\r'); 
+        out.write('\n'); 
+    }
 }



Mime
View raw message