KMime

headers.h
Go to the documentation of this file.
1/* -*- c++ -*-
2 kmime_headers.h
3
4 KMime, the KDE Internet mail/usenet news message library.
5 SPDX-FileCopyrightText: 2001-2002 the KMime authors.
6 See file AUTHORS for details
7 SPDX-FileCopyrightText: 2006 Volker Krause <vkrause@kde.org>
8
9 SPDX-License-Identifier: LGPL-2.0-or-later
10*/
11/**
12 @file
13 This file is part of the API for handling @ref MIME data and
14 defines the various header classes:
15 - header's base class defining the common interface
16 - generic base classes for different types of fields
17 - incompatible, Structured-based field classes
18 - compatible, Unstructured-based field classes
19
20 @brief
21 Defines the various headers classes.
22
23 @authors the KMime authors (see AUTHORS file),
24 Volker Krause <vkrause@kde.org>
25*/
26
27#pragma once
28
29#include "kmime_export.h"
30#include "headerparsing.h"
31
32#include <QByteArray>
33#include <QDateTime>
34#include <QList>
35#include <QMetaType>
36#include <QString>
37#include <QStringList>
38
39namespace KMime
40{
41
42class Content;
43
44namespace Headers
45{
46
47class BasePrivate;
48
49/**
50 Various possible values for the "Content-Transfer-Encoding" header.
51*/
53 CE7Bit, ///< 7bit
54 CE8Bit, ///< 8bit
55 CEquPr, ///< quoted-printable
56 CEbase64, ///< base64
57 CEuuenc, ///< uuencode
58 CEbinary ///< binary
59};
60
61/**
62 Various possible values for the "Content-Disposition" header.
63*/
65 CDInvalid, ///< Default, invalid value
66 CDinline, ///< inline
67 CDattachment, ///< attachment
68 CDparallel ///< parallel (invalid, do not use)
69};
70
71//@cond PRIVATE
72// internal macro to generate default constructors
73#define kmime_mk_trivial_ctor( subclass ) \
74 public: \
75 subclass(); \
76 ~subclass() override;
77
78#define kmime_mk_dptr_ctor( subclass ) \
79 protected: \
80 explicit subclass( subclass##Private *d );
81
82#define kmime_mk_trivial_ctor_with_name( subclass ) \
83 kmime_mk_trivial_ctor( subclass ) \
84 [[nodiscard]] const char *type() const override; \
85 [[nodiscard]] static const char *staticType();
86//@endcond
87
88//
89//
90// HEADER'S BASE CLASS. DEFINES THE COMMON INTERFACE
91//
92//
93
94/** Baseclass of all header-classes. It represents a
95 header-field as described in RFC-822. */
96class KMIME_EXPORT Base
97{
98public:
99 /**
100 A vector of headers.
101 */
103
104 /**
105 Creates an empty header.
106 */
107 Base();
108
109 /**
110 Destructor.
111 */
112 virtual ~Base();
113
114 /**
115 Parses the given string. Take care of RFC2047-encoded strings.
116 @param s The encoded header data.
117 */
118 virtual void from7BitString(QByteArrayView s) = 0;
119
120 /**
121 Returns the encoded header.
122 @param withHeaderType Specifies whether the header-type should be included.
123 */
124 [[nodiscard]] virtual QByteArray
125 as7BitString(bool withHeaderType = true) const = 0;
126
127 /**
128 Returns the charset that is used for RFC2047-encoding.
129 */
130 [[nodiscard]] QByteArray rfc2047Charset() const;
131
132 /**
133 Sets the charset for RFC2047-encoding.
134 @param cs The new charset used for RFC2047 encoding.
135 */
136 void setRFC2047Charset(const QByteArray &cs);
137
138 /**
139 Parses the given Unicode representation of the header content.
140 @param s The header data as Unicode string.
141 */
142 virtual void fromUnicodeString(const QString &s) = 0;
143 [[deprecated("call setRFC2047Charset for the second argument if different from UTF-8, otherwise remove second argument")]]
144 inline void fromUnicodeString(const QString &s, const QByteArray &b)
145 {
146 setRFC2047Charset(b);
147 fromUnicodeString(s);
148 }
149
150 /**
151 Returns the decoded content of the header without the header-type.
152
153 @note The return value of this method should only be used when showing an
154 address to the user. It is not guaranteed that fromUnicodeString(
155 asUnicodeString(), ... ) will return the original string.
156 */
157 [[nodiscard]] virtual QString asUnicodeString() const = 0;
158
159 /**
160 Checks if this header contains any data.
161 */
162 [[nodiscard]] virtual bool isEmpty() const = 0;
163
164 /**
165 Returns the type of this header (e.g. "From").
166 */
167 [[nodiscard]] virtual const char *type() const;
168
169 /**
170 Checks if this header is of type @p t.
171 */
172 [[nodiscard]] bool is(QByteArrayView t) const;
173
174protected:
175 /**
176 Helper method, returns the header prefix including ":".
177 */
178 [[nodiscard]] QByteArray typeIntro() const;
179
180 //@cond PRIVATE
181 BasePrivate *d_ptr;
182 kmime_mk_dptr_ctor(Base)
183 //@endcond
184
185private:
186 Q_DECLARE_PRIVATE(Base)
187 Q_DISABLE_COPY(Base)
188};
189
190//
191//
192// GENERIC BASE CLASSES FOR DIFFERENT TYPES OF FIELDS
193//
194//
195
196namespace Generics
197{
198
199class UnstructuredPrivate;
200
201/**
202 Abstract base class for unstructured header fields
203 (e.g. "Subject", "Comment", "Content-description").
204
205 Features: Decodes the header according to RFC2047, incl. RFC2231
206 extensions to encoded-words.
207
208 Subclasses need only re-implement @p const @p char* @p type().
209*/
210
211// known issues:
212// - uses old decodeRFC2047String function, instead of our own...
213
214class KMIME_EXPORT Unstructured : public Base
215{
216 //@cond PRIVATE
217 kmime_mk_dptr_ctor(Unstructured)
218 //@endcond
219public:
220 Unstructured();
221 ~Unstructured() override;
222
223 void from7BitString(QByteArrayView s) override;
224 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
225
226 void fromUnicodeString(const QString &s) override;
227 using Base::fromUnicodeString;
228 [[nodiscard]] QString asUnicodeString() const override;
229
230 [[nodiscard]] bool isEmpty() const override;
231
232private:
233 Q_DECLARE_PRIVATE(Unstructured)
234};
235
236class StructuredPrivate;
237
238/**
239 @brief
240 Base class for structured header fields.
241
242 This is the base class for all structured header fields.
243 It contains parsing methods for all basic token types found in rfc2822.
244
245 @section Parsing
246
247 At the basic level, there are tokens & tspecials (rfc2045),
248 atoms & specials, quoted-strings, domain-literals (all rfc822) and
249 encoded-words (rfc2047).
250
251 As a special token, we have the comment. It is one of the basic
252 tokens defined in rfc822, but it's parsing relies in part on the
253 basic token parsers (e.g. comments may contain encoded-words).
254 Also, most upper-level parsers (notably those for phrase and
255 dot-atom) choose to ignore any comment when parsing.
256
257 Then there are the real composite tokens, which are made up of one
258 or more of the basic tokens (and semantically invisible comments):
259 phrases (rfc822 with rfc2047) and dot-atoms (rfc2822).
260
261 This finishes the list of supported token types. Subclasses will
262 provide support for more higher-level tokens, where necessary,
263 using these parsers.
264
265 @author Marc Mutz <mutz@kde.org>
266*/
267
268class KMIME_EXPORT Structured : public Base
269{
270public:
271 Structured();
272 ~Structured() override;
273
274 void from7BitString(QByteArrayView s) override;
275 [[nodiscard]] QString asUnicodeString() const override;
276 void fromUnicodeString(const QString &s) override;
277 using Base::fromUnicodeString;
278
279protected:
280 /**
281 This method parses the raw header and needs to be implemented in
282 every sub-class.
283
284 @param scursor Pointer to the start of the data still to parse.
285 @param send Pointer to the end of the data.
286 @param isCRLF true if input string is terminated with a CRLF.
287 */
288 virtual bool parse(const char *&scursor, const char *const send,
289 bool isCRLF = false) = 0;
290
291 //@cond PRIVATE
292 kmime_mk_dptr_ctor(Structured)
293 //@endcond
294
295private:
296 Q_DECLARE_PRIVATE(Structured)
297};
298
299class MailboxListPrivate;
300
301/**
302 Base class for headers that deal with (possibly multiple)
303 addresses, but don't allow groups.
304
305 @see RFC 2822, section 3.4
306*/
307class KMIME_EXPORT MailboxList : public Structured
308{
309 //@cond PRIVATE
310 kmime_mk_trivial_ctor(MailboxList)
311 kmime_mk_dptr_ctor(MailboxList)
312 //@endcond
313public:
314 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
315 void fromUnicodeString(const QString &s) override;
316 using Base::fromUnicodeString;
317 [[nodiscard]] QString asUnicodeString() const override;
318
319 [[nodiscard]] bool isEmpty() const override;
320
321 /**
322 Adds an address to this header.
323
324 @param mbox A Mailbox object specifying the address.
325 */
326 void addAddress(const Types::Mailbox &mbox);
327
328 /**
329 Adds an address to this header.
330 @param address The actual email address, with or without angle brackets.
331 @param displayName An optional name associated with the address.
332 */
333 void addAddress(const QByteArray &address,
334 const QString &displayName = QString());
335
336 /**
337 Returns a list of all addresses in this header, regardless of groups.
338 */
339 [[nodiscard]] QList<QByteArray> addresses() const;
340
341 /**
342 Returns a list of all display names associated with the addresses in
343 this header. The address is added for addresses that do not have
344 a display name.
345 */
346 [[nodiscard]] QStringList displayNames() const;
347
348 /**
349 Returns a single string for user-facing display of this mailbox list.
350 This is equivalent to displayNames().join(", ").
351 @since 5.14
352 */
353 [[nodiscard]] QString displayString() const;
354
355 /**
356 Returns a list of mailboxes listed in this header.
357 */
358 [[nodiscard]] Types::Mailbox::List mailboxes() const;
359
360 /**
361 Sets the mailboxes listed in this header, replacing the current content.
362 @since 24.12
363 */
364 void setMailboxes(const Types::Mailbox::List &mailboxes);
365
366protected:
367 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
368
369private:
370 Q_DECLARE_PRIVATE(MailboxList)
371};
372
373class SingleMailboxPrivate;
374
375/**
376 Base class for headers that deal with exactly one mailbox
377 (e.g. Sender).
378*/
379class KMIME_EXPORT SingleMailbox : public MailboxList
380{
381 //@cond PRIVATE
382 kmime_mk_trivial_ctor(SingleMailbox)
383 //@endcond
384protected:
385 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
386private:
387 Q_DECLARE_PRIVATE(SingleMailbox)
388};
389
390class AddressListPrivate;
391
392/**
393 Base class for headers that deal with (possibly multiple)
394 addresses, allowing groups.
395
396 Note: Groups are parsed but not represented in the API yet. All addresses in
397 groups are listed as if they would not be part of a group.
398
399 @todo Add API for groups?
400
401 @see RFC 2822, section 3.4
402*/
403class KMIME_EXPORT AddressList : public Structured
404{
405 //@cond PRIVATE
406 kmime_mk_trivial_ctor(AddressList)
407 kmime_mk_dptr_ctor(AddressList)
408 //@endcond
409public:
410 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
411 void fromUnicodeString(const QString &s) override;
412 using Base::fromUnicodeString;
413 [[nodiscard]] QString asUnicodeString() const override;
414
415 [[nodiscard]] bool isEmpty() const override;
416
417 /**
418 Adds an address to this header.
419
420 @param mbox A Mailbox object specifying the address.
421 */
422 void addAddress(const Types::Mailbox &mbox);
423
424 /**
425 Adds an address to this header.
426 @param address The actual email address, with or without angle brackets.
427 @param displayName An optional name associated with the address.
428 */
429 void addAddress(const QByteArray &address, const QString &displayName = QString());
430
431 /**
432 Returns a list of all addresses in this header, regardless of groups.
433 */
434 [[nodiscard]] QList<QByteArray> addresses() const;
435
436 /**
437 Returns a list of all display names associated with the addresses in this header.
438 The address is added for addresses that don't have a display name.
439 */
440 [[nodiscard]] QStringList displayNames() const;
441
442 /**
443 Returns a single string for user-facing display of this address list.
444 This is equivalent to displayNames().join(", ").
445 @since 5.14
446 */
447 [[nodiscard]] QString displayString() const;
448
449 /**
450 Returns a list of mailboxes listed in this header.
451 */
452 [[nodiscard]] Types::Mailbox::List mailboxes() const;
453
454 /**
455 Sets the list of addresses listed in this header, replacing the existing content.
456 @since 24.12
457 */
458 void setAddressList(const Types::AddressList &addresses);
459
460protected:
461 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
462
463private:
464 Q_DECLARE_PRIVATE(AddressList)
465};
466
467class IdentPrivate;
468
469/**
470 Base class for headers which deal with a list of msg-id's.
471
472 @see RFC 2822, section 3.6.4
473*/
474class KMIME_EXPORT Ident : public Structured
475{
476 //@cond PRIVATE
477 kmime_mk_trivial_ctor(Ident)
478 kmime_mk_dptr_ctor(Ident)
479 //@endcond
480public:
481 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
482 [[nodiscard]] bool isEmpty() const override;
483
484 /**
485 Initialize this identifier Copy the data from
486 */
487 void fromIdent(const Ident* ident);
488
489 /**
490 Returns the list of identifiers contained in this header.
491 Note:
492 - Identifiers are not enclosed in angle-brackets.
493 - Identifiers are listed in the same order as in the header.
494 */
495 [[nodiscard]] QList<QByteArray> identifiers() const;
496
497 /**
498 Appends a new identifier to this header.
499 @param id The identifier to append, with or without angle-brackets.
500 */
501 void appendIdentifier(const QByteArray &id);
502
503protected:
504 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
505
506private:
507 Q_DECLARE_PRIVATE(Ident)
508};
509
510class SingleIdentPrivate;
511
512/**
513 Base class for headers which deal with a single msg-id.
514
515 @see RFC 2822, section 3.6.4
516*/
517class KMIME_EXPORT SingleIdent : public Structured
518{
519 //@cond PRIVATE
520 kmime_mk_trivial_ctor(SingleIdent)
521 kmime_mk_dptr_ctor(SingleIdent)
522 //@endcond
523public:
524 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
525 [[nodiscard]] bool isEmpty() const override;
526
527 /**
528 Returns the identifier contained in this header.
529 Note: The identifiers is not enclosed in angle-brackets.
530 */
531 [[nodiscard]] QByteArray identifier() const;
532
533 /**
534 Sets the identifier.
535 @param id The new identifier with or without angle-brackets.
536 */
537 void setIdentifier(const QByteArray &id);
538
539protected:
540 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
541
542private:
543 Q_DECLARE_PRIVATE(SingleIdent)
544};
545
546class TokenPrivate;
547
548/**
549 Base class for headers which deal with a single atom.
550*/
551class KMIME_EXPORT Token : public Structured
552{
553 //@cond PRIVATE
554 kmime_mk_trivial_ctor(Token)
555 kmime_mk_dptr_ctor(Token)
556 //@endcond
557public:
558 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
559 [[nodiscard]] bool isEmpty() const override;
560
561 /**
562 Returns the token.
563 */
564 [[nodiscard]] QByteArray token() const;
565
566 /**
567 Sets the token to @p t,
568 */
569 void setToken(const QByteArray &t);
570
571protected:
572 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
573
574private:
575 Q_DECLARE_PRIVATE(Token)
576};
577
578class PhraseListPrivate;
579
580/**
581 Base class for headers containing a list of phrases.
582*/
583class KMIME_EXPORT PhraseList : public Structured
584{
585 //@cond PRIVATE
586 kmime_mk_trivial_ctor(PhraseList)
587 //@endcond
588public:
589 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
590 [[nodiscard]] QString asUnicodeString() const override;
591 [[nodiscard]] bool isEmpty() const override;
592
593 /**
594 Returns the list of phrases contained in this header.
595 */
596 [[nodiscard]] QStringList phrases() const;
597
598protected:
599 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
600
601private:
602 Q_DECLARE_PRIVATE(PhraseList)
603};
604
605class DotAtomPrivate;
606
607/**
608 Base class for headers containing a dot atom.
609*/
610class KMIME_EXPORT DotAtom : public Structured
611{
612 //@cond PRIVATE
613 kmime_mk_trivial_ctor(DotAtom)
614 //@endcond
615public:
616 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
617 [[nodiscard]] QString asUnicodeString() const override;
618 [[nodiscard]] bool isEmpty() const override;
619
620protected:
621 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
622
623private:
624 Q_DECLARE_PRIVATE(DotAtom)
625};
626
627class ParametrizedPrivate;
628
629/**
630 Base class for headers containing a parameter list such as "Content-Type".
631*/
632class KMIME_EXPORT Parametrized : public Structured
633{
634 //@cond PRIVATE
635 kmime_mk_trivial_ctor(Parametrized)
636 kmime_mk_dptr_ctor(Parametrized)
637 //@endcond
638public:
639 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
640
641 [[nodiscard]] bool isEmpty() const override;
642
643 /**
644 Returns the value of the specified parameter.
645 @param key The parameter name.
646 */
647 [[nodiscard]] QString parameter(QByteArrayView key) const;
648 [[deprecated("use QByteArrayView as argument")]] [[nodiscard]] inline QString parameter(const QString &key) const
649 {
650 return parameter(QByteArrayView(key.toUtf8()));
651 }
652 [[deprecated("use QByteArrayView as argument")]] [[nodiscard]] inline QString parameter(QLatin1StringView key) const
653 {
654 return parameter(QByteArrayView(key));
655 }
656 // overload resolution helper, remove once the above deprecated overloads are removed
657 template <std::size_t N>
658 [[nodiscard]] inline QString parameter(const char (&key)[N]) const
659 {
660 return parameter(QByteArrayView(key, N));
661 }
662
663 /**
664 @param key the key of the parameter to check for
665 @return true if a parameter with the given @p key exists.
666 @since 4.5
667 */
668 [[nodiscard]] bool hasParameter(QByteArrayView key) const;
669 [[deprecated("use QByteArrayView as argument")]] [[nodiscard]] inline bool hasParameter(const QString &key) const
670 {
671 return hasParameter(QByteArrayView(key.toUtf8()));
672 }
673 [[deprecated("use QByteArrayView as argument")]] [[nodiscard]] inline bool hasParameter(QLatin1StringView key) const
674 {
675 return hasParameter(QByteArrayView(key));
676 }
677 // overload resolution helper, remove once the above deprecated overloads are removed
678 template <std::size_t N>
679 [[nodiscard]] inline bool hasParameter(const char (&key)[N]) const {
680 return hasParameter(QByteArrayView(key, N));
681 }
682
683 /**
684 Sets the parameter @p key to @p value.
685 @param key The parameter name.
686 @param value The new value for @p key.
687 */
688 void setParameter(const QByteArray &key, const QString &value);
689 [[deprecated("use a QByteArray[Literal] key")]] inline void setParameter(const QString &key, const QString &value)
690 {
691 return setParameter(key.toUtf8(), value);
692 }
693
694protected:
695 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
696
697private:
698 Q_DECLARE_PRIVATE(Parametrized)
699};
700
701} // namespace Generics
702
703//
704//
705// INCOMPATIBLE, GSTRUCTURED-BASED FIELDS:
706//
707//
708
709class ReturnPathPrivate;
710
711/**
712 Represents the Return-Path header field.
713
714 @see RFC 2822, section 3.6.7
715*/
716class KMIME_EXPORT ReturnPath : public Generics::Structured
717{
718 //@cond PRIVATE
719 kmime_mk_trivial_ctor_with_name(ReturnPath)
720 //@endcond
721public:
722 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
723 [[nodiscard]] bool isEmpty() const override;
724
725protected:
726 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
727
728private:
729 Q_DECLARE_PRIVATE(ReturnPath)
730};
731
732// Address et al.:
733
734// rfc(2)822 headers:
735/**
736 Represent a "From" header.
737
738 @see RFC 2822, section 3.6.2.
739*/
740class KMIME_EXPORT From : public Generics::MailboxList
741{
742 kmime_mk_trivial_ctor_with_name(From)
743};
744
745/**
746 Represents a "Sender" header.
747
748 @see RFC 2822, section 3.6.2.
749*/
750class KMIME_EXPORT Sender : public Generics::SingleMailbox
751{
752 kmime_mk_trivial_ctor_with_name(Sender)
753};
754
755/**
756 Represents a "To" header.
757
758 @see RFC 2822, section 3.6.3.
759*/
760class KMIME_EXPORT To : public Generics::AddressList
761{
762 kmime_mk_trivial_ctor_with_name(To)
763};
764
765/**
766 Represents a "Cc" header.
767
768 @see RFC 2822, section 3.6.3.
769*/
770class KMIME_EXPORT Cc : public Generics::AddressList
771{
772 kmime_mk_trivial_ctor_with_name(Cc)
773};
774
775/**
776 Represents a "Bcc" header.
777
778 @see RFC 2822, section 3.6.3.
779*/
780class KMIME_EXPORT Bcc : public Generics::AddressList
781{
782 kmime_mk_trivial_ctor_with_name(Bcc)
783};
784
785/**
786 Represents a "ReplyTo" header.
787
788 @see RFC 2822, section 3.6.2.
789*/
790class KMIME_EXPORT ReplyTo : public Generics::AddressList
791{
792 kmime_mk_trivial_ctor_with_name(ReplyTo)
793};
794
795class MailCopiesToPrivate;
796
797/**
798 Represents a "Mail-Copies-To" header.
799
800 @see http://www.newsreaders.com/misc/mail-copies-to.html
801*/
802class KMIME_EXPORT MailCopiesTo : public Generics::AddressList
803{
804 //@cond PRIVATE
805 kmime_mk_trivial_ctor_with_name(MailCopiesTo)
806 //@endcond
807public:
808 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
809 [[nodiscard]] QString asUnicodeString() const override;
810
811 [[nodiscard]] bool isEmpty() const override;
812
813 /**
814 Returns true if a mail copy was explicitly requested.
815 */
816 [[nodiscard]] bool alwaysCopy() const;
817
818 /**
819 Sets the header to "poster".
820 */
821 void setAlwaysCopy();
822
823 /**
824 Returns true if a mail copy was explicitly denied.
825 */
826 [[nodiscard]] bool neverCopy() const;
827
828 /**
829 Sets the header to "never".
830 */
831 void setNeverCopy();
832
833protected:
834 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
835
836private:
837 Q_DECLARE_PRIVATE(MailCopiesTo)
838};
839
840class ContentTransferEncodingPrivate;
841
842/**
843 Represents a "Content-Transfer-Encoding" header.
844
845 @see RFC 2045, section 6.
846*/
847class KMIME_EXPORT ContentTransferEncoding : public Generics::Token
848{
849 //@cond PRIVATE
850 kmime_mk_trivial_ctor_with_name(ContentTransferEncoding)
851 //@endcond
852public:
853 [[nodiscard]] bool isEmpty() const override;
854 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
855
856 /**
857 Returns the encoding specified in this header.
858 */
859 [[nodiscard]] contentEncoding encoding() const;
860
861 /**
862 Sets the encoding to @p e.
863 */
864 void setEncoding(contentEncoding e);
865
866protected:
867 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
868
869private:
870 Q_DECLARE_PRIVATE(ContentTransferEncoding)
871};
872
873/**
874 Represents a "Keywords" header.
875
876 @see RFC 2822, section 3.6.5.
877*/
878class KMIME_EXPORT Keywords : public Generics::PhraseList
879{
880 kmime_mk_trivial_ctor_with_name(Keywords)
881};
882
883// DotAtom:
884
885/**
886 Represents a "MIME-Version" header.
887
888 @see RFC 2045, section 4.
889*/
890class KMIME_EXPORT MIMEVersion : public Generics::DotAtom
891{
892 kmime_mk_trivial_ctor_with_name(MIMEVersion)
893};
894
895// Ident:
896
897/**
898 Represents a "Message-ID" header.
899
900 @see RFC 2822, section 3.6.4.
901*/
902class KMIME_EXPORT MessageID : public Generics::SingleIdent
903{
904 //@cond PRIVATE
905 kmime_mk_trivial_ctor_with_name(MessageID)
906 //@endcond
907public:
908 /**
909 Generate a message identifier.
910 @param fqdn A fully qualified domain name.
911 */
912 void generate(const QByteArray &fqdn);
913};
914
915class ContentIDPrivate;
916
917/**
918 Represents a "Content-ID" header.
919*/
920class KMIME_EXPORT ContentID : public Generics::SingleIdent
921{
922 //@cond PRIVATE
923 kmime_mk_trivial_ctor_with_name(ContentID)
924 kmime_mk_dptr_ctor(ContentID)
925 //@endcond
926
927protected:
928 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
929private:
930 Q_DECLARE_PRIVATE(ContentID)
931};
932
933/**
934 Represents a "Supersedes" header.
935*/
936class KMIME_EXPORT Supersedes : public Generics::SingleIdent
937{
938 kmime_mk_trivial_ctor_with_name(Supersedes)
939};
940
941/**
942 Represents a "In-Reply-To" header.
943
944 @see RFC 2822, section 3.6.4.
945*/
946class KMIME_EXPORT InReplyTo : public Generics::Ident
947{
948 kmime_mk_trivial_ctor_with_name(InReplyTo)
949};
950
951/**
952 Represents a "References" header.
953
954 @see RFC 2822, section 3.6.4.
955*/
956class KMIME_EXPORT References : public Generics::Ident
957{
958 kmime_mk_trivial_ctor_with_name(References)
959};
960
961class ContentTypePrivate;
962
963/**
964 Represents a "Content-Type" header.
965
966 @see RFC 2045, section 5.
967*/
968class KMIME_EXPORT ContentType : public Generics::Parametrized
969{
970 //@cond PRIVATE
971 kmime_mk_trivial_ctor_with_name(ContentType)
972 //@endcond
973public:
974 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
975 [[nodiscard]] bool isEmpty() const override;
976
977 /**
978 Returns the mimetype.
979 */
980 [[nodiscard]] QByteArray mimeType() const;
981
982 /**
983 Returns the media type (first part of the mimetype).
984 */
985
986 [[nodiscard]] QByteArray mediaType() const;
987
988 /**
989 Returns the mime sub-type (second part of the mimetype).
990 */
991 [[nodiscard]] QByteArray subType() const;
992
993 /**
994 Sets the mimetype.
995 @param mimeType The new mimetype.
996 */
997 void setMimeType(const QByteArray &mimeType);
998
999 /**
1000 Tests if the media type equals @p mediatype.
1001 */
1002 [[nodiscard]] bool isMediatype(const char *mediatype) const;
1003
1004 /**
1005 Tests if the mime sub-type equals @p subtype.
1006 */
1007 [[nodiscard]] bool isSubtype(const char *subtype) const;
1008
1009 /**
1010 Tests if the mime type is @p mimeType.
1011 */
1012 [[nodiscard]] bool isMimeType(const char *mimeType) const;
1013
1014 /**
1015 Returns true if the associated MIME entity is a text.
1016 */
1017 [[nodiscard]] bool isText() const;
1018
1019 /**
1020 Returns true if the associated MIME entity is a plain text.
1021 */
1022 [[nodiscard]] bool isPlainText() const;
1023
1024 /**
1025 Returns true if the associated MIME entity is a HTML file.
1026 */
1027 [[nodiscard]] bool isHTMLText() const;
1028
1029 /**
1030 Returns true if the associated MIME entity is an image.
1031 */
1032 [[nodiscard]] bool isImage() const;
1033
1034 /**
1035 Returns true if the associated MIME entity is a multipart container.
1036 */
1037 [[nodiscard]] bool isMultipart() const;
1038
1039 /**
1040 Returns true if the associated MIME entity contains partial data.
1041 @see partialNumber(), partialCount()
1042 */
1043 [[nodiscard]] bool isPartial() const;
1044
1045 /**
1046 Returns the charset for the associated MIME entity.
1047 */
1048 [[nodiscard]] QByteArray charset() const;
1049
1050 /**
1051 Sets the charset.
1052 */
1053 void setCharset(const QByteArray &s);
1054
1055 /**
1056 Returns the boundary (for multipart containers).
1057 */
1058 [[nodiscard]] QByteArray boundary() const;
1059
1060 /**
1061 Sets the multipart container boundary.
1062 */
1063 void setBoundary(const QByteArray &s);
1064
1065 /**
1066 Returns the name of the associated MIME entity.
1067 */
1068 [[nodiscard]] QString name() const;
1069
1070 /**
1071 Sets the name to @p s.
1072 */
1073 void setName(const QString &s);
1074 [[deprecated("call setRFC2047Charset for the second argument if different from UTF-8, otherwise remove second argument")]]
1075 inline void setName(const QString &s, const QByteArray &cs)
1076 {
1077 setRFC2047Charset(cs);
1078 setName(s);
1079 }
1080
1081 /**
1082 Returns the identifier of the associated MIME entity.
1083 */
1084 [[nodiscard]] QByteArray id() const;
1085
1086 /**
1087 Sets the identifier.
1088 */
1089 void setId(const QByteArray &s);
1090
1091 /**
1092 Returns the position of this part in a multi-part set.
1093 @see isPartial(), partialCount()
1094 */
1095 [[nodiscard]] int partialNumber() const;
1096
1097 /**
1098 Returns the total number of parts in a multi-part set.
1099 @see isPartial(), partialNumber()
1100 */
1101 [[nodiscard]] int partialCount() const;
1102
1103 /**
1104 Sets parameters of a partial MIME entity.
1105 @param total The total number of entities in the multi-part set.
1106 @param number The number of this entity in a multi-part set.
1107 */
1108 void setPartialParams(int total, int number);
1109
1110protected:
1111 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
1112
1113private:
1114 Q_DECLARE_PRIVATE(ContentType)
1115};
1116
1117class ContentDispositionPrivate;
1118
1119/**
1120 Represents a "Content-Disposition" header.
1121
1122 @see RFC 2183
1123*/
1125{
1126 //@cond PRIVATE
1127 kmime_mk_trivial_ctor_with_name(ContentDisposition)
1128 //@endcond
1129public:
1130 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
1131 [[nodiscard]] bool isEmpty() const override;
1132
1133 /**
1134 Returns the content disposition.
1135 */
1136 [[nodiscard]] contentDisposition disposition() const;
1137
1138 /**
1139 Sets the content disposition.
1140 @param disp The new content disposition.
1141 */
1142 void setDisposition(contentDisposition disp);
1143
1144 /**
1145 Returns the suggested filename for the associated MIME part.
1146 This is just a convenience function, it is equivalent to calling
1147 parameter( "filename" );
1148 */
1149 [[nodiscard]] QString filename() const;
1150
1151 /**
1152 Sets the suggested filename for the associated MIME part.
1153 This is just a convenience function, it is equivalent to calling
1154 setParameter( "filename", filename );
1155 @param filename The filename.
1156 */
1157 void setFilename(const QString &filename);
1158
1159protected:
1160 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
1161
1162private:
1163 Q_DECLARE_PRIVATE(ContentDisposition)
1164};
1165
1166//
1167//
1168// COMPATIBLE GUNSTRUCTURED-BASED FIELDS:
1169//
1170//
1171
1172class GenericPrivate;
1173
1174/**
1175 Represents an arbitrary header, that can contain any header-field.
1176 Adds a type over Unstructured.
1177 @see Unstructured
1178*/
1179class KMIME_EXPORT Generic : public Generics::Unstructured
1180{
1181public:
1182 Generic();
1183 Generic(const char *t, qsizetype len = -1);
1184 ~Generic() override;
1185
1186 [[nodiscard]] bool isEmpty() const override;
1187
1188 [[nodiscard]] const char *type() const override;
1189
1190 void setType(const char *type, qsizetype len = -1);
1191
1192private:
1193 Q_DECLARE_PRIVATE(Generic)
1194};
1195
1196/**
1197 Represents a "Subject" header.
1198
1199 @see RFC 2822, section 3.6.5.
1200*/
1201class KMIME_EXPORT Subject : public Generics::Unstructured
1202{
1203 //@cond PRIVATE
1204 kmime_mk_trivial_ctor_with_name(Subject)
1205 //@endcond
1206};
1207
1208/**
1209 Represents a "Organization" header.
1210*/
1211class KMIME_EXPORT Organization : public Generics::Unstructured
1212{
1213 kmime_mk_trivial_ctor_with_name(Organization)
1214};
1215
1216/**
1217 Represents a "Content-Description" header.
1218*/
1220{
1221 kmime_mk_trivial_ctor_with_name(ContentDescription)
1222};
1223
1224/**
1225 Represents a "Content-Location" header.
1226 @since 4.2
1227*/
1228class KMIME_EXPORT ContentLocation : public Generics::Unstructured
1229{
1230 kmime_mk_trivial_ctor_with_name(ContentLocation)
1231};
1232
1233class ControlPrivate;
1234
1235/**
1236 Represents a "Control" header.
1237
1238 @see RFC 1036, section 3.
1239*/
1240class KMIME_EXPORT Control : public Generics::Structured
1241{
1242 //@cond PRIVATE
1243 kmime_mk_trivial_ctor_with_name(Control)
1244 //@endcond
1245public:
1246 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
1247 [[nodiscard]] bool isEmpty() const override;
1248
1249 /**
1250 Returns the control message type.
1251 */
1252 [[nodiscard]] QByteArray controlType() const;
1253
1254 /**
1255 Returns the control message parameter.
1256 */
1257 [[nodiscard]] QByteArray parameter() const;
1258
1259 /**
1260 Returns true if this is a cancel control message.
1261 @see RFC 1036, section 3.1.
1262 */
1263 [[nodiscard]] bool isCancel() const;
1264
1265 /**
1266 Changes this header into a cancel control message for the given message-id.
1267 @param msgid The message-id of the article that should be canceled.
1268 */
1269 void setCancel(const QByteArray &msgid);
1270
1271protected:
1272 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
1273
1274private:
1275 Q_DECLARE_PRIVATE(Control)
1276};
1277
1278class DatePrivate;
1279
1280/**
1281 Represents a "Date" header.
1282
1283 @see RFC 2822, section 3.3.
1284*/
1285class KMIME_EXPORT Date : public Generics::Structured
1286{
1287 //@cond PRIVATE
1288 kmime_mk_trivial_ctor_with_name(Date)
1289 //@endcond
1290public:
1291 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
1292 [[nodiscard]] bool isEmpty() const override;
1293
1294 /**
1295 Returns the date contained in this header.
1296 */
1297 [[nodiscard]] QDateTime dateTime() const;
1298
1299 /**
1300 Sets the date.
1301 */
1302 void setDateTime(const QDateTime &dt);
1303
1304protected:
1305 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
1306
1307private:
1308 Q_DECLARE_PRIVATE(Date)
1309};
1310
1311class NewsgroupsPrivate;
1312
1313/**
1314 Represents a "Newsgroups" header.
1315
1316 @see RFC 1036, section 2.1.3.
1317*/
1318class KMIME_EXPORT Newsgroups : public Generics::Structured
1319{
1320 //@cond PRIVATE
1321 kmime_mk_trivial_ctor_with_name(Newsgroups)
1322 //@endcond
1323public:
1324 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
1325 void fromUnicodeString(const QString &s) override;
1326 using Base::fromUnicodeString;
1327 [[nodiscard]] QString asUnicodeString() const override;
1328 [[nodiscard]] bool isEmpty() const override;
1329
1330 /**
1331 Returns the list of newsgroups.
1332 */
1333 [[nodiscard]] QList<QByteArray> groups() const;
1334
1335 /**
1336 Sets the newsgroup list.
1337 */
1338 void setGroups(const QList<QByteArray> &groups);
1339
1340 /**
1341 Returns true if this message has been cross-posted, i.e. if it has been
1342 posted to multiple groups.
1343 */
1344 [[nodiscard]] bool isCrossposted() const;
1345
1346protected:
1347 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
1348
1349private:
1350 Q_DECLARE_PRIVATE(Newsgroups)
1351};
1352
1353/**
1354 Represents a "Followup-To" header.
1355
1356 @see RFC 1036, section 2.2.3.
1357*/
1358class KMIME_EXPORT FollowUpTo : public Newsgroups
1359{
1360 //@cond PRIVATE
1361 kmime_mk_trivial_ctor_with_name(FollowUpTo)
1362 //@endcond
1363};
1364
1365class LinesPrivate;
1366
1367/**
1368 Represents a "Lines" header.
1369
1370 @see RFC 1036, section 2.2.12.
1371*/
1372class KMIME_EXPORT Lines : public Generics::Structured
1373{
1374 //@cond PRIVATE
1375 kmime_mk_trivial_ctor_with_name(Lines)
1376 //@endcond
1377public:
1378 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
1379 [[nodiscard]] QString asUnicodeString() const override;
1380 [[nodiscard]] bool isEmpty() const override;
1381
1382 /**
1383 Returns the number of lines, undefined if isEmpty() returns true.
1384 */
1385 [[nodiscard]] int numberOfLines() const;
1386
1387 /**
1388 Sets the number of lines to @p lines.
1389 */
1390 void setNumberOfLines(int lines);
1391
1392protected:
1393 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
1394
1395private:
1396 Q_DECLARE_PRIVATE(Lines)
1397};
1398
1399/**
1400 Represents a "User-Agent" header.
1401*/
1402class KMIME_EXPORT UserAgent : public Generics::Unstructured
1403{
1404 kmime_mk_trivial_ctor_with_name(UserAgent)
1405};
1406
1407/** Creates a header based on @param type. If @param type is a known header type,
1408 * the right object type will be created, otherwise a null pointer is returned. */
1409[[nodiscard]] KMIME_EXPORT Base *createHeader(QByteArrayView type);
1410
1411} //namespace Headers
1412
1413} //namespace KMime
1414
1415// undefine code generation macros again
1416#undef kmime_mk_trivial_ctor
1417#undef kmime_mk_dptr_ctor
1418#undef kmime_mk_trivial_ctor_with_name
1419
1420Q_DECLARE_METATYPE(KMime::Headers::To*)
1421Q_DECLARE_METATYPE(KMime::Headers::Cc*)
1422Q_DECLARE_METATYPE(KMime::Headers::Bcc*)
1423
Baseclass of all header-classes.
Definition headers.h:97
virtual QByteArray as7BitString(bool withHeaderType=true) const =0
Returns the encoded header.
QList< KMime::Headers::Base * > List
A vector of headers.
Definition headers.h:102
virtual void from7BitString(QByteArrayView s)=0
Parses the given string.
virtual void fromUnicodeString(const QString &s)=0
Parses the given Unicode representation of the header content.
virtual QString asUnicodeString() const =0
Returns the decoded content of the header without the header-type.
virtual bool isEmpty() const =0
Checks if this header contains any data.
Represents a "Bcc" header.
Definition headers.h:781
Represents a "Cc" header.
Definition headers.h:771
Represents a "Content-Description" header.
Definition headers.h:1220
Represents a "Content-Disposition" header.
Definition headers.h:1125
Represents a "Content-ID" header.
Definition headers.h:921
Represents a "Content-Location" header.
Definition headers.h:1229
Represents a "Content-Transfer-Encoding" header.
Definition headers.h:848
Represents a "Content-Type" header.
Definition headers.h:969
Represents a "Control" header.
Definition headers.h:1241
Represents a "Date" header.
Definition headers.h:1286
Represents a "Followup-To" header.
Definition headers.h:1359
Represent a "From" header.
Definition headers.h:741
Represents an arbitrary header, that can contain any header-field.
Definition headers.h:1180
Base class for headers that deal with (possibly multiple) addresses, allowing groups.
Definition headers.h:404
Base class for headers containing a dot atom.
Definition headers.h:611
Base class for headers which deal with a list of msg-id's.
Definition headers.h:475
Base class for headers that deal with (possibly multiple) addresses, but don't allow groups.
Definition headers.h:308
Base class for headers containing a parameter list such as "Content-Type".
Definition headers.h:633
Base class for headers containing a list of phrases.
Definition headers.h:584
Base class for headers which deal with a single msg-id.
Definition headers.h:518
Base class for headers that deal with exactly one mailbox (e.g.
Definition headers.h:380
Base class for structured header fields.
Definition headers.h:269
virtual bool parse(const char *&scursor, const char *const send, bool isCRLF=false)=0
This method parses the raw header and needs to be implemented in every sub-class.
Base class for headers which deal with a single atom.
Definition headers.h:552
Abstract base class for unstructured header fields (e.g.
Definition headers.h:215
Represents a "In-Reply-To" header.
Definition headers.h:947
Represents a "Keywords" header.
Definition headers.h:879
Represents a "Lines" header.
Definition headers.h:1373
Represents a "MIME-Version" header.
Definition headers.h:891
Represents a "Mail-Copies-To" header.
Definition headers.h:803
Represents a "Message-ID" header.
Definition headers.h:903
Represents a "Newsgroups" header.
Definition headers.h:1319
Represents a "Organization" header.
Definition headers.h:1212
Represents a "References" header.
Definition headers.h:957
Represents a "ReplyTo" header.
Definition headers.h:791
Represents the Return-Path header field.
Definition headers.h:717
Represents a "Sender" header.
Definition headers.h:751
Represents a "Subject" header.
Definition headers.h:1202
Represents a "Supersedes" header.
Definition headers.h:937
Represents a "To" header.
Definition headers.h:761
Represents a "User-Agent" header.
Definition headers.h:1403
Represents an (email address, display name) pair according RFC 2822, section 3.4.
Definition types.h:38
Base * createHeader(QByteArrayView type)
Creates a header based on.
Definition headers.cpp:2008
contentEncoding
Various possible values for the "Content-Transfer-Encoding" header.
Definition headers.h:52
@ CE8Bit
8bit
Definition headers.h:54
@ CEbase64
base64
Definition headers.h:56
@ CE7Bit
7bit
Definition headers.h:53
@ CEbinary
binary
Definition headers.h:58
@ CEquPr
quoted-printable
Definition headers.h:55
@ CEuuenc
uuencode
Definition headers.h:57
contentDisposition
Various possible values for the "Content-Disposition" header.
Definition headers.h:64
@ CDInvalid
Default, invalid value.
Definition headers.h:65
@ CDattachment
attachment
Definition headers.h:67
@ CDinline
inline
Definition headers.h:66
@ CDparallel
parallel (invalid, do not use)
Definition headers.h:68
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.