2009-06-08 Gonzalo Paniagua Javier <gonzalo@novell.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Mon, 8 Jun 2009 20:40:18 +0000 (20:40 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Mon, 8 Jun 2009 20:40:18 +0000 (20:40 -0000)
* SmtpClient.cs: handle dots. Patch by Ted Unangst that fixes bug
#392875.

svn path=/trunk/mcs/; revision=135692

mcs/class/System/System.Net.Mail/ChangeLog
mcs/class/System/System.Net.Mail/SmtpClient.cs

index 577708b4df330e2da7125b8ae55d77038a356c48..a2a18ece713f443f52f5cf2113884d8a444d6405 100644 (file)
@@ -1,3 +1,7 @@
+2009-06-08 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * SmtpClient.cs: handle dots. Patch by Ted Unangst that fixes bug
+       #392875.
 
 2008-11-17 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
index 516f46f350f64324e42d4b4d2c1f8d3ce97a84e3..6ce88f62b75ef24047f10747b971a6af5da4e849 100644 (file)
@@ -683,7 +683,7 @@ namespace System.Net.Mail {
                        else
                                SendWithoutAttachments (message, null, false);
 
-                       SendData (".");
+                       SendDot ();
 
                        status = Read ();
                        if (IsError (status))
@@ -701,17 +701,39 @@ namespace System.Net.Mail {
                        Send (new MailMessage (from, to, subject, body));
                }
 
+               private void SendDot()
+               {
+                       writer.Write(".\r\n");
+                       writer.Flush();
+               }
+
                private void SendData (string data)
                {
-                       CheckCancellation ();
+                       if (String.IsNullOrEmpty (data)) {
+                               writer.Write("\r\n");
+                               writer.Flush();
+                               return;
+                       }
 
-                       // Certain SMTP servers will reject mail sent with unix line-endings; see http://cr.yp.to/docs/smtplf.html
-                       StringBuilder sb = new StringBuilder (data);
-                       sb.Replace ("\r\n", "\n");
-                       sb.Replace ('\r', '\n');
-                       sb.Replace ("\n", "\r\n");
-                       writer.Write (sb.ToString ());
-                       writer.Write ("\r\n");
+                       StringReader sr = new StringReader (data);
+                       string line;
+                       bool escapeDots = deliveryMethod == SmtpDeliveryMethod.Network;
+                       while ((line = sr.ReadLine ()) != null) {
+                               CheckCancellation ();
+
+                               if (escapeDots) {
+                                       int i;
+                                       for (i = 0; i < line.Length; i++) {
+                                               if (line[i] != '.')
+                                                       break;
+                                       }
+                                       if (i > 0 && i == line.Length) {
+                                               line += ".";
+                                       }
+                               }
+                               writer.Write (line);
+                               writer.Write ("\r\n");
+                       }
                        writer.Flush ();
                }