Ejemplo n.º 1
0
        public Boolean AuthenticateByAPop()
        {
            String s          = "";
            String TimeStamp  = "";
            Int32  StartIndex = 0;
            Int32  EndIndex   = 0;

            if (this.EnsureOpen() == Pop3ConnectionState.Connected)
            {
                s = this.Execute("user " + this._UserName, false);
                if (s.StartsWith("+OK") == true)
                {
                    if (s.IndexOf("<") > -1 &&
                        s.IndexOf(">") > -1)
                    {
                        StartIndex = s.IndexOf("<");
                        EndIndex   = s.IndexOf(">");
                        TimeStamp  = s.Substring(StartIndex, EndIndex - StartIndex + 1);

                        s = this.Execute("pass " + MailParser.ToMd5DigestString(TimeStamp + this._Password), false);
                        if (s.StartsWith("+OK") == true)
                        {
                            this._State = Pop3ConnectionState.Authenticated;
                        }
                    }
                }
            }
            return(this._State == Pop3ConnectionState.Authenticated);
        }
Ejemplo n.º 2
0
        /// POP3メールサーバーへAPOP認証でログインします。
        /// <summary>
        /// Log in to pop3 server by A-POP authenticate and return login success or failure as bool.
        /// POP3メールサーバーへAPOP認証でログインします。
        /// </summary>
        /// <returns></returns>
        public Boolean TryAuthenticateByAPop()
        {
            Pop3CommandResult rs         = null;
            String            TimeStamp  = "";
            Int32             StartIndex = 0;
            Int32             EndIndex   = 0;

            if (this.EnsureOpen() == Pop3ConnectionState.Connected)
            {
                //ユーザー名送信
                rs = this.Execute("user " + this.UserName, false);
                if (rs.Ok == true)
                {
                    if (rs.Text.IndexOf("<") > -1 &&
                        rs.Text.IndexOf(">") > -1)
                    {
                        StartIndex = rs.Text.IndexOf("<");
                        EndIndex   = rs.Text.IndexOf(">");
                        TimeStamp  = rs.Text.Substring(StartIndex, EndIndex - StartIndex + 1);
                        //パスワード送信
                        rs = this.Execute("pass " + Cryptography.ToMd5DigestString(TimeStamp + this.Password), false);
                        if (rs.Ok == true)
                        {
                            this._State = Pop3ConnectionState.Authenticated;
                        }
                    }
                }
            }
            return(this._State == Pop3ConnectionState.Authenticated);
        }
Ejemplo n.º 3
0
        private TcpClient GetTcpClient()
        {
            TcpClient   tc        = null;
            IPHostEntry hostEntry = null;


            hostEntry = this.GetHostEntry();

            if (hostEntry != null)
            {
                foreach (IPAddress address in hostEntry.AddressList)
                {
                    tc = this.TryGetTcpClient(address);
                    if (tc != null)
                    {
                        break;
                    }
                }
            }
            if (tc == null)
            {
                this._State = Pop3ConnectionState.Disconnected;
                return(null);
            }
            this._State = Pop3ConnectionState.Connected;
            return(tc);
        }
Ejemplo n.º 4
0
        public Boolean AuthenticateByPop()
        {
            String s = "";

            if (this.EnsureOpen() == Pop3ConnectionState.Connected)
            {
                s = this.Execute("user " + this._UserName, false);
                if (s.StartsWith("+OK") == true)
                {
                    s = this.Execute("pass " + this._Password, false);
                    if (s.StartsWith("+OK") == true)
                    {
                        this._State = Pop3ConnectionState.Authenticated;
                    }
                }
            }
            return(this._State == Pop3ConnectionState.Authenticated);
        }
Ejemplo n.º 5
0
        /// POP3メールサーバーへPOP認証でログインします。
        /// <summary>
        /// Log in to pop3 server by POP authenticate and return login success or failure as bool.
        /// POP3メールサーバーへPOP認証でログインします。
        /// </summary>
        /// <returns></returns>
        public Boolean TryAuthenticateByPop()
        {
            Pop3CommandResult rs = null;

            if (this.EnsureOpen() == Pop3ConnectionState.Connected)
            {
                //ユーザー名送信
                rs = this.Execute("user " + this.UserName, false);
                if (rs.Ok == true)
                {
                    //パスワード送信
                    rs = this.Execute("pass " + this.Password, false);
                    if (rs.Ok == true)
                    {
                        this._State = Pop3ConnectionState.Authenticated;
                    }
                }
            }
            return(this._State == Pop3ConnectionState.Authenticated);
        }
Ejemplo n.º 6
0
 /// サーバーへの接続を開きます。
 /// <summary>
 /// Open connection to a server.
 /// サーバーへの接続を開きます。
 /// </summary>
 public Pop3ConnectionState Open()
 {
     if (this.Connect() == true)
     {
         var s = this.GetResponse();
         if (s.StartsWith("+OK") == true)
         {
             this._State = Pop3ConnectionState.Connected;
         }
         else
         {
             this.Socket = null;
             this.Stream = null;
             this._State = Pop3ConnectionState.Disconnected;
         }
     }
     else
     {
         this._State = Pop3ConnectionState.Disconnected;
     }
     return(this._State);
 }
