2010-02-15 Gonzalo Paniagua Javier <gonzalo@novell.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Tue, 16 Feb 2010 01:22:22 +0000 (01:22 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Tue, 16 Feb 2010 01:22:22 +0000 (01:22 -0000)
* SmtpClient.cs: generate correct MIME when there are text and html
linked resources. Fixes bug #579984. Patch by Ásgeir Halldórsson.

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

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

index 349ef02221302e892916842f21433d16470edd7f..1dde195c8fa0766513df8354aaf9bc2e12ed013e 100644 (file)
@@ -1,3 +1,8 @@
+2010-02-15 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * SmtpClient.cs: generate correct MIME when there are text and html
+       linked resources. Fixes bug #579984. Patch by Ásgeir Halldórsson.
+
 2010-01-21 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * SmtpClient.cs: rethrow inner exception so that
index 012884823c24b141e0607ea24581db11cfa63a4f..e19d0aef6ffdb2ab8f5ca5ec62281625a4b1b6bf 100644 (file)
@@ -896,8 +896,10 @@ try {
                                        alt_boundary = GenerateBoundary ();
                                        contentType = new ContentType ("multipart/related");
                                        contentType.Boundary = alt_boundary;
-                                       contentType.Parameters ["type"] = "application/octet-stream";
+                                       
+                                       contentType.Parameters ["type"] = av.ContentType.ToString ();
                                        StartSection (inner_boundary, contentType);
+                                       StartSection (alt_boundary, av.ContentType, av.TransferEncoding);
                                } else {
                                        contentType = new ContentType (av.ContentType.ToString ());
                                        StartSection (inner_boundary, contentType, av.TransferEncoding);
@@ -945,8 +947,7 @@ try {
                private void SendLinkedResources (MailMessage message, LinkedResourceCollection resources, string boundary)
                {
                        foreach (LinkedResource lr in resources) {
-                               ContentType contentType = new ContentType (lr.ContentType.ToString ());
-                               StartSection (boundary, contentType, lr.TransferEncoding);
+                               StartSection (boundary, lr.ContentType, lr.TransferEncoding, lr);
 
                                switch (lr.TransferEncoding) {
                                case TransferEncoding.Base64:
@@ -1036,6 +1037,18 @@ try {
                        SendData (string.Empty);
                }
 
+               private void StartSection(string section, ContentType sectionContentType, TransferEncoding transferEncoding, LinkedResource lr)
+               {
+                       SendData (String.Format("--{0}", section));
+                       SendHeader ("content-type", sectionContentType.ToString ());
+                       SendHeader ("content-transfer-encoding", GetTransferEncodingName (transferEncoding));
+
+                       if (lr.ContentId != null && lr.ContentId.Length > 0)
+                               SendHeader("content-ID", "<" + lr.ContentId + ">");
+
+                       SendData (string.Empty);
+               }
+
                private void StartSection (string section, ContentType sectionContentType, TransferEncoding transferEncoding, ContentDisposition contentDisposition) {
                        SendData (String.Format ("--{0}", section));
                        SendHeader ("content-type", sectionContentType.ToString ());