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 <QString>
16#include <QPair>
17
18#include <QDateTime>
19
20#include <QStringList>
21
22namespace KMime
23{
24
25namespace Headers
26{
27class Base;
28}
29
30namespace Types
31{
32
33} // namespace KMime::Types
34
35namespace HeaderParsing
36{
37
38/**
39 Parses the encoded word.
40
41 @param scursor pointer to the first character beyond the initial '=' of
42 the input string.
43 @param send pointer to end of input buffer.
44 @param result the decoded string the encoded work represented.
45 @param language The language parameter according to RFC 2231, section 5.
46 @param usedCS the used charset is returned here
47 @param defaultCS the charset to use in case the detected
48 one isn't known to us.
49
50 @return true if the input string was successfully decode; false otherwise.
51*/
52[[nodiscard]] KMIME_EXPORT bool
53parseEncodedWord(const char *&scursor, const char *const send, QString &result,
54 QByteArray &language, QByteArray &usedCS,
55 const QByteArray &defaultCS = QByteArray());
56
57//
58// The parsing squad:
59//
60
61/** You may or may not have already started parsing into the
62 atom. This function will go on where you left off.
63 */
64[[nodiscard]] KMIME_EXPORT bool parseAtom(const char *&scursor,
65 const char *const send,
66 QByteArrayView &result,
67 bool allow8Bit = false);
68
69[[deprecated("Use the QByteArrayView overload")]] [[nodiscard]]
70inline bool parseAtom(const char *&scursor, const char *const send, QByteArray &result, bool allow8Bit = false)
71{
73 const auto r = parseAtom(scursor, send, v, allow8Bit);
74 result = v.toByteArray();
75 return r;
76}
77
78/** @p scursor must be positioned after the opening openChar. */
79[[nodiscard]] KMIME_EXPORT bool
80parseGenericQuotedString(const char *&scursor, const char *const send,
81 QString &result, bool isCRLF,
82 const char openChar = '"', const char closeChar = '"');
83
84/** @p scursor must be positioned right after the opening '(' */
85[[nodiscard]] KMIME_EXPORT bool
86parseComment(const char *&scursor, const char *const send, QString &result,
87 bool isCRLF = false, bool reallySave = true);
88
89/**
90 Parses a phrase.
91
92 You may or may not have already started parsing into the phrase, but
93 only if it starts with atext. If you setup this function to parse a
94 phrase starting with an encoded-word or quoted-string, @p scursor has
95 to point to the char introducing the encoded-word or quoted-string, resp.
96
97 @param scursor pointer to the first character beyond the initial '=' of
98 the input string.
99 @param send pointer to end of input buffer.
100 @param result the parsed string.
101
102 @return true if the input phrase was successfully parsed; false otherwise.
103*/
104[[nodiscard]] KMIME_EXPORT bool parsePhrase(const char *&scursor,
105 const char *const send,
106 QString &result,
107 bool isCRLF = false);
108
109/**
110 Parses into the initial atom.
111 You may or may not have already started parsing into the initial
112 atom, but not up to it's end.
113
114 @param scursor pointer to the first character beyond the initial '=' of
115 the input string.
116 @param send pointer to end of input buffer.
117 @param result the parsed string.
118
119 @return true if the input phrase was successfully parsed; false otherwise.
120*/
121[[nodiscard]] KMIME_EXPORT bool parseDotAtom(const char *&scursor,
122 const char *const send,
123 QByteArray &result,
124 bool isCRLF = false);
125
126/**
127 Eats comment-folding-white-space, skips whitespace, folding and comments
128 (even nested ones) and stops at the next non-CFWS character. After
129 calling this function, you should check whether @p scursor == @p send
130 (end of header reached).
131
132 If a comment with unbalanced parentheses is encountered, @p scursor
133 is being positioned on the opening '(' of the outmost comment.
134
135 @param scursor pointer to the first character beyond the initial '=' of
136 the input string.
137 @param send pointer to end of input buffer.
138 @param isCRLF true if input string is terminated with a CRLF.
139*/
140KMIME_EXPORT void eatCFWS(const char *&scursor, const char *const send,
141 bool isCRLF);
142
143[[nodiscard]] KMIME_EXPORT bool parseDomain(const char *&scursor,
144 const char *const send,
145 QString &result,
146 bool isCRLF = false);
147
148[[nodiscard]] KMIME_EXPORT bool
149parseObsRoute(const char *&scursor, const char *const send, QStringList &result,
150 bool isCRLF = false, bool save = false);
151
152[[nodiscard]] KMIME_EXPORT bool parseAddrSpec(const char *&scursor,
153 const char *const send,
154 Types::AddrSpec &result,
155 bool isCRLF = false);
156
157[[nodiscard]] KMIME_EXPORT bool parseAngleAddr(const char *&scursor,
158 const char *const send,
159 Types::AddrSpec &result,
160 bool isCRLF = false);
161
162/**
163 Parses a single mailbox.
164
165 RFC 2822, section 3.4 defines a mailbox as follows:
166 <pre>mailbox := addr-spec / ([ display-name ] angle-addr)</pre>
167
168 KMime also accepts the legacy format of specifying display names:
169 <pre>mailbox := (addr-spec [ "(" display-name ")" ])
170 / ([ display-name ] angle-addr)
171 / (angle-addr "(" display-name ")")</pre>
172
173 @param scursor pointer to the first character of the input string
174 @param send pointer to end of input buffer
175 @param result the parsing result
176 @param isCRLF true if input string is terminated with a CRLF.
177*/
178KMIME_EXPORT bool parseMailbox(const char *&scursor, const char *const send,
179 Types::Mailbox &result, bool isCRLF = false);
180
181[[nodiscard]] KMIME_EXPORT bool parseGroup(const char *&scursor,
182 const char *const send,
183 Types::Address &result,
184 bool isCRLF = false);
185
186[[nodiscard]] KMIME_EXPORT bool parseAddress(const char *&scursor,
187 const char *const send,
188 Types::Address &result,
189 bool isCRLF = false);
190
191[[nodiscard]] KMIME_EXPORT bool parseAddressList(const char *&scursor,
192 const char *const send,
193 Types::AddressList &result,
194 bool isCRLF = false);
195
196/**
197 Parses an integer number.
198 @param scursor pointer to the first character of the input string
199 @param send pointer to end of input buffer
200 @param result the parsing result
201 @returns The number of parsed digits (don't confuse with @p result!)
202*/
203[[nodiscard]] KMIME_EXPORT int parseDigits(const char *&scursor,
204 const char *const send, int &result);
205
206[[nodiscard]] KMIME_EXPORT bool
207parseTime(const char *&scursor, const char *const send, int &hour, int &min,
208 int &sec, long int &secsEastOfGMT, bool &timeZoneKnown,
209 bool isCRLF = false);
210
211[[nodiscard]] KMIME_EXPORT bool parseDateTime(const char *&scursor,
212 const char *const send,
213 QDateTime &result,
214 bool isCRLF = false);
215[[nodiscard]] KMIME_EXPORT bool parseQDateTime(const char *&scursor,
216 const char *const send,
217 QDateTime &result,
218 bool isCRLF = false);
219
220/** Parses the first header contained the given data.
221 * If a header is found @p head will be shortened to no longer
222 * include the corresponding data, ie. this method can be called
223 * iteratively on the same data until it returns @c null.
224 * @since 6.0
225 */
226[[nodiscard]] KMIME_EXPORT std::unique_ptr<KMime::Headers::Base> parseNextHeader(QByteArrayView &head);
227
228/**
229 * Extract the header header and the body from a complete content.
230 * Internally, it will simply look for the first newline and use that as a
231 * separator between the header and the body.
232 *
233 * @param content the complete mail
234 * @param header return value for the extracted header
235 * @param body return value for the extracted body
236 * @since 4.6
237 */
238KMIME_EXPORT void extractHeaderAndBody(const QByteArray &content,
239 QByteArray &header, QByteArray &body);
240
241} // namespace HeaderParsing
242
243} // namespace KMime
QByteArray toByteArray() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:51:33 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.