Beispiel #1
0
        public override Pop3Response Interact(IConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            connection.SendLine(this.CommandText);
            Pop3Response response = new Pop3Response(connection.ReceiveLine());

            if (response.Type == EPop3ResponseType.OK)
            {
                string str;
                while ((str = connection.ReceiveLine()) != ".")
                {
                    Match match = this.regCommand.Match(str);
                    if (match.Groups.Count > 2)
                    {
                        this.Commands.Add(match.Groups[1].Value, match.Groups[2].Value);
                    }
                    else if (match.Groups.Count > 1)
                    {
                        this.Commands.Add(match.Groups[1].Value, "");
                    }
                }
            }
            return(response);
        }
Beispiel #2
0
        public override Pop3Response Interact(IConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            connection.SendLine(this.CommandText);
            string       message  = connection.ReceiveLine();
            Pop3Response response = new Pop3Response(message);

            if (response.Type != EPop3ResponseType.ERR)
            {
                Pop3MessageUIDInfo oneMessage;
                if (!this._selectOneMessage)
                {
                    message = connection.ReceiveLine();
                    while (message != ".")
                    {
                        oneMessage = this.GetOneMessage(message);
                        if (oneMessage != null)
                        {
                            this.Messages.Add(oneMessage);
                        }
                        message = connection.ReceiveLine();
                    }
                    return(response);
                }
                oneMessage = this.GetOneMessage(message);
                if (oneMessage != null)
                {
                    this.Messages.Add(oneMessage);
                }
            }
            return(new Pop3Response(message));
        }
Beispiel #3
0
        public override Pop3Response Interact(IConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            connection.SendLine(this.CommandText);
            Pop3Response response = new Pop3Response(connection.ReceiveLine());

            this.Statistics = new Pop3MessageStatistics();
            if (response.Type == EPop3ResponseType.ERR)
            {
                throw new Pop3ReceiveException(string.Format("Request error {0}:{1}", this.CommandText, response.Message));
            }
            uint            result = 0;
            uint            num2   = 0;
            MatchCollection matchs = Pop3Command.regUInt.Matches(response.Message);

            if (matchs.Count == 2)
            {
                uint.TryParse(matchs[0].Value, out result);
                uint.TryParse(matchs[1].Value, out num2);
            }
            this.Statistics = new Pop3MessageStatistics(result, num2);
            return(response);
        }
        /// <summary>
        /// Creates the response.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <returns>
        /// The <c>Pop3Response</c> containing the results of the
        /// Pop3 command execution.
        /// </returns>
        protected override RetrieveResponse CreateResponse(byte[] buffer)
        {
            Pop3Response response = Pop3Response.CreateResponse(buffer);

            MemoryStream responseStream = StripPop3HostMessage(buffer, response.HostMessage, ".");

            return(new RetrieveResponse(response, responseStream.ToArray()));
        }
Beispiel #5
0
        public override Pop3Response Interact(IConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            Pop3Response response = this._user.Interact(connection);

            if (response.Type == EPop3ResponseType.OK)
            {
                response = this._pass.Interact(connection);
            }
            return(response);
        }
Beispiel #6
0
        public virtual Pop3Response Interact(IConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            connection.SendLine(this.CommandText);
            Pop3Response response = new Pop3Response(connection.ReceiveLine());

            if (response.Type == EPop3ResponseType.ERR)
            {
                throw new Pop3ReceiveException(string.Format("Request error {0}:{1}", this.CommandText, response.Message));
            }
            return(response);
        }
Beispiel #7
0
        public override Pop3Response Interact(IConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            connection.SendLine(this.CommandText);
            Pop3Response response = new Pop3Response(connection.ReceiveLine());

            if (response.Type == EPop3ResponseType.OK)
            {
                connection.SwitchToSslChannel();
            }
            return(response);
        }
Beispiel #8
0
        /// <summary>
        /// Creates the response.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <returns>
        /// The <c>Pop3Response</c> containing the results of the
        /// Pop3 command execution.
        /// </returns>
        protected override StatResponse CreateResponse(byte[] buffer)
        {
            Pop3Response response = Pop3Response.CreateResponse(buffer);

            string[] values = response.HostMessage.Split(' ');

            //should consist of '+OK', 'messagecount', 'octets'
            if (values.Length < 3)
            {
                throw new Pop3Exception(string.Concat("Invalid response message: ", response.HostMessage));
            }

            int  messageCount = Convert.ToInt32(values[1]);
            long octets       = Convert.ToInt64(values[2]);

            return(new StatResponse(response, messageCount, octets));
        }
