using System; using System.IO; namespace Ant.Service.Utilities { /// /// This class represents the Pop3 STAT command. /// internal sealed class StatCommand : Pop3Command { /// /// Initializes a new instance of the class. /// /// The stream. public StatCommand(Stream stream) : base(stream, false, Pop3State.Transaction) { } /// /// Creates the STAT request message. /// /// /// The byte[] containing the STAT request message. /// protected override byte[] CreateRequestMessage() { return GetRequestMessage(Pop3Commands.Stat); } /// /// Creates the response. /// /// The buffer. /// /// The Pop3Response containing the results of the /// Pop3 command execution. /// 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); } } }