Ejemplo n.º 7
0
 public Pop3ConnectionState Open()
 {
     this._TcpClient = this.GetTcpClient();
     if (this._TcpClient == null)
     {
         this._State = Pop3ConnectionState.Disconnected;
     }
     else
     {
         if (this._Ssl == true)
         {
             SslStream ssl = new SslStream(this._TcpClient.GetStream(), false, this.RemoteCertificateValidationCallback);
             ssl.AuthenticateAsClient(this._ServerName);
             if (ssl.IsAuthenticated == false)
             {
                 this._State     = Pop3ConnectionState.Disconnected;
                 this._TcpClient = null;
                 return(this._State);
             }
             this._Stream = ssl;
         }
         else
         {
             this._Stream = this._TcpClient.GetStream();
         }
         if (this.GetResponse().StartsWith("+OK") == true)
         {
             this._State = Pop3ConnectionState.Connected;
         }
         else
         {
             this._TcpClient = null;
             this._State     = Pop3ConnectionState.Disconnected;
         }
     }
     return(this._State);
 }
Ejemplo n.º 8
0
 public void Close()
 {
     this._TcpClient.Close();
     this._State = Pop3ConnectionState.Disconnected;
 }
Ejemplo n.º 9
0
 /// サーバーへの接続を開きます。
 /// <summary>
 /// Open connection to a server.
 /// サーバーへの接続を開きます。
 /// </summary>
 public Pop3ConnectionState Open()
 {
     if (this.Connect() == true)
     {
         var s = this.GetResponse();
         if (s.Ok == true)
         {
             this.State = Pop3ConnectionState.Connected;
         }
         else
         {
             this.Close();
         }
     }
     else
     {
         this.State = Pop3ConnectionState.Disconnected;
     }
     return this._State;
 }
Ejemplo n.º 10
0
 /// メールサーバーとの接続を切断します。
 /// <summary>
 /// disconnect connection to pop3 server.
 /// メールサーバーとの接続を切断します。
 /// </summary>
 public override void Close()
 {
     base.Close();
     this._State = Pop3ConnectionState.Disconnected;
 }
Ejemplo n.º 11
0
        /// POP3メールサーバーへPOP認証でログインします。
        /// <summary>
        /// Log in to pop3 server by POP authenticate and return login success or failure as bool.
        /// POP3メールサーバーへPOP認証でログインします。
        /// </summary>
        /// <returns></returns>
        public Boolean TryAuthenticateByPop()
        {
            Pop3CommandResult rs = null;

            if (this.EnsureOpen() == Pop3ConnectionState.Connected)
            {
                //ユーザー名送信
                rs = this.Execute("user " + this.UserName, false);
                if (rs.Ok == true)
                {
                    //パスワード送信
                    rs = this.Execute("pass " + this.Password, false);
                    if (rs.Ok == true)
                    {
                        this._State = Pop3ConnectionState.Authenticated;
                    }
                }
            }
            return this._State == Pop3ConnectionState.Authenticated;
        }
Ejemplo n.º 12
0
        /// POP3メールサーバーへAPOP認証でログインします。
        /// <summary>
        /// Log in to pop3 server by A-POP authenticate and return login success or failure as bool.
        /// POP3メールサーバーへAPOP認証でログインします。
        /// </summary>
        /// <returns></returns>
        public Boolean TryAuthenticateByAPop()
        {
            Pop3CommandResult rs = null;
            String TimeStamp = "";
            Int32 StartIndex = 0;
            Int32 EndIndex = 0;

            if (this.EnsureOpen() == Pop3ConnectionState.Connected)
            {
                //ユーザー名送信
                rs = this.Execute("user " + this.UserName, false);
                if (rs.Ok == true)
                {
                    if (rs.Text.IndexOf("<") > -1 &&
                        rs.Text.IndexOf(">") > -1)
                    {
                        StartIndex = rs.Text.IndexOf("<");
                        EndIndex = rs.Text.IndexOf(">");
                        TimeStamp = rs.Text.Substring(StartIndex, EndIndex - StartIndex + 1);
                        //パスワード送信
                        rs = this.Execute("pass " + Cryptography.ToMd5DigestString(TimeStamp + this.Password), false);
                        if (rs.Ok == true)
                        {
                            this._State = Pop3ConnectionState.Authenticated;
                        }
                    }
                }
            }
            return this._State == Pop3ConnectionState.Authenticated;
        }
Ejemplo n.º 13
0
 /// メールサーバーとの接続を切断します。
 /// <summary>
 /// disconnect connection to pop3 server.
 /// メールサーバーとの接続を切断します。
 /// </summary>
 public override void Close()
 {
     base.Close();
     this._State = Pop3ConnectionState.Disconnected;
 }
Ejemplo n.º 14
0
 /// メールサーバーとの接続を切断します。
 /// <summary>
 /// disconnect connection to pop3 server.
 /// メールサーバーとの接続を切断します。
 /// </summary>
 public void Close()
 {
     this.Socket.Close();
     this._State = Pop3ConnectionState.Disconnected;
 }