Beispiel #9
0
        public override Pop3Response Interact(IConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            connection.SendLine(this.CommandText);
            string message = connection.ReceiveLine();

            if (message == ".")
            {
                message = connection.ReceiveLine();
            }
            Pop3Response response = new Pop3Response(message);

            if (response.Type == EPop3ResponseType.OK)
            {
                message = "";
                while ((message.Length == 0) || !message.EndsWith("\r\n\r\n"))
                {
                    string str2 = connection.ReceiveLine();
                    message = message + str2 + "\r\n";
                }
                this.MessageHeaders = message.Remove(message.Length - ("\r\n".Length * 2), "\r\n".Length * 2);
                if (this.messageRowCount != 0)
                {
                    message = "";
                }
                while ((message.Length == 0) || !message.EndsWith("\r\n\r\n\r\n.\r\n"))
                {
                    string str3 = connection.ReceiveLine();
                    message = message + str3 + "\r\n";
                }
                message = message.Remove((message.Length - ("\r\n".Length * 4)) - 1, ("\r\n".Length * 4) + 1);
                if (this.messageRowCount != 0)
                {
                    this.MessageBody = message;
                }
                return(response);
            }
            if ((response.Type == EPop3ResponseType.ERR) && (string.Compare("no such message", response.Message, StringComparison.CurrentCultureIgnoreCase) != 0))
            {
                throw new Pop3ReceiveException("Incorrect server response");
            }
            return(response);
        }
Beispiel #10
0
        public override Pop3Response Interact(IConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            STAT stat = new STAT();

            stat.Interact(connection);
            connection.SendLine(this.CommandText);
            string str = connection.ReceiveLine();

            if (this.selectOneMessage)
            {
                Pop3MessageInfo oneMessage = this.GetOneMessage(str);
                if (oneMessage != null)
                {
                    this.Messages.Add(oneMessage);
                }
            }
            else
            {
                Pop3Response response = new Pop3Response(str);
                if (response.Type == EPop3ResponseType.OK)
                {
                    MatchCollection matchs = Pop3Command.regUInt.Matches(response.Message);
                    if (stat.MessagesCount > 0)
                    {
                        for (int i = 0; i < stat.MessagesCount; i++)
                        {
                            str = connection.ReceiveLine();
                            Pop3MessageInfo item = this.GetOneMessage(str);
                            if (item != null)
                            {
                                this.Messages.Add(item);
                            }
                        }
                        connection.ReceiveLine();
                        return(response);
                    }
                    return(response);
                }
            }
            return(new Pop3Response(str));
        }
        /// <summary>
        /// Ensures the response.
        /// </summary>
        /// <param name="response">The response.</param>
        /// <param name="error">The error.</param>
        private static void EnsureResponse(Pop3Response response, string error)
        {
            if (response == null)
            {
                throw new Pop3Exception("Unable to get Response.  Response object null.");
            }

            if (response.StatusIndicator)
            {
                return;
            } //the command execution was successful.

            string errorMessage = string.IsNullOrEmpty(error) ? response.HostMessage : string.Concat(error, ": ", error);

            string responseContent = Encoding.ASCII.GetString(response.ResponseContents);

            throw new Pop3Exception(errorMessage + "\r\n\t" + responseContent.Replace("\n", "\n\t"));
        }
Beispiel #12
0
        /// <summary>
        /// Creates the response.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <returns>A <c>ListResponse</c> containing the results of the Pop3 LIST command.</returns>
        protected override ListResponse CreateResponse(byte[] buffer)
        {
            Pop3Response response = Pop3Response.CreateResponse(buffer);

            List <Pop3ListItemResult> items;

            if (IsMultiline)
            {
                items = new List <Pop3ListItemResult>();
                string[] values;
                string[] lines = GetResponseLines(StripPop3HostMessage(buffer, response.HostMessage));

                foreach (string line in lines)
                {
                    //each line should consist of 'n m' where n is the message number and m is the number of octets
                    values = line.Split(' ');
                    if (values.Length < 2)
                    {
                        throw new Pop3Exception(string.Concat("Invalid line in multiline response:  ", line));
                    }

                    items.Add(new Pop3ListItemResult(Convert.ToInt32(values[0]),
                                                     Convert.ToInt64(values[1])));
                }
            }             //Parse the multiline response.
            else
            {
                items = new List <Pop3ListItemResult>(1);
                string[] values = response.HostMessage.Split(' ');

                //should consist of '+OK messageNumber octets'
                if (values.Length < 3)
                {
                    throw new Pop3Exception(string.Concat("Invalid response message: ", response.HostMessage));
                }
                items.Add(new Pop3ListItemResult(Convert.ToInt32(values[1]), Convert.ToInt64(values[2])));
            }             //Parse the single line results.

            return(new ListResponse(response, items));
        }
Beispiel #13
0
        public override Pop3Response Interact(IConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            connection.SendLine(this.CommandText);
            byte[]       bytes    = connection.ReceiveBytes();
            Pop3Response response = new Pop3Response(Encoding.UTF8.GetString(bytes, 0, bytes.Length));

            if (response.Type == EPop3ResponseType.OK)
            {
                Pop3MessageStreamReader reader = new Pop3MessageStreamReader(connection);
                this.Message = new MailMessageParser().Parse(reader, uid, this.AttachmentDirectory);
                return(response);
            }
            if ((response.Type == EPop3ResponseType.ERR) && (string.Compare("no such message", response.Message, StringComparison.CurrentCultureIgnoreCase) != 0))
            {
                throw new Pop3ReceiveException("Incorrect server response");
            }
            return(response);
        }
