Example #1
0
        protected virtual Pop3Response DoCommand(IPOP3Command command)
        {
            Pop3Response response;

            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            try
            {
                response = command.Interact(this._connection);
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
                if (exception is IOException)
                {
                    if (Login().Type == EPop3ResponseType.OK)
                    {
                        return(DoCommand(command));
                    }
                }
                throw;
            }
            return(response);
        }
Example #2
0
        public virtual Pop3Response Login()
        {
            Pop3Client client7;

            this._connection = this._connectionFactory.GetConnection(this._configurationProvider);
            lock (this)
            {
                if (this.State != EPop3ClientState.Awaiting)
                {
                    throw new InvalidOperationException("Pop3Client doesn't allow executing multiple operations simulteneously in a few threads using one object");
                }
                this.State = EPop3ClientState.Busy;
            }
            if (this.ConnectionState == EPop3ConnectionState.Connected)
            {
                lock (this)
                {
                    this.State = EPop3ClientState.Awaiting;
                }
                return(new Pop3Response("+OK"));
            }
            try
            {
                this._connection.Open();
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
                throw;
            }
            if (this._connection.State == EConnectionState.Connected)
            {
                this.ConnectionState = EPop3ConnectionState.Connected;
                if (this.Connected != null)
                {
                    this.Connected(this);
                }
            }
            Pop3Response response = new Pop3Response(this._connection.ReceiveLine());

            if (response.Type != EPop3ResponseType.OK)
            {
                goto Label_03F9;
            }
            CAPA         capa      = new CAPA();
            Pop3Response response2 = this.DoCommand(capa);

            if (this._configurationProvider.SSLInteractionType == EInteractionType.StartTLS)
            {
                Pop3Response response3 = this.DoCommand(new STLS());
                if (response3.Type != EPop3ResponseType.OK)
                {
                    return(response3);
                }
            }
            IPOP3Command command = null;

            if ((this.AuthenticationType == EAuthenticationType.Auto) && ((response2.Type == EPop3ResponseType.ERR) || !capa.Commands.ContainsKey("SASL")))
            {
                command = new AuthStandart(this.Username, this.Password);
            }
            else
            {
                string str2 = string.Empty;
                switch (this.AuthenticationType)
                {
                case EAuthenticationType.Auto:
                {
                    bool flag = false;
                    if (str2.Contains("PLAIN"))
                    {
                        command = new AuthPlain(this.Username, this.Password);
                        flag    = true;
                    }
                    if (str2.Contains("LOGIN"))
                    {
                        command = new AuthStandart(this.Username, this.Password);
                        flag    = true;
                    }
                    if (!flag)
                    {
                        command = new AuthStandart(this.Username, this.Password);
                    }
                    goto Label_03C9;
                }

                case EAuthenticationType.Plain:
                    if (!str2.Contains("PLAIN"))
                    {
                        lock (this)
                        {
                            this.State = EPop3ClientState.Awaiting;
                        }
                        throw new AuthenticationMethodNotSupportedException("Selected authentication method is not supported by the server");
                    }
                    command = new AuthPlain(this.Username, this.Password);
                    goto Label_03C9;

                case EAuthenticationType.Login:
                    if (!str2.Contains("LOGIN"))
                    {
                        lock (this)
                        {
                            this.State = EPop3ClientState.Awaiting;
                        }
                        throw new AuthenticationMethodNotSupportedException("Selected authentication method is not supported by the server");
                    }
                    command = new AuthLogin(this.Username, this.Password);
                    goto Label_03C9;
                }
            }
Label_03C9:
            if (command != null)
            {
                response = this.DoCommand(command);
            }
            if (response.Type == EPop3ResponseType.OK)
            {
                this.ConnectionState = EPop3ConnectionState.Authenticated;
                if (this.Authenticated != null)
                {
                    this.Authenticated(this);
                }
            }
Label_03F9:
            Monitor.Enter(client7 = this);
            try
            {
                this.State = EPop3ClientState.Awaiting;
            }
            finally
            {
                Monitor.Exit(client7);
            }
            return(response);
        }