2008-08-15 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Fri, 15 Aug 2008 05:56:20 +0000 (05:56 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Fri, 15 Aug 2008 05:56:20 +0000 (05:56 -0000)
* SmtpClient.cs : fixed bug #382670, based on the patch by Ted
  Unangst. DeriveryMethod.SpecifiedPickupDirectory was not supported.

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

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

index 3eed1764d4dc137298aa70515844e90517d84d53..93e89b8907fbf6c49d2e2a3206676adcb265501f 100644 (file)
@@ -1,3 +1,8 @@
+2008-08-15  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * SmtpClient.cs : fixed bug #382670, based on the patch by Ted
+         Unangst. DeriveryMethod.SpecifiedPickupDirectory was not supported.
+
 2008-08-14  Atsushi Enomoto  <atsushi@ximian.com>
 
        * SmtpClient.cs : Patch by Ted Unangst, fixed bug #392843.
index 8dd5c9b8ca70b74c766c5b8ed369d013b862ca34..ded9c497c67929a07c73902899f7451c3cbaa915 100644 (file)
@@ -453,9 +453,17 @@ namespace System.Net.Mail {
                        if (message == null)
                                throw new ArgumentNullException ("message");
 
-                       if (String.IsNullOrEmpty (Host))
+                       if (deliveryMethod == SmtpDeliveryMethod.Network && String.IsNullOrEmpty (Host))
                                throw new InvalidOperationException ("The SMTP host was not specified");
-                       
+                       if (deliveryMethod == SmtpDeliveryMethod.SpecifiedPickupDirectory) {
+                               if (String.IsNullOrEmpty(pickupDirectoryLocation))
+                                       throw new SmtpException("The pickup directory was not specified");
+                               if (false && pickupDirectoryLocation[0] != '/')
+                                       throw new SmtpException("Only absolute directories are allowed for pickup directory.");
+                       }
+                       if (deliveryMethod == SmtpDeliveryMethod.PickupDirectoryFromIis)
+                               throw new NotSupportedException("IIS delivery is not supported");
+
                        if (port == 0)
                                port = 25;
                        
@@ -463,7 +471,10 @@ namespace System.Net.Mail {
                        mutex.WaitOne ();
                        try {
                                messageInProcess = message;
-                               SendInternal (message);
+                               if (deliveryMethod == SmtpDeliveryMethod.SpecifiedPickupDirectory)
+                                       SendToFile (message, pickupDirectoryLocation + "/" + Guid.NewGuid() + ".eml");
+                               else
+                                       SendInternal (message);
                        } catch (CancellationException) {
                                // This exception is introduced for convenient cancellation process.
                        } finally {
@@ -498,6 +509,41 @@ namespace System.Net.Mail {
                                        client.Close ();
                        }
                }
+               // FIXME: simple implementation, could be brushed up.
+               private void SendToFile (MailMessage message, String filename)
+               {
+                       try {
+                               writer = new StreamWriter(filename);
+
+                               MailAddress from = message.From;
+
+                               if (from == null)
+                                       from = defaultFrom;
+                               
+                               SendHeader (HeaderName.Date, DateTime.Now.ToString ("ddd, dd MMM yyyy HH':'mm':'ss zzz", DateTimeFormatInfo.InvariantInfo));
+                               SendHeader (HeaderName.From, from.ToString ());
+                               SendHeader (HeaderName.To, message.To.ToString ());
+                               if (message.CC.Count > 0)
+                                       SendHeader (HeaderName.Cc, message.CC.ToString ());
+                               SendHeader (HeaderName.Subject, EncodeSubjectRFC2047 (message));
+
+                               foreach (string s in message.Headers.AllKeys)
+                                       SendHeader (s, message.Headers [s]);
+
+                               AddPriorityHeader (message);
+
+                               boundaryIndex = 0;
+                               if (message.Attachments.Count > 0)
+                                       SendWithAttachments (message);
+                               else
+                                       SendWithoutAttachments (message, null, false);
+
+
+                       } finally {
+                               if (writer != null) writer.Close(); writer = null;
+                       }
+               }
 
                private void SendCore (MailMessage message)
                {