Click here to Skip to main content
15,891,778 members
Articles / Programming Languages / C#

.NET POP3 MIME Client

Rate me:
Please Sign up or sign in to vote.
4.89/5 (53 votes)
8 Feb 2008CPOL9 min read 1.1M   6.8K   174  
This article provides an implementation of a POP3 MIME client using .NET 2.0 and C#.
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.IO;

namespace Net.Mail
{
    /// <summary>
    /// This class represents the Pop3 RETR command.
    /// </summary>
    internal sealed class RetrCommand : Pop3Command<RetrResponse>
    {
        int _message;

        /// <summary>
        /// Initializes a new instance of the <see cref="RetrCommand"/> class.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="message">The message.</param>
        public RetrCommand(Stream stream, int message) 
            : base(stream, true, Pop3State.Transaction)
        {
            if (message < 0)
            {
                throw new ArgumentOutOfRangeException("message");
            }

            _message = message;
        }

        /// <summary>
        /// Creates the RETR request message.
        /// </summary>
        /// <returns>
        /// The byte[] containing the RETR request message.
        /// </returns>
        protected override byte[] CreateRequestMessage()
        {
            return GetRequestMessage(Pop3Commands.Retr, _message.ToString(), Pop3Commands.Crlf);
        }

        /// <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);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions