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 Structured
380{
381 //@cond PRIVATE
382 kmime_mk_trivial_ctor(SingleMailbox)
383 //@endcond
384public:
385 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
386 void fromUnicodeString(const QString &s) override;
387 using Base::fromUnicodeString;
388 [[nodiscard]] QString asUnicodeString() const override;
389 [[nodiscard]] bool isEmpty() const override;
390
391 /**
392 Returns the mailbox in this header.
393 @since 25.04
394 */
395 [[nodiscard]] Types::Mailbox mailbox() const;
396
397 /**
398 Sets the mailboxes in this header, replacing the current content.
399 @since 25.04
400 */
401 void setMailbox(const Types::Mailbox &mailbox);
402
403protected:
404 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
405
406private:
407 Q_DECLARE_PRIVATE(SingleMailbox)
408};
409
410class AddressListPrivate;
411
412/**
413 Base class for headers that deal with (possibly multiple)
414 addresses, allowing groups.
415
416 Note: Groups are parsed but not represented in the API yet. All addresses in
417 groups are listed as if they would not be part of a group.
418
419 @todo Add API for groups?
420
421 @see RFC 2822, section 3.4
422*/
423class KMIME_EXPORT AddressList : public Structured
424{
425 //@cond PRIVATE
426 kmime_mk_trivial_ctor(AddressList)
427 kmime_mk_dptr_ctor(AddressList)
428 //@endcond
429public:
430 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
431 void fromUnicodeString(const QString &s) override;
432 using Base::fromUnicodeString;
433 [[nodiscard]] QString asUnicodeString() const override;
434
435 [[nodiscard]] bool isEmpty() const override;
436
437 /**
438 Adds an address to this header.
439
440 @param mbox A Mailbox object specifying the address.
441 */
442 void addAddress(const Types::Mailbox &mbox);
443
444 /**
445 Adds an address to this header.
446 @param address The actual email address, with or without angle brackets.
447 @param displayName An optional name associated with the address.
448 */
449 void addAddress(const QByteArray &address, const QString &displayName = QString());
450
451 /**
452 Returns a list of all addresses in this header, regardless of groups.
453 */
454 [[nodiscard]] QList<QByteArray> addresses() const;
455
456 /**
457 Returns a list of all display names associated with the addresses in this header.
458 The address is added for addresses that don't have a display name.
459 */
460 [[nodiscard]] QStringList displayNames() const;
461
462 /**
463 Returns a single string for user-facing display of this address list.
464 This is equivalent to displayNames().join(", ").
465 @since 5.14
466 */
467 [[nodiscard]] QString displayString() const;
468
469 /**
470 Returns a list of mailboxes listed in this header.
471 */
472 [[nodiscard]] Types::Mailbox::List mailboxes() const;
473
474 /**
475 Sets the list of addresses listed in this header, replacing the existing content.
476 @since 24.12
477 */
478 void setAddressList(const Types::AddressList &addresses);
479
480protected:
481 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
482
483private:
484 Q_DECLARE_PRIVATE(AddressList)
485};
486
487class IdentPrivate;
488
489/**
490 Base class for headers which deal with a list of msg-id's.
491
492 @see RFC 2822, section 3.6.4
493*/
494class KMIME_EXPORT Ident : public Structured
495{
496 //@cond PRIVATE
497 kmime_mk_trivial_ctor(Ident)
498 kmime_mk_dptr_ctor(Ident)
499 //@endcond
500public:
501 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
502 [[nodiscard]] bool isEmpty() const override;
503
504 /**
505 Initialize this identifier Copy the data from
506 */
507 void fromIdent(const Ident* ident);
508
509 /**
510 Returns the list of identifiers contained in this header.
511 Note:
512 - Identifiers are not enclosed in angle-brackets.
513 - Identifiers are listed in the same order as in the header.
514 */
515 [[nodiscard]] QList<QByteArray> identifiers() const;
516
517 /**
518 Appends a new identifier to this header.
519 @param id The identifier to append, with or without angle-brackets.
520 */
521 void appendIdentifier(const QByteArray &id);
522
523protected:
524 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
525
526private:
527 Q_DECLARE_PRIVATE(Ident)
528};
529
530class SingleIdentPrivate;
531
532/**
533 Base class for headers which deal with a single msg-id.
534
535 @see RFC 2822, section 3.6.4
536*/
537class KMIME_EXPORT SingleIdent : public Structured
538{
539 //@cond PRIVATE
540 kmime_mk_trivial_ctor(SingleIdent)
541 kmime_mk_dptr_ctor(SingleIdent)
542 //@endcond
543public:
544 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
545 [[nodiscard]] bool isEmpty() const override;
546
547 /**
548 Returns the identifier contained in this header.
549 Note: The identifiers is not enclosed in angle-brackets.
550 */
551 [[nodiscard]] QByteArray identifier() const;
552
553 /**
554 Sets the identifier.
555 @param id The new identifier with or without angle-brackets.
556 */
557 void setIdentifier(const QByteArray &id);
558
559protected:
560 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
561
562private:
563 Q_DECLARE_PRIVATE(SingleIdent)
564};
565
566class TokenPrivate;
567
568/**
569 Base class for headers which deal with a single atom.
570*/
571class KMIME_EXPORT Token : public Structured
572{
573 //@cond PRIVATE
574 kmime_mk_trivial_ctor(Token)
575 kmime_mk_dptr_ctor(Token)
576 //@endcond
577public:
578 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
579 [[nodiscard]] bool isEmpty() const override;
580
581 /**
582 Returns the token.
583 */
584 [[nodiscard]] QByteArray token() const;
585
586 /**
587 Sets the token to @p t,
588 */
589 void setToken(const QByteArray &t);
590
591protected:
592 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
593
594private:
595 Q_DECLARE_PRIVATE(Token)
596};
597
598class PhraseListPrivate;
599
600/**
601 Base class for headers containing a list of phrases.
602*/
603class KMIME_EXPORT PhraseList : public Structured
604{
605 //@cond PRIVATE
606 kmime_mk_trivial_ctor(PhraseList)
607 //@endcond
608public:
609 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
610 [[nodiscard]] QString asUnicodeString() const override;
611 [[nodiscard]] bool isEmpty() const override;
612
613 /**
614 Returns the list of phrases contained in this header.
615 */
616 [[nodiscard]] QStringList phrases() const;
617
618protected:
619 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
620
621private:
622 Q_DECLARE_PRIVATE(PhraseList)
623};
624
625class DotAtomPrivate;
626
627/**
628 Base class for headers containing a dot atom.
629*/
630class KMIME_EXPORT DotAtom : public Structured
631{
632 //@cond PRIVATE
633 kmime_mk_trivial_ctor(DotAtom)
634 //@endcond
635public:
636 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
637 [[nodiscard]] QString asUnicodeString() const override;
638 [[nodiscard]] bool isEmpty() const override;
639
640protected:
641 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
642
643private:
644 Q_DECLARE_PRIVATE(DotAtom)
645};
646
647class ParametrizedPrivate;
648
649/**
650 Base class for headers containing a parameter list such as "Content-Type".
651*/
652class KMIME_EXPORT Parametrized : public Structured
653{
654 //@cond PRIVATE
655 kmime_mk_trivial_ctor(Parametrized)
656 kmime_mk_dptr_ctor(Parametrized)
657 //@endcond
658public:
659 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
660
661 [[nodiscard]] bool isEmpty() const override;
662
663 /**
664 Returns the value of the specified parameter.
665 @param key The parameter name.
666 */
667 [[nodiscard]] QString parameter(QByteArrayView key) const;
668 [[deprecated("use QByteArrayView as argument")]] [[nodiscard]] inline QString parameter(const QString &key) const
669 {
670 return parameter(QByteArrayView(key.toUtf8()));
671 }
672 [[deprecated("use QByteArrayView as argument")]] [[nodiscard]] inline QString parameter(QLatin1StringView key) const
673 {
674 return parameter(QByteArrayView(key));
675 }
676 // overload resolution helper, remove once the above deprecated overloads are removed
677 template <std::size_t N>
678 [[nodiscard]] inline QString parameter(const char (&key)[N]) const
679 {
680 return parameter(QByteArrayView(key, N));
681 }
682
683 /**
684 @param key the key of the parameter to check for
685 @return true if a parameter with the given @p key exists.
686 @since 4.5
687 */
688 [[nodiscard]] bool hasParameter(QByteArrayView key) const;
689 [[deprecated("use QByteArrayView as argument")]] [[nodiscard]] inline bool hasParameter(const QString &key) const
690 {
691 return hasParameter(QByteArrayView(key.toUtf8()));
692 }
693 [[deprecated("use QByteArrayView as argument")]] [[nodiscard]] inline bool hasParameter(QLatin1StringView key) const
694 {
695 return hasParameter(QByteArrayView(key));
696 }
697 // overload resolution helper, remove once the above deprecated overloads are removed
698 template <std::size_t N>
699 [[nodiscard]] inline bool hasParameter(const char (&key)[N]) const {
700 return hasParameter(QByteArrayView(key, N));
701 }
702
703 /**
704 Sets the parameter @p key to @p value.
705 @param key The parameter name.
706 @param value The new value for @p key.
707 */
708 void setParameter(const QByteArray &key, const QString &value);
709 [[deprecated("use a QByteArray[Literal] key")]] inline void setParameter(const QString &key, const QString &value)
710 {
711 return setParameter(key.toUtf8(), value);
712 }
713
714protected:
715 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
716
717private:
718 Q_DECLARE_PRIVATE(Parametrized)
719};
720
721} // namespace Generics
722
723//
724//
725// INCOMPATIBLE, GSTRUCTURED-BASED FIELDS:
726//
727//
728
729class ReturnPathPrivate;
730
731/**
732 Represents the Return-Path header field.
733
734 @see RFC 2822, section 3.6.7
735*/
736class KMIME_EXPORT ReturnPath : public Generics::Structured
737{
738 //@cond PRIVATE
739 kmime_mk_trivial_ctor_with_name(ReturnPath)
740 //@endcond
741public:
742 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
743 [[nodiscard]] bool isEmpty() const override;
744
745protected:
746 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
747
748private:
749 Q_DECLARE_PRIVATE(ReturnPath)
750};
751
752// Address et al.:
753
754// rfc(2)822 headers:
755/**
756 Represent a "From" header.
757
758 @see RFC 2822, section 3.6.2.
759*/
760class KMIME_EXPORT From : public Generics::MailboxList
761{
762 kmime_mk_trivial_ctor_with_name(From)
763};
764
765/**
766 Represents a "Sender" header.
767
768 @see RFC 2822, section 3.6.2.
769*/
770class KMIME_EXPORT Sender : public Generics::SingleMailbox
771{
772 kmime_mk_trivial_ctor_with_name(Sender)
773};
774
775/**
776 Represents a "To" header.
777
778 @see RFC 2822, section 3.6.3.
779*/
780class KMIME_EXPORT To : public Generics::AddressList
781{
782 kmime_mk_trivial_ctor_with_name(To)
783};
784
785/**
786 Represents a "Cc" header.
787
788 @see RFC 2822, section 3.6.3.
789*/
790class KMIME_EXPORT Cc : public Generics::AddressList
791{
792 kmime_mk_trivial_ctor_with_name(Cc)
793};
794
795/**
796 Represents a "Bcc" header.
797
798 @see RFC 2822, section 3.6.3.
799*/
800class KMIME_EXPORT Bcc : public Generics::AddressList
801{
802 kmime_mk_trivial_ctor_with_name(Bcc)
803};
804
805/**
806 Represents a "ReplyTo" header.
807
808 @see RFC 2822, section 3.6.2.
809*/
810class KMIME_EXPORT ReplyTo : public Generics::AddressList
811{
812 kmime_mk_trivial_ctor_with_name(ReplyTo)
813};
814
815class MailCopiesToPrivate;
816
817/**
818 Represents a "Mail-Copies-To" header.
819
820 @see http://www.newsreaders.com/misc/mail-copies-to.html
821*/
822class KMIME_EXPORT MailCopiesTo : public Generics::AddressList
823{
824 //@cond PRIVATE
825 kmime_mk_trivial_ctor_with_name(MailCopiesTo)
826 //@endcond
827public:
828 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
829 [[nodiscard]] QString asUnicodeString() const override;
830
831 [[nodiscard]] bool isEmpty() const override;
832
833 /**
834 Returns true if a mail copy was explicitly requested.
835 */
836 [[nodiscard]] bool alwaysCopy() const;
837
838 /**
839 Sets the header to "poster".
840 */
841 void setAlwaysCopy();
842
843 /**
844 Returns true if a mail copy was explicitly denied.
845 */
846 [[nodiscard]] bool neverCopy() const;
847
848 /**
849 Sets the header to "never".
850 */
851 void setNeverCopy();
852
853protected:
854 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
855
856private:
857 Q_DECLARE_PRIVATE(MailCopiesTo)
858};
859
860class ContentTransferEncodingPrivate;
861
862/**
863 Represents a "Content-Transfer-Encoding" header.
864
865 @see RFC 2045, section 6.
866*/
867class KMIME_EXPORT ContentTransferEncoding : public Generics::Token
868{
869 //@cond PRIVATE
870 kmime_mk_trivial_ctor_with_name(ContentTransferEncoding)
871 //@endcond
872public:
873 [[nodiscard]] bool isEmpty() const override;
874 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
875
876 /**
877 Returns the encoding specified in this header.
878 */
879 [[nodiscard]] contentEncoding encoding() const;
880
881 /**
882 Sets the encoding to @p e.
883 */
884 void setEncoding(contentEncoding e);
885
886protected:
887 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
888
889private:
890 Q_DECLARE_PRIVATE(ContentTransferEncoding)
891};
892
893/**
894 Represents a "Keywords" header.
895
896 @see RFC 2822, section 3.6.5.
897*/
898class KMIME_EXPORT Keywords : public Generics::PhraseList
899{
900 kmime_mk_trivial_ctor_with_name(Keywords)
901};
902
903// DotAtom:
904
905/**
906 Represents a "MIME-Version" header.
907
908 @see RFC 2045, section 4.
909*/
910class KMIME_EXPORT MIMEVersion : public Generics::DotAtom
911{
912 kmime_mk_trivial_ctor_with_name(MIMEVersion)
913};
914
915// Ident:
916
917/**
918 Represents a "Message-ID" header.
919
920 @see RFC 2822, section 3.6.4.
921*/
922class KMIME_EXPORT MessageID : public Generics::SingleIdent
923{
924 //@cond PRIVATE
925 kmime_mk_trivial_ctor_with_name(MessageID)
926 //@endcond
927public:
928 /**
929 Generate a message identifier.
930 @param fqdn A fully qualified domain name.
931 */
932 void generate(const QByteArray &fqdn);
933};
934
935class ContentIDPrivate;
936
937/**
938 Represents a "Content-ID" header.
939*/
940class KMIME_EXPORT ContentID : public Generics::SingleIdent
941{
942 //@cond PRIVATE
943 kmime_mk_trivial_ctor_with_name(ContentID)
944 kmime_mk_dptr_ctor(ContentID)
945 //@endcond
946
947protected:
948 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
949private:
950 Q_DECLARE_PRIVATE(ContentID)
951};
952
953/**
954 Represents a "Supersedes" header.
955*/
956class KMIME_EXPORT Supersedes : public Generics::SingleIdent
957{
958 kmime_mk_trivial_ctor_with_name(Supersedes)
959};
960
961/**
962 Represents a "In-Reply-To" header.
963
964 @see RFC 2822, section 3.6.4.
965*/
966class KMIME_EXPORT InReplyTo : public Generics::Ident
967{
968 kmime_mk_trivial_ctor_with_name(InReplyTo)
969};
970
971/**
972 Represents a "References" header.
973
974 @see RFC 2822, section 3.6.4.
975*/
976class KMIME_EXPORT References : public Generics::Ident
977{
978 kmime_mk_trivial_ctor_with_name(References)
979};
980
981class ContentTypePrivate;
982
983/**
984 Represents a "Content-Type" header.
985
986 @see RFC 2045, section 5.
987*/
988class KMIME_EXPORT ContentType : public Generics::Parametrized
989{
990 //@cond PRIVATE
991 kmime_mk_trivial_ctor_with_name(ContentType)
992 //@endcond
993public:
994 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
995 [[nodiscard]] bool isEmpty() const override;
996
997 /**
998 Returns the mimetype.
999 */
1000 [[nodiscard]] QByteArray mimeType() const;
1001
1002 /**
1003 Returns the media type (first part of the mimetype).
1004 */
1005
1006 [[nodiscard]] QByteArray mediaType() const;
1007
1008 /**
1009 Returns the mime sub-type (second part of the mimetype).
1010 */
1011 [[nodiscard]] QByteArray subType() const;
1012
1013 /**
1014 Sets the mimetype.
1015 @param mimeType The new mimetype.
1016 */
1017 void setMimeType(const QByteArray &mimeType);
1018
1019 /**
1020 Tests if the media type equals @p mediatype.
1021 */
1022 [[nodiscard]] bool isMediatype(const char *mediatype) const;
1023
1024 /**
1025 Tests if the mime sub-type equals @p subtype.
1026 */
1027 [[nodiscard]] bool isSubtype(const char *subtype) const;
1028
1029 /**
1030 Tests if the mime type is @p mimeType.
1031 */
1032 [[nodiscard]] bool isMimeType(const char *mimeType) const;
1033
1034 /**
1035 Returns true if the associated MIME entity is a text.
1036 */
1037 [[nodiscard]] bool isText() const;
1038
1039 /**
1040 Returns true if the associated MIME entity is a plain text.
1041 */
1042 [[nodiscard]] bool isPlainText() const;
1043
1044 /**
1045 Returns true if the associated MIME entity is a HTML file.
1046 */
1047 [[nodiscard]] bool isHTMLText() const;
1048
1049 /**
1050 Returns true if the associated MIME entity is an image.
1051 */
1052 [[nodiscard]] bool isImage() const;
1053
1054 /**
1055 Returns true if the associated MIME entity is a multipart container.
1056 */
1057 [[nodiscard]] bool isMultipart() const;
1058
1059 /**
1060 Returns true if the associated MIME entity contains partial data.
1061 @see partialNumber(), partialCount()
1062 */
1063 [[nodiscard]] bool isPartial() const;
1064
1065 /**
1066 Returns the charset for the associated MIME entity.
1067 */
1068 [[nodiscard]] QByteArray charset() const;
1069
1070 /**
1071 Sets the charset.
1072 */
1073 void setCharset(const QByteArray &s);
1074
1075 /**
1076 Returns the boundary (for multipart containers).
1077 */
1078 [[nodiscard]] QByteArray boundary() const;
1079
1080 /**
1081 Sets the multipart container boundary.
1082 */
1083 void setBoundary(const QByteArray &s);
1084
1085 /**
1086 Returns the name of the associated MIME entity.
1087 */
1088 [[nodiscard]] QString name() const;
1089
1090 /**
1091 Sets the name to @p s.
1092 */
1093 void setName(const QString &s);
1094 [[deprecated("call setRFC2047Charset for the second argument if different from UTF-8, otherwise remove second argument")]]
1095 inline void setName(const QString &s, const QByteArray &cs)
1096 {
1097 setRFC2047Charset(cs);
1098 setName(s);
1099 }
1100
1101 /**
1102 Returns the identifier of the associated MIME entity.
1103 */
1104 [[nodiscard]] QByteArray id() const;
1105
1106 /**
1107 Sets the identifier.
1108 */
1109 void setId(const QByteArray &s);
1110
1111 /**
1112 Returns the position of this part in a multi-part set.
1113 @see isPartial(), partialCount()
1114 */
1115 [[nodiscard]] int partialNumber() const;
1116
1117 /**
1118 Returns the total number of parts in a multi-part set.
1119 @see isPartial(), partialNumber()
1120 */
1121 [[nodiscard]] int partialCount() const;
1122
1123 /**
1124 Sets parameters of a partial MIME entity.
1125 @param total The total number of entities in the multi-part set.
1126 @param number The number of this entity in a multi-part set.
1127 */
1128 void setPartialParams(int total, int number);
1129
1130protected:
1131 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
1132
1133private:
1134 Q_DECLARE_PRIVATE(ContentType)
1135};
1136
1137class ContentDispositionPrivate;
1138
1139/**
1140 Represents a "Content-Disposition" header.
1141
1142 @see RFC 2183
1143*/
1145{
1146 //@cond PRIVATE
1147 kmime_mk_trivial_ctor_with_name(ContentDisposition)
1148 //@endcond
1149public:
1150 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
1151 [[nodiscard]] bool isEmpty() const override;
1152
1153 /**
1154 Returns the content disposition.
1155 */
1156 [[nodiscard]] contentDisposition disposition() const;
1157
1158 /**
1159 Sets the content disposition.
1160 @param disp The new content disposition.
1161 */
1162 void setDisposition(contentDisposition disp);
1163
1164 /**
1165 Returns the suggested filename for the associated MIME part.
1166 This is just a convenience function, it is equivalent to calling
1167 parameter( "filename" );
1168 */
1169 [[nodiscard]] QString filename() const;
1170
1171 /**
1172 Sets the suggested filename for the associated MIME part.
1173 This is just a convenience function, it is equivalent to calling
1174 setParameter( "filename", filename );
1175 @param filename The filename.
1176 */
1177 void setFilename(const QString &filename);
1178
1179protected:
1180 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
1181
1182private:
1183 Q_DECLARE_PRIVATE(ContentDisposition)
1184};
1185
1186//
1187//
1188// COMPATIBLE GUNSTRUCTURED-BASED FIELDS:
1189//
1190//
1191
1192class GenericPrivate;
1193
1194/**
1195 Represents an arbitrary header, that can contain any header-field.
1196 Adds a type over Unstructured.
1197 @see Unstructured
1198*/
1199class KMIME_EXPORT Generic : public Generics::Unstructured
1200{
1201public:
1202 Generic();
1203 Generic(const char *t, qsizetype len = -1);
1204 ~Generic() override;
1205
1206 [[nodiscard]] bool isEmpty() const override;
1207
1208 [[nodiscard]] const char *type() const override;
1209
1210 void setType(const char *type, qsizetype len = -1);
1211
1212private:
1213 Q_DECLARE_PRIVATE(Generic)
1214};
1215
1216/**
1217 Represents a "Subject" header.
1218
1219 @see RFC 2822, section 3.6.5.
1220*/
1221class KMIME_EXPORT Subject : public Generics::Unstructured
1222{
1223 //@cond PRIVATE
1224 kmime_mk_trivial_ctor_with_name(Subject)
1225 //@endcond
1226};
1227
1228/**
1229 Represents a "Organization" header.
1230*/
1231class KMIME_EXPORT Organization : public Generics::Unstructured
1232{
1233 kmime_mk_trivial_ctor_with_name(Organization)
1234};
1235
1236/**
1237 Represents a "Content-Description" header.
1238*/
1240{
1241 kmime_mk_trivial_ctor_with_name(ContentDescription)
1242};
1243
1244/**
1245 Represents a "Content-Location" header.
1246 @since 4.2
1247*/
1248class KMIME_EXPORT ContentLocation : public Generics::Unstructured
1249{
1250 kmime_mk_trivial_ctor_with_name(ContentLocation)
1251};
1252
1253class ControlPrivate;
1254
1255/**
1256 Represents a "Control" header.
1257
1258 @see RFC 1036, section 3.
1259*/
1260class KMIME_EXPORT Control : public Generics::Structured
1261{
1262 //@cond PRIVATE
1263 kmime_mk_trivial_ctor_with_name(Control)
1264 //@endcond
1265public:
1266 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
1267 [[nodiscard]] bool isEmpty() const override;
1268
1269 /**
1270 Returns the control message type.
1271 */
1272 [[nodiscard]] QByteArray controlType() const;
1273
1274 /**
1275 Returns the control message parameter.
1276 */
1277 [[nodiscard]] QByteArray parameter() const;
1278
1279 /**
1280 Returns true if this is a cancel control message.
1281 @see RFC 1036, section 3.1.
1282 */
1283 [[nodiscard]] bool isCancel() const;
1284
1285 /**
1286 Changes this header into a cancel control message for the given message-id.
1287 @param msgid The message-id of the article that should be canceled.
1288 */
1289 void setCancel(const QByteArray &msgid);
1290
1291protected:
1292 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
1293
1294private:
1295 Q_DECLARE_PRIVATE(Control)
1296};
1297
1298class DatePrivate;
1299
1300/**
1301 Represents a "Date" header.
1302
1303 @see RFC 2822, section 3.3.
1304*/
1305class KMIME_EXPORT Date : public Generics::Structured
1306{
1307 //@cond PRIVATE
1308 kmime_mk_trivial_ctor_with_name(Date)
1309 //@endcond
1310public:
1311 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
1312 [[nodiscard]] bool isEmpty() const override;
1313
1314 /**
1315 Returns the date contained in this header.
1316 */
1317 [[nodiscard]] QDateTime dateTime() const;
1318
1319 /**
1320 Sets the date.
1321 */
1322 void setDateTime(const QDateTime &dt);
1323
1324protected:
1325 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
1326
1327private:
1328 Q_DECLARE_PRIVATE(Date)
1329};
1330
1331class NewsgroupsPrivate;
1332
1333/**
1334 Represents a "Newsgroups" header.
1335
1336 @see RFC 1036, section 2.1.3.
1337*/
1338class KMIME_EXPORT Newsgroups : public Generics::Structured
1339{
1340 //@cond PRIVATE
1341 kmime_mk_trivial_ctor_with_name(Newsgroups)
1342 //@endcond
1343public:
1344 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
1345 void fromUnicodeString(const QString &s) override;
1346 using Base::fromUnicodeString;
1347 [[nodiscard]] QString asUnicodeString() const override;
1348 [[nodiscard]] bool isEmpty() const override;
1349
1350 /**
1351 Returns the list of newsgroups.
1352 */
1353 [[nodiscard]] QList<QByteArray> groups() const;
1354
1355 /**
1356 Sets the newsgroup list.
1357 */
1358 void setGroups(const QList<QByteArray> &groups);
1359
1360 /**
1361 Returns true if this message has been cross-posted, i.e. if it has been
1362 posted to multiple groups.
1363 */
1364 [[nodiscard]] bool isCrossposted() const;
1365
1366protected:
1367 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
1368
1369private:
1370 Q_DECLARE_PRIVATE(Newsgroups)
1371};
1372
1373/**
1374 Represents a "Followup-To" header.
1375
1376 @see RFC 1036, section 2.2.3.
1377*/
1378class KMIME_EXPORT FollowUpTo : public Newsgroups
1379{
1380 //@cond PRIVATE
1381 kmime_mk_trivial_ctor_with_name(FollowUpTo)
1382 //@endcond
1383};
1384
1385class LinesPrivate;
1386
1387/**
1388 Represents a "Lines" header.
1389
1390 @see RFC 1036, section 2.2.12.
1391*/
1392class KMIME_EXPORT Lines : public Generics::Structured
1393{
1394 //@cond PRIVATE
1395 kmime_mk_trivial_ctor_with_name(Lines)
1396 //@endcond
1397public:
1398 [[nodiscard]] QByteArray as7BitString(bool withHeaderType = true) const override;
1399 [[nodiscard]] QString asUnicodeString() const override;
1400 [[nodiscard]] bool isEmpty() const override;
1401
1402 /**
1403 Returns the number of lines, undefined if isEmpty() returns true.
1404 */
1405 [[nodiscard]] int numberOfLines() const;
1406
1407 /**
1408 Sets the number of lines to @p lines.
1409 */
1410 void setNumberOfLines(int lines);
1411
1412protected:
1413 bool parse(const char *&scursor, const char *const send, bool isCRLF = false) override;
1414
1415private:
1416 Q_DECLARE_PRIVATE(Lines)
1417};
1418
1419/**
1420 Represents a "User-Agent" header.
1421*/
1422class KMIME_EXPORT UserAgent : public Generics::Unstructured
1423{
1424 kmime_mk_trivial_ctor_with_name(UserAgent)
1425};
1426
1427/** Creates a header based on @param type. If @param type is a known header type,
1428 * the right object type will be created, otherwise a null pointer is returned. */
1429[[nodiscard]] KMIME_EXPORT Base *createHeader(QByteArrayView type);
1430
1431} //namespace Headers
1432
1433} //namespace KMime
1434
1435// undefine code generation macros again
1436#undef kmime_mk_trivial_ctor
1437#undef kmime_mk_dptr_ctor
1438#undef kmime_mk_trivial_ctor_with_name
1439
1440Q_DECLARE_METATYPE(KMime::Headers::To*)
1441Q_DECLARE_METATYPE(KMime::Headers::Cc*)
1442Q_DECLARE_METATYPE(KMime::Headers::Bcc*)
1443
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:801
Represents a "Cc" header.
Definition headers.h:791
Represents a "Content-Description" header.
Definition headers.h:1240
Represents a "Content-Disposition" header.
Definition headers.h:1145
Represents a "Content-ID" header.
Definition headers.h:941
Represents a "Content-Location" header.
Definition headers.h:1249
Represents a "Content-Transfer-Encoding" header.
Definition headers.h:868
Represents a "Content-Type" header.
Definition headers.h:989
Represents a "Control" header.
Definition headers.h:1261
Represents a "Date" header.
Definition headers.h:1306
Represents a "Followup-To" header.
Definition headers.h:1379
Represent a "From" header.
Definition headers.h:761
Represents an arbitrary header, that can contain any header-field.
Definition headers.h:1200
Base class for headers that deal with (possibly multiple) addresses, allowing groups.
Definition headers.h:424
Base class for headers containing a dot atom.
Definition headers.h:631
Base class for headers which deal with a list of msg-id's.
Definition headers.h:495
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:653
Base class for headers containing a list of phrases.
Definition headers.h:604
Base class for headers which deal with a single msg-id.
Definition headers.h:538
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:572
Abstract base class for unstructured header fields (e.g.
Definition headers.h:215
Represents a "In-Reply-To" header.
Definition headers.h:967
Represents a "Keywords" header.
Definition headers.h:899
Represents a "Lines" header.
Definition headers.h:1393
Represents a "MIME-Version" header.
Definition headers.h:911
Represents a "Mail-Copies-To" header.
Definition headers.h:823
Represents a "Message-ID" header.
Definition headers.h:923
Represents a "Newsgroups" header.
Definition headers.h:1339
Represents a "Organization" header.
Definition headers.h:1232
Represents a "References" header.
Definition headers.h:977
Represents a "ReplyTo" header.
Definition headers.h:811
Represents the Return-Path header field.
Definition headers.h:737
Represents a "Sender" header.
Definition headers.h:771
Represents a "Subject" header.
Definition headers.h:1222
Represents a "Supersedes" header.
Definition headers.h:957
Represents a "To" header.
Definition headers.h:781
Represents a "User-Agent" header.
Definition headers.h:1423
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:2053
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 Sat Dec 21 2024 17:05:57 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.