KMime

headerparsing.h
1/* -*- c++ -*-
2 kmime_header_parsing.h
3
4 KMime, the KDE Internet mail/usenet news message library.
5 SPDX-FileCopyrightText: 2001-2002 Marc Mutz <mutz@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#pragma once
11
12#include "kmime_export.h"
13#include "types.h"
14
15#include <QDateTime>
16#include <QString>
17#include <QStringList>
18
19namespace KMime
20{
21
22namespace Headers
23{
24class Base;
25}
26
27namespace HeaderParsing
28{
29
30//
31// The parsing squad:
32//
33
34/** You may or may not have already started parsing into the
35 atom. This function will go on where you left off.
36 */
37[[nodiscard]] KMIME_EXPORT bool parseAtom(const char *&scursor,
38 const char *const send,
39 QByteArrayView &result,
40 bool allow8Bit = false);
41
42[[deprecated("Use the QByteArrayView overload")]] [[nodiscard]]
43inline bool parseAtom(const char *&scursor, const char *const send, QByteArray &result, bool allow8Bit = false)
44{
46 const auto r = parseAtom(scursor, send, v, allow8Bit);
47 result = v.toByteArray();
48 return r;
49}
50
51/**
52 Eats comment-folding-white-space, skips whitespace, folding and comments
53 (even nested ones) and stops at the next non-CFWS character. After
54 calling this function, you should check whether @p scursor == @p send
55 (end of header reached).
56
57 If a comment with unbalanced parentheses is encountered, @p scursor
58 is being positioned on the opening '(' of the outmost comment.
59
60 @param scursor pointer to the first character beyond the initial '=' of
61 the input string.
62 @param send pointer to end of input buffer.
63 @param isCRLF true if input string is terminated with a CRLF.
64*/
65KMIME_EXPORT void eatCFWS(const char *&scursor, const char *const send,
66 bool isCRLF);
67
68/**
69 Parses a single mailbox.
70
71 RFC 2822, section 3.4 defines a mailbox as follows:
72 <pre>mailbox := addr-spec / ([ display-name ] angle-addr)</pre>
73
74 KMime also accepts the legacy format of specifying display names:
75 <pre>mailbox := (addr-spec [ "(" display-name ")" ])
76 / ([ display-name ] angle-addr)
77 / (angle-addr "(" display-name ")")</pre>
78
79 @param scursor pointer to the first character of the input string
80 @param send pointer to end of input buffer
81 @param result the parsing result
82 @param isCRLF true if input string is terminated with a CRLF.
83*/
84KMIME_EXPORT bool parseMailbox(const char *&scursor, const char *const send,
85 Types::Mailbox &result, bool isCRLF = false);
86
87[[nodiscard]] KMIME_EXPORT bool parseGroup(const char *&scursor,
88 const char *const send,
89 Types::Address &result,
90 bool isCRLF = false);
91
92[[nodiscard]] KMIME_EXPORT bool parseAddress(const char *&scursor,
93 const char *const send,
94 Types::Address &result,
95 bool isCRLF = false);
96
97[[nodiscard]] KMIME_EXPORT bool parseAddressList(const char *&scursor,
98 const char *const send,
99 Types::AddressList &result,
100 bool isCRLF = false);
101
102/** Parses the first header contained the given data.
103 * If a header is found @p head will be shortened to no longer
104 * include the corresponding data, ie. this method can be called
105 * iteratively on the same data until it returns @c null.
106 * @since 6.0
107 */
108[[nodiscard]] KMIME_EXPORT std::unique_ptr<KMime::Headers::Base> parseNextHeader(QByteArrayView &head);
109
110/**
111 * Extract the header header and the body from a complete content.
112 * Internally, it will simply look for the first newline and use that as a
113 * separator between the header and the body.
114 *
115 * @param content the complete mail
116 * @param header return value for the extracted header
117 * @param body return value for the extracted body
118 * @since 4.6
119 */
120KMIME_EXPORT void extractHeaderAndBody(const QByteArray &content,
121 QByteArray &header, QByteArray &body);
122
123} // namespace HeaderParsing
124
125} // namespace KMime
QByteArray toByteArray() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Nov 6 2024 12:05:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.