[Mono-dev] [PATCH] SmtpClient minor bugs

Michal Bochnak bochnak at hotmail.com
Fri Jun 4 17:00:32 EDT 2010


I found two minor bugs while running Mono's implementation of SmtpClient.

 

1. Mail sent using Mono's SmtpClient always encodes mail addresses to format
"display_name" <email at email.com>, regardless of display name not being
provided. This results in delivered emails show in some mail clients (e.g.
Outlook) to come from an empty address. Here's a simple patch for it (2.6):



Index: SmtpClient.cs

===================================================================

--- SmtpClient.cs    (revision 158490)

+++ SmtpClient.cs    (working copy)

@@ -264,8 +264,13 @@

              

              private static string EncodeAddress(MailAddress address)

              {

-                    string encodedDisplayName =
ContentType.EncodeSubjectRFC2047 (address.DisplayName, Encoding.UTF8);

-                    return "\"" + encodedDisplayName + "\" <" +
address.Address + ">";

+                    if (string.IsNullOrEmpty(address.DisplayName)) {

+                          return address.Address;

+                    }

+                    else {

+                          string encodedDisplayName =
ContentType.EncodeSubjectRFC2047 (address.DisplayName, Encoding.UTF8);

+                          return "\"" + encodedDisplayName + "\" <" +
address.Address + ">";

+                    }

              }

 

              private static string EncodeAddresses(MailAddressCollection
addresses)

 

 

2. Upon delivery of mail, when recipient is rejected (or other recipient
error occurs), only status and recipient are preserved in
SmtpFailedRecipientException object. Original response is not preserved
which is a bug. Here's a fix for it (2.6):

 

Index: SmtpClient.cs

===================================================================

--- SmtpClient.cs    (revision 158490)

+++ SmtpClient.cs    (working copy)

@@ -621,17 +621,17 @@

                     for (int i = 0; i < message.To.Count; i ++) {

                           status = SendCommand ("RCPT TO:<" + message.To
[i].Address + '>');

                           if (IsError (status)) 

-                                 sfre.Add (new SmtpFailedRecipientException
(status.StatusCode, message.To [i].Address));

+                                 sfre.Add (new SmtpFailedRecipientException
(status.StatusCode, message.To [i].Address, status.Description));

                     }

                     for (int i = 0; i < message.CC.Count; i ++) {

                           status = SendCommand ("RCPT TO:<" + message.CC
[i].Address + '>');

                           if (IsError (status)) 

-                                 sfre.Add (new SmtpFailedRecipientException
(status.StatusCode, message.CC [i].Address));

+                                 sfre.Add (new SmtpFailedRecipientException
(status.StatusCode, message.CC [i].Address, status.Description));

                     }

                     for (int i = 0; i < message.Bcc.Count; i ++) {

                           status = SendCommand ("RCPT TO:<" + message.Bcc
[i].Address + '>');

                           if (IsError (status)) 

-                                 sfre.Add (new SmtpFailedRecipientException
(status.StatusCode, message.Bcc [i].Address));

+                                 sfre.Add (new SmtpFailedRecipientException
(status.StatusCode, message.Bcc [i].Address, status.Description));

                     }

 

 #if TARGET_JVM // List<T>.ToArray () is not supported

 

 

I'm not sure if this is a proper way for submitting patches but it is
selfish and definitely the beginning of an adventure with Mono.
http://mono-project.com/Contributing

Thank you!

Michal

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100604/d457d2dc/attachment-0001.html 


More information about the Mono-devel-list mailing list