StatCommand.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.IO;
  3. namespace Ant.Service.Utilities
  4. {
  5. /// <summary>
  6. /// This class represents the Pop3 STAT command.
  7. /// </summary>
  8. internal sealed class StatCommand : Pop3Command<StatResponse>
  9. {
  10. /// <summary>
  11. /// Initializes a new instance of the <see cref="StatCommand"/> class.
  12. /// </summary>
  13. /// <param name="stream">The stream.</param>
  14. public StatCommand(Stream stream)
  15. : base(stream, false, Pop3State.Transaction) { }
  16. /// <summary>
  17. /// Creates the STAT request message.
  18. /// </summary>
  19. /// <returns>
  20. /// The byte[] containing the STAT request message.
  21. /// </returns>
  22. protected override byte[] CreateRequestMessage()
  23. {
  24. return GetRequestMessage(Pop3Commands.Stat);
  25. }
  26. /// <summary>
  27. /// Creates the response.
  28. /// </summary>
  29. /// <param name="buffer">The buffer.</param>
  30. /// <returns>
  31. /// The <c>Pop3Response</c> containing the results of the
  32. /// Pop3 command execution.
  33. /// </returns>
  34. protected override StatResponse CreateResponse(byte[] buffer)
  35. {
  36. Pop3Response response = Pop3Response.CreateResponse(buffer);
  37. string[] values = response.HostMessage.Split(' ');
  38. //should consist of '+OK', 'messagecount', 'octets'
  39. if (values.Length < 3)
  40. {
  41. throw new Pop3Exception(string.Concat("Invalid response message: ", response.HostMessage));
  42. }
  43. int messageCount = Convert.ToInt32(values[1]);
  44. long octets = Convert.ToInt64(values[2]);
  45. return new StatResponse(response, messageCount, octets);
  46. }
  47. }
  48. }