using System; using System.IO; namespace Ant.Service.Utilities { internal sealed class TopCommand : Pop3Command { private int _messageNumber; private int _lineCount; /// /// Initializes a new instance of the class. /// /// The stream. /// The message number. /// The line count. internal TopCommand(Stream stream, int messageNumber, int lineCount) : base(stream, true, Pop3State.Transaction) { if (messageNumber < 1) { throw new ArgumentOutOfRangeException("messageNumber"); } if (lineCount < 0) { throw new ArgumentOutOfRangeException("lineCount"); } _messageNumber = messageNumber; _lineCount = lineCount; } /// /// Abstract method intended for inheritors to /// build out the byte[] request message for /// the specific command. /// /// /// The byte[] containing the request message. /// protected override byte[] CreateRequestMessage() { return GetRequestMessage(Pop3Commands.Top, _messageNumber.ToString(), " ", _lineCount.ToString(), Pop3Commands.Crlf); } /// /// Creates the response. /// /// The buffer. /// /// The Pop3Response containing the results of the /// Pop3 command execution. /// protected override RetrResponse CreateResponse(byte[] buffer) { Pop3Response response = Pop3Response.CreateResponse(buffer); if (response == null) { return null; } string[] messageLines = GetResponseLines(StripPop3HostMessage(buffer, response.HostMessage)); return new RetrResponse(response, messageLines); } } }