[Dnsmail-cvs] dnsmail/DnsMail DnsMail.cs, 1.5, 1.6 OpenSslStream.cs, 1.3, NONE
Brought to you by:
ethem
From: Ethem E. <et...@us...> - 2006-08-04 12:53:40
|
Update of /cvsroot/dnsmail/dnsmail/DnsMail In directory sc8-pr-cvs12.sourceforge.net:/tmp/cvs-serv31965/dnsmail/DnsMail Modified Files: DnsMail.cs Removed Files: OpenSslStream.cs Log Message: - OpensslStream class removed and new SmtpStream class derived from NetworkStream added. - New class handles normal and ssl connections automatically. - Socket and OpenSslStream removed from DnsMail client. New SmtpStream member added. --- OpenSslStream.cs DELETED --- Index: DnsMail.cs =================================================================== RCS file: /cvsroot/dnsmail/dnsmail/DnsMail/DnsMail.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DnsMail.cs 4 Aug 2006 09:52:19 -0000 1.5 --- DnsMail.cs 4 Aug 2006 12:53:36 -0000 1.6 *************** *** 35,40 **** #region Class Members ! private Socket m_Client; // Mail Client ! private OpenSslStream m_Ssl; // SSL Stream private Int32 m_RcptCount; // Recipient OK Count private Encoding m_Enc; // Charset Encoder --- 35,39 ---- #region Class Members ! private SmtpStream m_Stream; // Data Stream private Int32 m_RcptCount; // Recipient OK Count private Encoding m_Enc; // Charset Encoder *************** *** 167,175 **** #region ssl section - - private bool normalconn = true; public bool SslActive { ! get { return (!normalconn); } } --- 166,172 ---- #region ssl section public bool SslActive { ! get { return (m_Stream != null && m_Stream.SslActive); } } *************** *** 263,292 **** * Release UNmanaged objects... **************************************************/ ! // Socket release ! if( m_Client != null ) { try { ! if( m_Client.Poll(1000, SelectMode.SelectWrite) ) SendAndReceive("QUIT\r\n"); } catch {} ! ! if (m_Ssl != null) ! { ! normalconn = true; ! try { m_Ssl.Close(); } ! catch {} ! m_Ssl = null; ! } ! ! try { m_Client.Shutdown(SocketShutdown.Receive); } ! catch {} ! finally ! { ! m_Client.Close(); ! m_Client = null; ! } ! OnClosed(EventArgs.Empty); } --- 260,273 ---- * Release UNmanaged objects... **************************************************/ ! if( m_Stream != null ) { try { ! if( m_Stream.Poll(1000, SelectMode.SelectWrite) ) SendAndReceive("QUIT\r\n"); } catch {} ! m_Stream.Close(); ! m_Stream = null; OnClosed(EventArgs.Empty); } *************** *** 402,406 **** bool isok; string[] pars; - Recipient rec; m_RcptCount = 1; StringBuilder sb; --- 383,386 ---- *************** *** 408,414 **** string originalSubject = mi.Subject; bool readycontrol = false, senddatax = false, sendersent = true; ! for(IEnumerator ien = mi.Recipients.GetEnumerator(); ien.MoveNext(); ) { - rec = ien.Current as Recipient; try { --- 388,393 ---- string originalSubject = mi.Subject; bool readycontrol = false, senddatax = false, sendersent = true; ! foreach(Recipient rec in mi.Recipients) { try { *************** *** 562,586 **** private bool isready(IPAddress ip) { ! if (ip == null) return false; ! try { ! m_Client = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); ! m_Client.Bind(LocalPoint); ! m_Client.SetSocketOption(SocketOptionLevel.Tcp,SocketOptionName.NoDelay,1); ! m_Client.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReceiveTimeout,TimeOut); ! m_Client.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.SendTimeout,TimeOut); ! m_Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, new LingerOption(true, 5)); ! m_Client.Connect( new IPEndPoint(ip, Port) ); ! if( m_Client.Poll(7 * TimeOut, SelectMode.SelectRead) && SendAndReceive(null)==Commands.Ok) { ! esmtp = (LastAnswer.ToLower().IndexOf("esmtp") != -1); ! OnConnect( ip.ToString() ); ! return true; } } ! catch {} ! m_Client.Close(); ! m_Client = null; ! return false; } --- 541,578 ---- private bool isready(IPAddress ip) { ! bool ret = false; ! if (ip != null) { ! Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); ! try { ! s.Bind(LocalPoint); ! s.SetSocketOption(SocketOptionLevel.Tcp,SocketOptionName.NoDelay,1); ! s.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReceiveTimeout,TimeOut); ! s.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.SendTimeout,TimeOut); ! s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, new LingerOption(true, 5)); ! s.Connect( new IPEndPoint(ip, Port) ); ! if( s.Poll(7 * TimeOut, SelectMode.SelectRead) ) ! { ! m_Stream = new SmtpStream(s, true); ! if (SendAndReceive(null) == Commands.Ok) ! { ! esmtp = (LastAnswer.ToLower().IndexOf("esmtp") != -1); ! OnConnect( ip.ToString() ); ! ret = true; ! } ! } ! } ! catch ! { ! s.Close(); ! if (m_Stream != null) ! { ! m_Stream.Close(); ! m_Stream = null; ! } } } ! return ret; } *************** *** 596,618 **** return; ! if (!normalconn) ! return; ! ! m_Ssl = new OpenSslStream(true); ! if (!m_Ssl.InitOk) ! { ! m_Ssl = null; return; - } if( SendAndReceive("STARTTLS\r\n") != Commands.Ok ) { - m_Ssl.Close(); m_Ssl = null; SendAndReceive("RSET\r\n"); return; } ! normalconn = (false == m_Ssl.Open(m_Client)); ! sayhello(); } --- 588,604 ---- return; ! if (!SmtpStream.SslAvailable || m_Stream == null || m_Stream.SslActive) return; if( SendAndReceive("STARTTLS\r\n") != Commands.Ok ) { SendAndReceive("RSET\r\n"); return; } ! if (m_Stream.Handshake(true)) ! { ! sayhello(); // say hello again. ! } } *************** *** 825,829 **** OnSendProgress(totalsent, remain); buffer = null; ! if ((totalsent < len) && m_Client.Connected) { goto Label_loop; --- 811,815 ---- OnSendProgress(totalsent, remain); buffer = null; ! if ((totalsent < len) && m_Stream.Poll(500, SelectMode.SelectWrite)) { goto Label_loop; *************** *** 841,845 **** try { ! if (m_Client != null && m_Client.Connected && m_Client.Poll(TimeOut, SelectMode.SelectWrite)) SocketWrite(crlf_dot_crlf, crlf_dot_crlf.Length); } --- 827,831 ---- try { ! if (m_Stream != null && m_Stream.Poll(TimeOut, SelectMode.SelectWrite)) SocketWrite(crlf_dot_crlf, crlf_dot_crlf.Length); } *************** *** 866,875 **** int bytes, breceived = 0; String tmpResp = String.Empty; do { ! bytes = (normalconn) ? ! m_Client.Receive(recvBuffer, 0, recvBuffer.Length, SocketFlags.None) : ! m_Ssl.Read(recvBuffer, 0, recvBuffer.Length); ! if (bytes<=0 || breceived>MaxBuffer) break; breceived += bytes; --- 852,859 ---- int bytes, breceived = 0; String tmpResp = String.Empty; + do { ! bytes = m_Stream.Read(recvBuffer, 0, recvBuffer.Length); if (bytes<=0 || breceived>MaxBuffer) break; breceived += bytes; *************** *** 880,884 **** break; } ! } while(m_Client.Poll(500, SelectMode.SelectRead)); if (tmpResp.Length < 4) --- 864,868 ---- break; } ! } while(m_Stream.Poll(500, SelectMode.SelectRead)); if (tmpResp.Length < 4) *************** *** 899,906 **** private int SocketWrite(byte[] buf, int len) { ! if (normalconn) ! return m_Client.Send(buf, 0, len, SocketFlags.None); ! ! m_Ssl.Write(buf, 0, len); return len; } --- 883,887 ---- private int SocketWrite(byte[] buf, int len) { ! m_Stream.Write(buf, 0, len); return len; } |