Exemplo n.º 1
0
 internal void MultiLineResponseCallback(IAsyncResult asyncResult)
 {
     DataCommunicator.State state = (DataCommunicator.State)asyncResult.AsyncState;
     try
     {
         int num = state.DataStream.EndRead(asyncResult);
         if (num > 0)
         {
             state.AppendReceivedData(num);
             if (!PopClient.IsOkResponse(state.Response))
             {
                 if (!state.Response.EndsWith("\r\n", StringComparison.Ordinal))
                 {
                     state.ReadDataCallback = new AsyncCallback(base.SingleLineResponseCallback);
                     state.BeginRead();
                     return;
                 }
             }
             else
             {
                 bool flag = false;
                 if (!state.Response.EndsWith("\r\n.\r\n", StringComparison.Ordinal))
                 {
                     flag = true;
                 }
                 if (flag)
                 {
                     state.BeginRead();
                     return;
                 }
             }
         }
     }
     catch (InvalidOperationException exception)
     {
         if (base.Communicator.HasTimedOut)
         {
             base.Communicator.HandleException(DataCommunicator.CreateTimeoutException());
             return;
         }
         base.Communicator.HandleException(exception);
     }
     catch (IOException exception2)
     {
         base.Communicator.HandleException(exception2);
         return;
     }
     base.Communicator.StopTimer();
     state.LaunchResponseDelegate();
 }
Exemplo n.º 2
0
        private void GetTheResponse(string response, object extraData)
        {
            switch (this.currentState)
            {
            case PopTransaction.State.SettingUpSecureStreamForTls:
            case PopTransaction.State.GettingMessageData:
            case PopTransaction.State.DeletingOlderMessages:
            case PopTransaction.State.LoggingOff:
            case PopTransaction.State.Disconnecting:
                break;

            default:
                if (!PopClient.IsOkResponse(response))
                {
                    this.ReportErrorAndQuit(response);
                    return;
                }
                break;
            }
            switch (this.currentState)
            {
            case PopTransaction.State.Disconnected:
            case PopTransaction.State.Disconnecting:
                return;

            case PopTransaction.State.Connecting:
                if (base.ConnectionType == ProtocolConnectionType.Tls)
                {
                    this.currentState = PopTransaction.State.NegotiatingTls;
                    this.popClient.Stls(new DataCommunicator.GetCommandResponseDelegate(this.GetTheResponse));
                    return;
                }
                break;

            case PopTransaction.State.Connected:
            case PopTransaction.State.SettingUpSecureStreamForTls:
                break;

            case PopTransaction.State.NegotiatingTls:
                this.currentState = PopTransaction.State.SettingUpSecureStreamForTls;
                this.popClient.SetUpSecureStreamForTls(new DataCommunicator.GetCommandResponseDelegate(this.GetTheResponse));
                return;

            case PopTransaction.State.ReadyToLogIn:
                if (base.LightMode)
                {
                    this.ReportSuccessAndLogOff();
                    return;
                }
                base.Verbose(Strings.PopImapLoggingOn);
                this.currentState = PopTransaction.State.SendingUserCommand;
                if (!string.IsNullOrEmpty(base.User.UserPrincipalName))
                {
                    this.popClient.UserCommand(new DataCommunicator.GetCommandResponseDelegate(this.GetTheResponse), base.User.UserPrincipalName);
                    return;
                }
                this.popClient.UserCommand(new DataCommunicator.GetCommandResponseDelegate(this.GetTheResponse), base.User.SamAccountName);
                return;

            case PopTransaction.State.SendingUserCommand:
                this.currentState = PopTransaction.State.SendingPassCommand;
                this.popClient.PassCommand(new DataCommunicator.GetCommandResponseDelegate(this.GetTheResponse), base.Password);
                return;

            case PopTransaction.State.SendingPassCommand:
                this.popClient.HasLoggedIn = true;
                this.currentState          = PopTransaction.State.GettingMessageIds;
                base.Verbose(Strings.PopGettingMessageIDs);
                this.popClient.List(new DataCommunicator.GetCommandResponseDelegate(this.GetTheResponse));
                return;

            case PopTransaction.State.GettingMessageIds:
                this.messageIdQueue = PopTransaction.PutIDsInQueue(response);
                if (this.messageIdQueue.Count == 0)
                {
                    throw new ArgumentOutOfRangeException("this.messageIDQueue", Strings.PopImapNoMessagesToDelete);
                }
                this.messagesToDelete.Clear();
                this.currentState = PopTransaction.State.GettingMessageData;
                this.popClient.GetMessage(new DataCommunicator.GetCommandResponseDelegate(this.GetTheResponse), this.messageIdQueue.Peek());
                return;

            case PopTransaction.State.GettingMessageData:
            {
                string item = this.messageIdQueue.Dequeue();
                if (PopClient.IsOkResponse(response))
                {
                    bool   flag = false;
                    string text = ProtocolClient.GetSubjectOfMessage(response).Trim();
                    if (string.IsNullOrEmpty(this.testMessageID) && base.MailSubject.Equals(text, StringComparison.OrdinalIgnoreCase))
                    {
                        flag = true;
                        this.testMessageID = item;
                    }
                    if (!flag && text.StartsWith("Test-POPConnectivity-", StringComparison.OrdinalIgnoreCase))
                    {
                        ExDateTime dt = ExDateTime.Parse(ProtocolClient.GetDateOfMessage(response), CultureInfo.InvariantCulture);
                        if ((ExDateTime.Now - dt).Days >= 1)
                        {
                            this.messagesToDelete.Enqueue(item);
                        }
                    }
                }
                if (this.messageIdQueue.Count > 0)
                {
                    this.popClient.GetMessage(new DataCommunicator.GetCommandResponseDelegate(this.GetTheResponse), this.messageIdQueue.Peek());
                    return;
                }
                this.currentState = PopTransaction.State.DeletingTestMessage;
                this.DeleteTestMessage();
                return;
            }

            case PopTransaction.State.DeletingTestMessage:
                base.Verbose(Strings.PopImapDeleteOldMsgs);
                if (this.messagesToDelete.Count == 0)
                {
                    base.Verbose(Strings.PopImapNoMessagesToDelete);
                    this.ReportSuccessAndLogOff();
                    return;
                }
                this.currentState = PopTransaction.State.DeletingOlderMessages;
                this.popClient.DeleteMessage(new DataCommunicator.GetCommandResponseDelegate(this.GetTheResponse), this.messagesToDelete.Dequeue());
                return;

            case PopTransaction.State.DeletingOlderMessages:
                if (this.messagesToDelete.Count > 0)
                {
                    this.popClient.DeleteMessage(new DataCommunicator.GetCommandResponseDelegate(this.GetTheResponse), this.messagesToDelete.Dequeue());
                    return;
                }
                this.ReportSuccessAndLogOff();
                return;

            case PopTransaction.State.LoggingOff:
                this.popClient.HasLoggedIn = false;
                this.currentState          = PopTransaction.State.Disconnecting;
                this.Disconnect();
                return;

            default:
                throw new ArgumentOutOfRangeException(Strings.PopImapErrorUnexpectedValue(this.currentState.ToString()));
            }
            this.currentState = PopTransaction.State.ReadyToLogIn;
            this.popClient.Capa(new DataCommunicator.GetCommandResponseDelegate(this.GetTheResponse));
        }