RetrCommand.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.IO;
  3. namespace Ant.Service.Utilities
  4. {
  5. /// <summary>
  6. /// This class represents the Pop3 RETR command.
  7. /// </summary>
  8. internal sealed class RetrCommand : Pop3Command<RetrResponse>
  9. {
  10. int _message;
  11. /// <summary>
  12. /// Initializes a new instance of the <see cref="RetrCommand"/> class.
  13. /// </summary>
  14. /// <param name="stream">The stream.</param>
  15. /// <param name="message">The message.</param>
  16. public RetrCommand(Stream stream, int message)
  17. : base(stream, true, Pop3State.Transaction)
  18. {
  19. if (message < 0)
  20. {
  21. throw new ArgumentOutOfRangeException("message");
  22. }
  23. _message = message;
  24. }
  25. /// <summary>
  26. /// Creates the RETR request message.
  27. /// </summary>
  28. /// <returns>
  29. /// The byte[] containing the RETR request message.
  30. /// </returns>
  31. protected override byte[] CreateRequestMessage()
  32. {
  33. return GetRequestMessage(Pop3Commands.Retr, _message.ToString(), Pop3Commands.Crlf);
  34. }
  35. /// <summary>
  36. /// Creates the response.
  37. /// </summary>
  38. /// <param name="buffer">The buffer.</param>
  39. /// <returns>
  40. /// The <c>Pop3Response</c> containing the results of the
  41. /// Pop3 command execution.
  42. /// </returns>
  43. protected override RetrResponse CreateResponse(byte[] buffer)
  44. {
  45. Pop3Response response = Pop3Response.CreateResponse(buffer);
  46. string[] messageLines = GetResponseLines(StripPop3HostMessage(buffer, response.HostMessage));
  47. return new RetrResponse(response, messageLines);
  48. }
  49. }
  50. }