Ejemplo n.º 1
0
 protected virtual bool _TryReset(out Pop3Response responce)
 {
     responce = this.DoCommand(new RSET());
     if (responce.Type == EPop3ResponseType.ERR)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Logs out of the mail account.
 /// </summary>
 /// <param name="response">The response.</param>
 /// <returns>The response type.</returns>
 protected override CommandResponseType LogoutCommand(out string response)
 {
     try
     {
         Pop3Response logoutResponse = _client.Logout();
         response = logoutResponse.Message;
         return(GetCommandResponseType(logoutResponse.Type));
     }
     catch (Exception ex)
     {
         response = ex.ToString();
         return(CommandResponseType.Bad);
     }
 }
Ejemplo n.º 3
0
        private bool _TryGetStatistic(out Pop3MessageStatistics statistic, out string errorMessage)
        {
            STAT         command  = new STAT();
            Pop3Response response = this.DoCommand(command);

            errorMessage = "";
            statistic    = command.Statistics;
            if (response.Type == EPop3ResponseType.ERR)
            {
                errorMessage = response.Message;
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Deletes the specified message.
        /// </summary>
        /// <param name="mailbox">The mailbox to delete from.</param>
        /// <param name="messagePaths">The message paths to delete.</param>
        /// <param name="response">The response.</param>
        /// <returns>The response type.</returns>
        protected override CommandResponseType DeleteMessageCommand(Mailbox mailbox, Dictionary <string, string> messagePaths, out string response)
        {
            response = string.Empty;
            Pop3Response pop3Response = null;

            // Find the messages to delete
            foreach (StatisticInfo statistic in _statistics.Where(o => messagePaths.ContainsKey(o.UniqueNumber)))
            {
                // Delete the message
                pop3Response = _client.DeleteMessage(statistic.SerialNumber);
                response     = pop3Response.Message;
            }

            return(pop3Response == null ? CommandResponseType.Ok : GetCommandResponseType(pop3Response.Type));
        }
Ejemplo n.º 5
0
        protected virtual bool _TryGetUIDMessage(uint serialNumber, out Pop3MessageUIDInfo messageUIDInfo, out string errorMessage)
        {
            UIDL         command  = new UIDL(serialNumber);
            Pop3Response response = this.DoCommand(command);

            errorMessage = "";
            if (command.Messages.Count > 0)
            {
                messageUIDInfo = command.Messages[0];
                return(true);
            }
            messageUIDInfo = null;
            errorMessage   = response.Message;
            return(false);
        }
Ejemplo n.º 6
0
        protected virtual bool _TryGetAllUIDMessages(out Pop3MessageUIDInfoCollection messageUIDInfo, out string errorMessage)
        {
            UIDL         command  = new UIDL();
            Pop3Response response = this.DoCommand(command);

            errorMessage = "";
            if (response.Type == EPop3ResponseType.OK)
            {
                messageUIDInfo = command.Messages;
                return(true);
            }
            messageUIDInfo = null;
            errorMessage   = response.Message;
            return(false);
        }
Ejemplo n.º 7
0
        protected virtual bool _TryGetMessagesInfo(out Pop3MessageInfoCollection infoCollection, out string errorMessage)
        {
            infoCollection = new Pop3MessageInfoCollection();
            errorMessage   = "";
            LIST         command  = new LIST();
            Pop3Response response = this.DoCommand(command);

            if (response.Type == EPop3ResponseType.OK)
            {
                infoCollection = command.Messages;
            }
            else
            {
                errorMessage = response.Message;
            }
            return(true);
        }
Ejemplo n.º 8
0
        protected virtual bool _TryGetMessageInfo(uint number, out Pop3MessageInfo messageInfo, out string errorMessage)
        {
            errorMessage = "";
            LIST         command  = new LIST(number);
            Pop3Response response = this.DoCommand(command);

            if (command.Messages.Count > 0)
            {
                messageInfo = command.Messages[0];
            }
            else
            {
                errorMessage = response.Message;
                messageInfo  = null;
            }
            return(response.Type == EPop3ResponseType.OK);
        }
Ejemplo n.º 9
0
        protected virtual bool _TryDeleteMessage(uint serialNumber, out Pop3Response responce)
        {
            DELE         command  = new DELE(serialNumber);
            Pop3Response response = this.DoCommand(command);

            if (response.Type == EPop3ResponseType.OK)
            {
                if (this.MessageDeleted != null)
                {
                    this.MessageDeleted(this, serialNumber);
                }
                responce = new Pop3Response();
                return(true);
            }
            responce = new Pop3Response(response.Message);
            return(false);
        }
Ejemplo n.º 10
0
        public virtual bool TryDeleteMessage(uint serialNumber, out Pop3Response responce)
        {
            lock (this)
            {
                if (this.State != EPop3ClientState.Awaiting)
                {
                    responce = new Pop3Response("Pop3Client doesn't allow executing multiple operations simulteneously in a few threads using one object");
                    return(false);
                }
                this.State = EPop3ClientState.Busy;
            }
            if (this.ConnectionState != EPop3ConnectionState.Authenticated)
            {
                responce   = new Pop3Response("The command cannot be executed in this state");
                this.State = EPop3ClientState.Awaiting;
                return(false);
            }
            bool flag = this._TryDeleteMessage(serialNumber, out responce);

            this.State = EPop3ClientState.Awaiting;
            return(flag);
        }
Ejemplo n.º 11
0
        public virtual Pop3Response Logout()
        {
            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;
            }
            Pop3Response response = new Pop3Response("+OK");

            if (this.ConnectionState != EPop3ConnectionState.Disconnected)
            {
                QUIT command = new QUIT();
                response = this.DoCommand(command);
                if (this.Quit != null)
                {
                    this.Quit(this);
                }
                this.ConnectionState = EPop3ConnectionState.Disconnected;
                if (Disconnected != null)
                {
                    Disconnected(this);
                }
                try
                {
                    this._connection.Close();
                }
                catch (Exception exception)
                {
                    this.HandleException(exception);
                    throw;
                }
            }
            this.State = EPop3ClientState.Awaiting;
            return(response);
        }
Ejemplo n.º 12
0
        protected virtual bool _TryGetMessage(uint number, string uid, out PopMessage message, out string errorMessage)
        {
            RETR         command  = new RETR(number, uid, this._configurationProvider.AttachmentDirectory);
            Pop3Response response = this.DoCommand(command);

            if (response.Type == EPop3ResponseType.OK)
            {
                if (this.MessageReceived != null)
                {
                    this.MessageReceived(this, command.Message);
                }
                errorMessage = "";
                message      = command.Message;
                return(true);
            }
            if (this.BrokenMessage != null)
            {
                this.BrokenMessage(this, new Pop3MessageInfo(number, 0), response.Message, command.Message);
            }
            errorMessage = response.Message;
            message      = command.Message;
            return(false);
        }
Ejemplo n.º 13
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);
        }