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