TopCommand.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.IO;
  3. namespace Ant.Service.Utilities
  4. {
  5. internal sealed class TopCommand : Pop3Command<RetrResponse>
  6. {
  7. private int _messageNumber;
  8. private int _lineCount;
  9. /// <summary>
  10. /// Initializes a new instance of the <see cref="TopCommand"/> class.
  11. /// </summary>
  12. /// <param name="stream">The stream.</param>
  13. /// <param name="messageNumber">The message number.</param>
  14. /// <param name="lineCount">The line count.</param>
  15. internal TopCommand(Stream stream, int messageNumber, int lineCount)
  16. : base(stream, true, Pop3State.Transaction)
  17. {
  18. if (messageNumber < 1)
  19. {
  20. throw new ArgumentOutOfRangeException("messageNumber");
  21. }
  22. if (lineCount < 0)
  23. {
  24. throw new ArgumentOutOfRangeException("lineCount");
  25. }
  26. _messageNumber = messageNumber;
  27. _lineCount = lineCount;
  28. }
  29. /// <summary>
  30. /// Abstract method intended for inheritors to
  31. /// build out the byte[] request message for
  32. /// the specific command.
  33. /// </summary>
  34. /// <returns>
  35. /// The byte[] containing the request message.
  36. /// </returns>
  37. protected override byte[] CreateRequestMessage()
  38. {
  39. return GetRequestMessage(Pop3Commands.Top, _messageNumber.ToString(), " ", _lineCount.ToString(), Pop3Commands.Crlf);
  40. }
  41. /// <summary>
  42. /// Creates the response.
  43. /// </summary>
  44. /// <param name="buffer">The buffer.</param>
  45. /// <returns>
  46. /// The <c>Pop3Response</c> containing the results of the
  47. /// Pop3 command execution.
  48. /// </returns>
  49. protected override RetrResponse CreateResponse(byte[] buffer)
  50. {
  51. Pop3Response response = Pop3Response.CreateResponse(buffer);
  52. if (response == null)
  53. {
  54. return null;
  55. }
  56. string[] messageLines = GetResponseLines(StripPop3HostMessage(buffer, response.HostMessage));
  57. return new RetrResponse(response, messageLines);
  58. }
  59. }
  60. }