Beispiel #14
0
        private SortedList <string, Rfc822Message> getSmtpMessages()
        {
            Pop3Client target = new Pop3Client();

            target.Host = Host;
            //TCP port for connection
            target.Port = Convert.ToUInt16(Port);
            //Username to login to the POP3 server
            target.Username = Username;
            //Password to login to the POP3 server
            target.Password = Password;
            // SSL Interaction type
            Email.Net.Common.Configurations.EInteractionType interaction = default(Email.Net.Common.Configurations.EInteractionType);
            if (TSL)
            {
                interaction = EInteractionType.StartTLS;
            }
            else if (SSL)
            {
                interaction = EInteractionType.SSLPort;
            }
            else
            {
                interaction = EInteractionType.Plain;
            }
            target.SSLInteractionType = EInteractionType.SSLPort;
            target.AuthenticationType = EAuthenticationType.Login;
            if (authenticationType == (int)EAuthenticationType.None)
            {
                Password = "";
                Username = "";
            }

            System.Collections.Generic.SortedList <string, Rfc822Message> messages = new System.Collections.Generic.SortedList <string, Rfc822Message>();
            Rfc822Message msg = null;

            // Login to POP server
            try {
                Pop3Response response = target.Login();
                if (response.Type == EPop3ResponseType.OK)
                {
                    // Retrieve Unique IDs for all messages
                    Pop3MessageUIDInfoCollection messageUIDs = target.GetAllUIDMessages();
                    //Check if messages already received
                    foreach (Pop3MessageUIDInfo uidInfo in messageUIDs)
                    {
                        try {
                            msg = target.GetMessage(uidInfo.SerialNumber);
                        } catch (Email.Net.Common.Exceptions.ConnectionException ex) {
                        } catch (Email.Net.Common.Exceptions.AuthenticationMethodNotSupportedException ex) {
                        } catch (System.Exception ex) {
                        }
                        if ((msg != null))
                        {
                            if (!string.IsNullOrEmpty(UtilFunctions.findIssueTag(msg).Trim()))
                            {
                                if (!UtilFunctions.searchUID(uidInfo.UniqueNumber))
                                {
                                    // No.  Add to list
                                    messages.Add(uidInfo.UniqueNumber, target.GetMessage(uidInfo.SerialNumber));
                                }
                            }
                        }
                        if (!runFlag | !isEnabled)
                        {
                            break;                             // TODO: might not be correct. Was : Exit For
                        }
                    }
                    string cnt = (messages.Count.ToString());
                    cnt += " SMTP messages were found";
                    GlobalShared.Log.Log((int)LogClass.logType.Info, cnt, false);
                }
                //Logout from the server
                target.Logout();
            } catch (IOException ex) {
                GlobalShared.Log.Log((int)LogClass.logType.ErrorCondition, ex.Message, false);
            } catch (Email.Net.Common.Exceptions.ConnectionException ex) {
                GlobalShared.Log.Log((int)LogClass.logType.ErrorCondition, ex.Message, false);
            } catch (System.Exception ex) {
                GlobalShared.Log.Log((int)LogClass.logType.ErrorCondition, ex.Message, false);
            }
            return(messages);
        }
Beispiel #15
0
        /// <summary>
        /// Creates the response.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <returns>
        /// The <c>Pop3Response</c> containing the results of the
        /// Pop3 command execution.
        /// </returns>
        protected override ConnectResponse CreateResponse(byte[] buffer)
        {
            Pop3Response response = Pop3Response.CreateResponse(buffer);

            return(new ConnectResponse(response, NetworkStream));
        }
Beispiel #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StatResponse"/> class.
 /// </summary>
 /// <param name="response">The response.</param>
 /// <param name="messageCount">The message count.</param>
 /// <param name="octets">The octets.</param>
 public StatResponse(Pop3Response response, int messageCount, long octets)
     : base(response.ResponseContents, response.HostMessage, response.StatusIndicator)
 {
     _messageCount = messageCount;
     _octets       = octets;
 }
 /// <summary>
 /// Ensures the response.
 /// </summary>
 /// <param name="response">The response.</param>
 private static void EnsureResponse(Pop3Response response)
 {
     EnsureResponse(response, string.Empty);
 }
Beispiel #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StatResponse"/> class.
 /// </summary>
 /// <param name="response">The response.</param>
 /// <param name="messageCount">The message count.</param>
 /// <param name="octets">The octets.</param>
 public StatResponse(Pop3Response response, int messageCount, long octets)
     : base(response.ResponseContents, response.HostMessage, response.StatusIndicator)
 {
     _messageCount = messageCount;
     _octets = octets;
 }
Beispiel #19
0
 /// <summary>
 /// Creates the response.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 /// <returns>The <c>Pop3Response</c> containing the results of the
 /// Pop3 command execution.</returns>
 protected virtual T CreateResponse(byte[] buffer)
 {
     return(Pop3Response.CreateResponse(buffer) as T);
 }