#ifndef __MessageHeaders_h__ # define __MessageHeaders_h__ #include #include namespace mail { /// /// Text-only header parsing shared by FETCH's ENVELOPE/BODY[HEADER...] /// data items and SEARCH's FROM/TO/CC/SUBJECT criteria. Deliberately /// does NOT parse MIME structure (no multipart, no Content-Type /// tree) - see MailFolder.h's own doc comment on the same scoping /// decision (BODYSTRUCTURE is out of scope; ENVELOPE only needs /// header text). /// struct Address { std::string name; std::string mailbox; std::string host; }; // Splits a raw message into its header block and body, at the first // blank line. header does NOT include the trailing blank line. void splitMessage(const std::string &message, std::string &headerBlock, std::string &bodyBlock); // Unfolds continuation lines (RFC 5322 3.2.2 - a line starting with // SP/TAB continues the previous header) and returns every header as // (name, value) in on-the-wire order. Value has the folding // whitespace collapsed to a single space and is otherwise verbatim. std::vector> parseHeaderLines(const std::string &headerBlock); // First header matching name (case-insensitive), or "" if absent. std::string getHeader(const std::vector> &headers, const std::string &name); // "Name , user2@host2" -> parsed addresses. Splits on // top-level commas only (respecting "..." and <...>) - a simplified, // not fully RFC 5322-compliant parser (no comments, no obsolete // routing syntax), sufficient for real-world From/To/Cc header text. std::vector
parseAddressList(const std::string &headerValue); // RFC 3501 7.4.2 ENVELOPE structure, built entirely from parsed // headers - "sender"/"reply-to" default to "from" when their own // header is absent, per the same RFC section's own convention. std::string buildEnvelope(const std::string &message); // nstring per RFC 3501 4.3 - a quoted string with backslash/quote // escaped, or the literal NIL for an empty value. std::string imapQuoteOrNil(const std::string &value); } #endif