Ejemplo n.º 1
0
        /// <summary>
        /// Ensures the response.
        /// </summary>
        /// <param name="response">The response.</param>
        /// <param name="error">The error.</param>
        private 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.Empty;

            if (string.IsNullOrEmpty(error))
            {
                errorMessage = response.HostMessage;
            }
            else
            {
                errorMessage = string.Concat(error, ": ", error);
            }

            throw new Pop3Exception(errorMessage);
        }
Ejemplo n.º 2
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 RetrResponse CreateResponse(byte[] buffer)
        {
            Pop3Response response = Pop3Response.CreateResponse(buffer);

            string[] messageLines = GetResponseLines(StripPop3HostMessage(buffer, response.HostMessage));

            return(new RetrResponse(response, messageLines));
        }
Ejemplo n.º 3
0
 public ConnectResponse(Pop3Response response, Stream networkStream)
     : base(response.ResponseContents, response.HostMessage, response.StatusIndicator)
 {
     if (networkStream == null)
     {
         throw new ArgumentNullException("networkStream");
     }
     _networkStream = networkStream;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ListResponse"/> class.
        /// </summary>
        /// <param name="response">The response.</param>
        /// <param name="items">The items.</param>
        public ListResponse(Pop3Response response, List <Pop3ListItem> items)
            : base(response.ResponseContents, response.HostMessage, response.StatusIndicator)
        {
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }

            _items = items;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RetrResponse"/> class.
        /// </summary>
        /// <param name="response">The response.</param>
        /// <param name="messageLines">The message lines.</param>
        public RetrResponse(Pop3Response response, string[] messageLines)
            : base(response.ResponseContents, response.HostMessage, response.StatusIndicator)
        {
            if (messageLines == null)
            {
                throw new ArgumentNullException("messageLines");
            }
            string[] values = response.HostMessage.Split(' ');
            if (values.Length == 2)
            {
                _octects = Convert.ToInt64(values[1]);
            }

            _messageLines = messageLines;
        }
Ejemplo n.º 6
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 <Pop3ListItem> items;

            if (IsMultiline)
            {
                items = new List <Pop3ListItem>();
                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 Pop3ListItem(Convert.ToInt32(values[0]),
                                               Convert.ToInt64(values[1])));
                }
            } //Parse the multiline response.
            else
            {
                items = new List <Pop3ListItem>(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 Pop3ListItem(Convert.ToInt32(values[1]), Convert.ToInt64(values[2])));
            } //Parse the single line results.

            return(new ListResponse(response, items));
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Ensures the response.
 /// </summary>
 /// <param name="response">The response.</param>
 private void EnsureResponse(Pop3Response response)
 {
     EnsureResponse(response, string.Empty);
 }
Ejemplo n.º 9
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);
 }