// MailHeaders.hpp // Copyright (C) 2008 ARM Research Labs, LLC. // See www.armresearch.com for the copyright terms. // // Header file for MailHeaders.cpp. #ifndef MailHeadershpp_included #define Mailheadershpp_included #include using namespace std; /// Class to extract mail header name/body pairs. // // This class extracts mail header name/body pairs from a string // containing a series of mail headers. // class MailHeaders { private: string Buffer; ///< Contains the mail headers. const string SMTPENDL; ///< STMP end-of-line string (e.g. "\r\n). const string LibMilterENDL; ///< libmilter end-of-line string. const string Prefix; ///< Start of header name (e.g. "X-"). /// Get the next header name and body. // // This method inputs a string containing zero or more RFC // 2822-compliant headers, and returns the header name and body in // a format suitable for adding the header using the libmilter // library. The header name, ":", body, and the trailing SMTPENDL // are removed from the input string. // // \param[out] HeaderName contains the name of the header. // // \param[in,out] Buffer on input contains the headers. On output, // the name of the first header, the ":", header body, and trailing // SMTPENDL are removed from the beginning. // // \returns true if a header is found, false if Buffer is "". // // \throws std::invalid_argument if Buffer does not have the correct // format. // // \see getHeaderLine. // // \see getHeaderBody. // bool getHeaderName(std::string *HeaderName); /// Get the next line of a mail header. // // This method inputs a string containing zero or more lines of // the body of a RFC 2822-compliant header, and returns the next // line of the body of the header. The line and the SMTPENDL are // removed from the input string Buffer. // // \param[out] HeaderLine contains the line of the header. // // \returns true if a line is found, false if Buffer is "". // // \throws std::invalid_argument if the first line of Buffer is not // "", and does not end with SMTPENDL. // bool getHeaderLine(std::string *HeaderLine); public: MailHeaders(); ///< Constructer for MailHeaders. ~MailHeaders(); ///< Destructor for MailHeaders. /// Load mail headers. // // This method loads the object with the headers. // // \param[in] HeaderBuffer contains the headers. // void loadHeaders(const string &HeaderBuffer); /// Get the next header name and body. // // This method returns the next header name and body. The body is // formatted so that it can be used as input for the libmilter // smfi_addheader() function. // // \param[out] HeaderName contains the header name. // // \param[out] FormattedHeaderBody contains the formatted header // body. // // \returns true if a header/body is found, false if the buffer is // "". // // \throws exceptions thrown by getHeaderName and getHeaderLine. // // \see getHeaderName. // // \see getHeaderLine. // bool getNameBody(string *HeaderName, string *FormattedHeaderBody); }; #endif