New test.
[mono.git] / mcs / class / System / System.Net.Mail / SmtpClient.cs
index 6ce88f62b75ef24047f10747b971a6af5da4e849..8fe2b6ae83df9d688041155c05132b316e178951 100644 (file)
@@ -123,6 +123,11 @@ namespace System.Net.Mail {
                        if (cfg != null) {
                                this.host = cfg.Network.Host;
                                this.port = cfg.Network.Port;
+                               TargetName = cfg.Network.TargetName;
+                               if (this.TargetName == null)
+                                       TargetName = "SMTPSVC/" + (host != null ? host : "");
+
+                               
                                if (cfg.Network.UserName != null) {
                                        string password = String.Empty;
 
@@ -135,6 +140,9 @@ namespace System.Net.Mail {
                                if (cfg.From != null)
                                        defaultFrom = new MailAddress (cfg.From);
                        }
+#else
+                       // Just to eliminate the warning, this codepath does not end up in production.
+                       defaultFrom = null;
 #endif
 
                        if (!String.IsNullOrEmpty (host))
@@ -159,6 +167,11 @@ namespace System.Net.Mail {
                }
 #endif
 
+#if NET_4_0
+               public
+#endif
+               string TargetName { get; set; }
+
                public ICredentialsByHost Credentials {
                        get { return credentials; }
                        set {
@@ -669,12 +682,17 @@ namespace System.Net.Mail {
                        SendHeader ("Priority", v);
                        if (message.Sender != null)
                                SendHeader ("Sender", EncodeAddress (message.Sender));
-                       if (message.ReplyTo != null)
-                               SendHeader ("ReplyTo", EncodeAddress (message.ReplyTo));
-                       
+                       if (message.ReplyToList.Count > 0)
+                               SendHeader ("Reply-To", EncodeAddresses (message.ReplyToList));
+
+#if NET_4_0
+                       foreach (string s in message.Headers.AllKeys)
+                               SendHeader (s, ContentType.EncodeSubjectRFC2047 (message.Headers [s], message.HeadersEncoding));
+#else
                        foreach (string s in message.Headers.AllKeys)
                                SendHeader (s, message.Headers [s]);
-
+#endif
+       
                        AddPriorityHeader (message);
 
                        boundaryIndex = 0;
@@ -749,6 +767,7 @@ namespace System.Net.Mail {
                                        Send (message);
                                } catch (Exception ex) {
                                        ea.Result = ex;
+                                       throw ex;
                                }
                        };
                        worker.WorkerSupportsCancellation = true;
@@ -880,8 +899,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);
@@ -929,8 +950,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:
@@ -1020,6 +1040,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 ());
@@ -1091,6 +1123,10 @@ try {
                                                                         X509Certificate certificate,
                                                                         X509Chain chain,
                                                                         SslPolicyErrors sslPolicyErrors) {
+                       // honor any exciting callback defined on ServicePointManager
+                       if (ServicePointManager.ServerCertificateValidationCallback != null)
+                               return ServicePointManager.ServerCertificateValidationCallback (sender, certificate, chain, sslPolicyErrors);
+                       // otherwise provide our own
                        if (sslPolicyErrors != SslPolicyErrors.None)
                                throw new InvalidOperationException ("SSL authentication error: " + sslPolicyErrors);
                        return true;