+2008-08-12 Atsushi Enomoto <atsushi@ximian.com>
+
+ * SmtpClient.cs : fixed bug #392682, in the same spirit in the
+ patch by Ted Unangst, to assure safety on socket closing.
+
2008-08-07 Atsushi Enomoto <atsushi@ximian.com>
* SmtpClient.cs : Fixed bug #392809, patch by Ted Unangst. Text body
mutex.WaitOne ();
try {
messageInProcess = message;
- SendCore (message);
+ SendInternal (message);
} catch (CancellationException) {
// This exception is introduced for convenient cancellation process.
} finally {
}
}
- private void SendCore (MailMessage message)
+ private void SendInternal (MailMessage message)
{
- SmtpResponse status;
-
CheckCancellation ();
- client = new TcpClient (host, port);
- stream = client.GetStream ();
- // FIXME: this StreamWriter creation is bogus.
- // It expects as if a Stream were able to switch to SSL
- // mode (such behavior is only in Mainsoft Socket API).
- writer = new StreamWriter (stream);
- reader = new StreamReader (stream);
+ try {
+ client = new TcpClient (host, port);
+ stream = client.GetStream ();
+ // FIXME: this StreamWriter creation is bogus.
+ // It expects as if a Stream were able to switch to SSL
+ // mode (such behavior is only in Mainsoft Socket API).
+ writer = new StreamWriter (stream);
+ reader = new StreamReader (stream);
+
+ SendCore (message);
+ } finally {
+ if (writer != null)
+ writer.Close ();
+ if (reader != null)
+ reader.Close ();
+ if (stream != null)
+ stream.Close ();
+ if (client != null)
+ client.Close ();
+ }
+ }
+
+ private void SendCore (MailMessage message)
+ {
+ SmtpResponse status;
status = Read ();
if (IsError (status))
} catch (System.IO.IOException) {
// We excuse server for the rude connection closing as a response to QUIT
}
-
- writer.Close ();
- reader.Close ();
- stream.Close ();
- client.Close ();
}
public void Send (string from, string to, string subject, string body)