KMime::HeaderParsing Namespace

namespace KMime::HeaderParsing
Header: #include <KMime/HeaderParsing>
CMake: find_package(KPim6 REQUIRED COMPONENTS Mime)
target_link_libraries(mytarget PRIVATE KPim6::Mime)

Types

flags ParseTokenFlags
(since 26.04) enum class ParsingPolicy { Allow7BitOnly, Allow8Bit }

Functions

void eatCFWS(const char *&scursor, const char *const send, KMime::NewlineType newline)
void eatCFWS(const char *&scursor, const char *const send, KMime::NewlineType newline, KMime::HeaderParsing::ParserState &state)
void extractHeaderAndBody(const QByteArray &content, QByteArray &header, QByteArray &body)
bool parseAddress(const char *&scursor, const char *const send, KMime::Types::Address &result, KMime::NewlineType newline = NewlineType::LF)
bool parseAddressList(const char *&scursor, const char *const send, QList<KMime::Types::Address> &result, KMime::NewlineType newline = NewlineType::LF)
bool parseAtom(const char *&scursor, const char *const send, QByteArrayView &result, KMime::HeaderParsing::ParsingPolicy parsingPolicy = ParsingPolicy::Allow7BitOnly)
bool parseGroup(const char *&scursor, const char *const send, KMime::Types::Address &result, KMime::NewlineType newline = NewlineType::LF)
bool parseMailbox(const char *&scursor, const char *const send, KMime::Types::Mailbox &result, KMime::NewlineType newline = NewlineType::LF)
(since 6.0) std::unique_ptr<KMime::Headers::Base> parseNextHeader(QByteArrayView &head)

Detailed Description

Type Documentation

[since 26.04] enum class HeaderParsing::ParsingPolicy

Policy for parseAtom().

ConstantValueDescription
KMime::HeaderParsing::ParsingPolicy::Allow7BitOnly0Stop parsing if an 8-bit character is encountered
KMime::HeaderParsing::ParsingPolicy::Allow8Bit1Accept 8-bit characters

This enum was introduced in 26.04.

Function Documentation

void HeaderParsing::eatCFWS(const char *&scursor, const char *const send, KMime::NewlineType newline)

Eats comment-folding-white-space, skips whitespace, folding and comments (even nested ones) and stops at the next non-CFWS character. After calling this function, you should check whether scursor == send (end of header reached).

If a comment with unbalanced parentheses is encountered, scursor is being positioned on the opening '(' of the outmost comment.

scursor pointer to the first character beyond the initial '=' of the input string.

send pointer to end of input buffer.

newline whether the input string is terminated with CRLF or LF.

void HeaderParsing::eatCFWS(const char *&scursor, const char *const send, KMime::NewlineType newline, KMime::HeaderParsing::ParserState &state)

Eats comment-folding-white-space, skips whitespace, folding and comments (even nested ones) and stops at the next non-CFWS character. After calling this function, you should check whether scursor == send (end of header reached).

If a comment with unbalanced parentheses is encountered, scursor is being positioned on the opening '(' of the outmost comment.

scursor pointer to the first character beyond the initial '=' of the input string.

send pointer to end of input buffer.

newline whether the input string is terminated with CRLF or LF.

state Parser state between different calls on the same header. Use when possible to prevent quadratic behavior on invalid nested comments.

void HeaderParsing::extractHeaderAndBody(const QByteArray &content, QByteArray &header, QByteArray &body)

Extract the header header and the body from a complete content.

Internally, it will simply look for the first newline and use that as a separator between the header and the body.

content the complete mail

header return value for the extracted header

body return value for the extracted body

bool HeaderParsing::parseAddress(const char *&scursor, const char *const send, KMime::Types::Address &result, KMime::NewlineType newline = NewlineType::LF)

bool HeaderParsing::parseAddressList(const char *&scursor, const char *const send, QList<KMime::Types::Address> &result, KMime::NewlineType newline = NewlineType::LF)

bool HeaderParsing::parseAtom(const char *&scursor, const char *const send, QByteArrayView &result, KMime::HeaderParsing::ParsingPolicy parsingPolicy = ParsingPolicy::Allow7BitOnly)

You may or may not have already started parsing into the atom. This function will go on where you left off.

bool HeaderParsing::parseGroup(const char *&scursor, const char *const send, KMime::Types::Address &result, KMime::NewlineType newline = NewlineType::LF)

bool HeaderParsing::parseMailbox(const char *&scursor, const char *const send, KMime::Types::Mailbox &result, KMime::NewlineType newline = NewlineType::LF)

Parses a single mailbox.

RFC 2822, section 3.4 defines a mailbox as follows:

mailbox := addr-spec / ([ display-name ] angle-addr)

KMime also accepts the legacy format of specifying display names:

mailbox := (addr-spec [ "(" display-name ")" ])
/ ([ display-name ] angle-addr)
/ (angle-addr "(" display-name ")")

scursor pointer to the first character of the input string

send pointer to end of input buffer

result the parsing result

newline whether the input string is terminated with CRLF or LF.

[since 6.0] std::unique_ptr<KMime::Headers::Base> HeaderParsing::parseNextHeader(QByteArrayView &head)

Parses the first header contained the given data.

If a header is found head will be shortened to no longer include the corresponding data, ie. this method can be called iteratively on the same data until it returns nullptr.

This function was introduced in 6.0.