public bool IssueCommand(RFC1939.POPCommand command)
 {
     try
     {
         if (m_CurrentState.IssueCommand(command, this))
         {
             OnCommandIssued(this,
                             new CommandIssuedEventArgs(command));
             return(true);
         }
     }
     catch (RFC1939.POPException ex)
     {
         if (ex.InnerException != null)
         {
             if (ex.InnerException.InnerException != null)
             {
                 if (ex.InnerException.InnerException is System.Net.Sockets.SocketException)
                 {
                     CloseConnection();
                     CurrentState = DisconnectedState.GetInstane();
                     return(false);
                 }
             }
         }
         throw ex;
     }
     return(false);
 }
 public static DisconnectedState GetInstane()
 {
     if (s_State == null)
     {
         s_State = new DisconnectedState();
     }
     return(s_State);
 }
        public POPClient(IMailReader mailreader)
        {
            m_CurrentState   = DisconnectedState.GetInstane();
            m_TcpClient      = new TcpClient();
            m_CommandHistory = new Queue <jingxian.mail.popper.RFC1939.POPCommand>();
            m_PollTimer      = new System.Timers.Timer();
            m_MailReader     = mailreader;

            mailreader.DataRead += new DataReadEventHandler(OnDataRead);
            m_PollTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_PollTimer_Elapsed);
        }
Exemple #4
0
        /// <summary>
        /// 执行命令,如果命令是与登录相关则不执行
        /// </summary>
        /// <returns>如果返回true,则说明命令执行成功</returns>
        public override bool IssueCommand(RFC1939.POPCommand command, POPClient context)
        {
            if (!IsLegalCommand(command))
            {
                return(false);
            }

            if (command is RFC1939.QuitCommand)
            {
                if (command.Execute())
                {
                    context.LoggCommand(command);
                    context.CurrentState = DisconnectedState.GetInstane();
                    return(true);
                }
                context.CurrentState = DisconnectedState.GetInstane();
                context.LoggCommand(command);
            }
            else if (command is RFC1939.RetriveCommand || command is RFC1939.TopCommand)
            {
                if (command.Execute())
                {
                    context.LoggCommand(command);
                    context.CurrentState = ReadingState.GetInstance();
                    return(true);
                }
                context.LoggCommand(command);
            }
            else if (command is RFC1939.NoopCommand)
            {
                if (command.Execute())
                {
                    context.LoggCommand(command);
                    return(true);
                }
                else
                {
                    context.LoggCommand(command);
                    context.Disconnect();
                    context.CurrentState = DisconnectedState.GetInstane();
                }
            }
            else
            {
                if (command.Execute())
                {
                    context.LoggCommand(command);
                    return(true);
                }
                context.LoggCommand(command);
            }
            return(false);
        }
Exemple #5
0
        public override bool IssueCommand(RFC1939.POPCommand command, POPClient context)
        {
            if (!IsLegalCommand(command))
            {
                return(false);
            }

            if (command is RFC1939.ConnectCommand)
            {
                if (command.Execute())
                {
                    context.LoggCommand(command);
                    context.CurrentState = TransactionState.GetInstance();
                    return(true);
                }
                context.LoggCommand(command);
            }
            else if (command is RFC1939.UserCommand)
            {
                if (command.Execute())
                {
                    context.LoggCommand(command);
                    return(true);
                }
                context.LoggCommand(command);
            }
            else if (command is RFC1939.PassCommand)
            {
                if (command.Execute())
                {
                    context.LoggCommand(command);
                    context.CurrentState = TransactionState.GetInstance();
                    return(true);
                }
                context.LoggCommand(command);
            }
            else if (command is RFC1939.QuitCommand)
            {
                if (command.Execute())
                {
                    context.LoggCommand(command);
                    context.CurrentState = DisconnectedState.GetInstane();
                    return(true);
                }
                context.LoggCommand(command);
            }

            return(false);
        }