You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MailHeaders.hpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // MailHeaders.hpp
  2. // Copyright (C) 2008 ARM Research Labs, LLC.
  3. // See www.armresearch.com for the copyright terms.
  4. //
  5. // Header file for MailHeaders.cpp.
  6. #ifndef MailHeadershpp_included
  7. #define MailHeadershpp_included
  8. #include <string>
  9. using namespace std;
  10. /// Class to extract mail header name/body pairs.
  11. //
  12. // This class extracts mail header name/body pairs from a string
  13. // containing a series of mail headers.
  14. //
  15. class MailHeaders {
  16. private:
  17. string Buffer; ///< Contains the mail headers.
  18. const string SMTPENDL; ///< STMP end-of-line string (e.g. "\r\n).
  19. const string LibMilterENDL; ///< libmilter end-of-line string.
  20. const string Prefix; ///< Start of header name (e.g. "X-").
  21. /// Get the next header name and body.
  22. //
  23. // This method inputs a string containing zero or more RFC
  24. // 2822-compliant headers, and returns the header name and body in
  25. // a format suitable for adding the header using the libmilter
  26. // library. The header name, ":", body, and the trailing SMTPENDL
  27. // are removed from the input string.
  28. //
  29. // \param[out] HeaderName contains the name of the header.
  30. //
  31. // \param[in,out] Buffer on input contains the headers. On output,
  32. // the name of the first header, the ":", header body, and trailing
  33. // SMTPENDL are removed from the beginning.
  34. //
  35. // \returns true if a header is found, false if Buffer is "".
  36. //
  37. // \throws std::invalid_argument if Buffer does not have the correct
  38. // format.
  39. //
  40. // \see getHeaderLine.
  41. //
  42. // \see getHeaderBody.
  43. //
  44. bool getHeaderName(std::string *HeaderName);
  45. /// Get the next line of a mail header.
  46. //
  47. // This method inputs a string containing zero or more lines of
  48. // the body of a RFC 2822-compliant header, and returns the next
  49. // line of the body of the header. The line and the SMTPENDL are
  50. // removed from the input string Buffer.
  51. //
  52. // \param[out] HeaderLine contains the line of the header.
  53. //
  54. // \returns true if a line is found, false if Buffer is "".
  55. //
  56. // \throws std::invalid_argument if the first line of Buffer is not
  57. // "", and does not end with SMTPENDL.
  58. //
  59. bool getHeaderLine(std::string *HeaderLine);
  60. public:
  61. MailHeaders(); ///< Constructer for MailHeaders.
  62. ~MailHeaders(); ///< Destructor for MailHeaders.
  63. /// Load mail headers.
  64. //
  65. // This method loads the object with the headers.
  66. //
  67. // \param[in] HeaderBuffer contains the headers.
  68. //
  69. void loadHeaders(const string &HeaderBuffer);
  70. /// Get the next header name and body.
  71. //
  72. // This method returns the next header name and body. The body is
  73. // formatted so that it can be used as input for the libmilter
  74. // smfi_addheader() function.
  75. //
  76. // \param[out] HeaderName contains the header name.
  77. //
  78. // \param[out] FormattedHeaderBody contains the formatted header
  79. // body.
  80. //
  81. // \returns true if a header/body is found, false if the buffer is
  82. // "".
  83. //
  84. // \throws exceptions thrown by getHeaderName and getHeaderLine.
  85. //
  86. // \see getHeaderName.
  87. //
  88. // \see getHeaderLine.
  89. //
  90. bool getNameBody(string *HeaderName, string *FormattedHeaderBody);
  91. };
  92. #endif