commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1697379 - in /commons/proper/net/trunk/src: changes/changes.xml main/java/org/apache/commons/net/smtp/SimpleSMTPHeader.java
Date Mon, 24 Aug 2015 13:04:12 GMT
Author: sebb
Date: Mon Aug 24 13:04:12 2015
New Revision: 1697379

URL: http://svn.apache.org/r1697379
Log:
NET-582 SimpleSMTPHeader does not allow for missing To: field

Modified:
    commons/proper/net/trunk/src/changes/changes.xml
    commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/SimpleSMTPHeader.java

Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1697379&r1=1697378&r2=1697379&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/net/trunk/src/changes/changes.xml [utf-8] Mon Aug 24 13:04:12 2015
@@ -73,6 +73,9 @@ This is mainly a bug-fix release. See fu
   This is the inverse of the IMAPImportMbox example added previously
         ">
         
+            <action issue="NET-582" type="fix" dev="sebb">
+            SimpleSMTPHeader does not allow for missing To: field
+            </action>
             <action issue="NET-580" type="fix" dev="sebb" due-to="Simon Arlott">
             SMTPClient.sendSimpleMessage() silently ignores failed recipients
             Update Javadoc

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/SimpleSMTPHeader.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/SimpleSMTPHeader.java?rev=1697379&r1=1697378&r2=1697379&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/SimpleSMTPHeader.java
(original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/SimpleSMTPHeader.java
Mon Aug 24 13:04:12 2015
@@ -47,7 +47,9 @@ package org.apache.commons.net.smtp;
 
 public class SimpleSMTPHeader
 {
-    private final String __subject, __from, __to;
+    private final String __subject;
+    private final String __from;
+    private final String __to;
     private final StringBuffer __headerFields;
     private StringBuffer __cc;
 
@@ -57,13 +59,19 @@ public class SimpleSMTPHeader
      * <p>
      * @param from  The value of the <code>From:</code> header field.  This
      *              should be the sender's email address.
+     *              Must not be null.
      * @param to    The value of the <code>To:</code> header field.  This
      *              should be the recipient's email address.
+     *              May be null
      * @param subject  The value of the <code>Subject:</code> header field.
      *              This should be the subject of the message.
+     *              May be null
      ***/
     public SimpleSMTPHeader(String from, String to, String subject)
     {
+        if (from == null) {
+            throw new IllegalArgumentException("From cannot be null");
+        }
         __to = to;
         __from = from;
         __subject = subject;
@@ -126,25 +134,23 @@ public class SimpleSMTPHeader
             header.append(__headerFields.toString());
         }
 
-        header.append("From: ");
-        header.append(__from);
-        header.append("\nTo: ");
-        header.append(__to);
+        header.append("From: ").append(__from).append("\n");
+
+        if (__to != null) {
+            header.append("To: ").append(__to).append("\n");
+        }
 
         if (__cc != null)
         {
-            header.append("\nCc: ");
-            header.append(__cc.toString());
+            header.append("Cc: ").append(__cc.toString()).append("\n");
         }
 
         if (__subject != null)
         {
-            header.append("\nSubject: ");
-            header.append(__subject);
+            header.append("Subject: ").append(__subject).append("\n");
         }
 
-        header.append('\n');
-        header.append('\n');
+        header.append('\n'); // end of headers; body follows
 
         return header.toString();
     }



Mime
View raw message