KMime

types.h
1/* -*- c++ -*-
2 kmime_header_types.h
3
4 KMime, the KDE Internet mail/usenet news message library.
5 SPDX-FileCopyrightText: 2001-2002 Marc Mutz <mutz@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#pragma once
11
12#include <QList>
13#include <QString>
14
15#include "kmime_export.h"
16
17namespace KMime
18{
19
20namespace Types
21{
22
23struct KMIME_EXPORT AddrSpec {
24 [[nodiscard]] QString asString() const;
25 /*! This is the same as asString(), except it decodes IDNs for display */
26 [[nodiscard]] QString asPrettyString() const;
27 [[nodiscard]] bool isEmpty() const;
28 QString localPart;
29 QString domain;
30};
31using AddrSpecList = QList<AddrSpec>;
32
33/**
34 Represents an (email address, display name) pair according RFC 2822,
35 section 3.4.
36*/
37class KMIME_EXPORT Mailbox
38{
39public:
40 typedef QList<Mailbox> List;
41
42 /**
43 Returns a string representation of the email address, without
44 the angle brackets.
45 */
46 [[nodiscard]] QByteArray address() const;
47
48 [[nodiscard]] AddrSpec addrSpec() const;
49
50 /**
51 Returns the display name.
52 */
53 [[nodiscard]] QString name() const;
54
55 /**
56 Sets the email address.
57 */
58 void setAddress(const AddrSpec &addr);
59
60 /**
61 Sets the email address.
62 */
63 void setAddress(const QByteArray &addr);
64
65 /**
66 Sets the name.
67 */
68 void setName(const QString &name);
69
70 /**
71 Sets the name based on a 7bit encoded string.
72 */
73 void setNameFrom7Bit(const QByteArray &name,
74 const QByteArray &defaultCharset = QByteArray());
75
76 /**
77 Returns true if this mailbox has an address.
78 */
79 [[nodiscard]] bool hasAddress() const;
80
81 /**
82 Returns true if this mailbox has a display name.
83 */
84 [[nodiscard]] bool hasName() const;
85
86 /**
87 * Describes how display names should be quoted
88 * @since 4.5
89 */
90 // AK_REVIEW: remove this enum
91 enum Quoting {
92 QuoteNever, ///< Don't quote display names at all. Such an unquoted display
93 ///< name can not
94 /// be machine-processed anymore in some cases, for example when it
95 /// contains commas, like in "Lastname, Firstname".
96 QuoteWhenNecessary, ///< Only quote display names when they contain
97 ///< characters that need to be
98 /// quoted, like commas or quote signs.
99 QuoteAlways ///< Always quote the display name
100 };
101
102 /**
103 * Overloaded method that gives more control over the quoting of the display
104 * name
105 * @param quoting describes how the display name should be quoted
106 * @since 4.5
107 */
108 [[nodiscard]] QString prettyAddress(Quoting quoting = QuoteNever) const;
109
110 /**
111 Parses the given unicode string.
112 */
113 void fromUnicodeString(QStringView s);
114
115 /**
116 Parses the given 7bit encoded string.
117 */
118 void from7BitString(QByteArrayView s);
119
120 /**
121 Returns a 7bit transport encoded representation of this mailbox.
122
123 @param encCharset The charset used for encoding.
124 */
125 [[nodiscard]] QByteArray as7BitString(const QByteArray &encCharset) const;
126
127 /**
128 * Returns a list of mailboxes from an unicode string.
129 *
130 * @since 5.14
131 */
132 [[nodiscard]] static QList<Mailbox> listFromUnicodeString(QStringView s);
133
134 /**
135 * Returns a list of mailboxes from an encoded 7bit string.
136 *
137 * @since 5.14
138 */
139 [[nodiscard]] static QList<Mailbox> listFrom7BitString(QByteArrayView s);
140
141 /**
142 * Returns a unicode string representing the given list of mailboxes.
143 *
144 * @since 5.15
145 */
146 [[nodiscard]] static QString
147 listToUnicodeString(const QList<Mailbox> &mailboxes);
148
149private:
150 QString mDisplayName;
151 AddrSpec mAddrSpec;
152};
153
154typedef QList<Mailbox> MailboxList;
155
156struct KMIME_EXPORT Address {
157 QString displayName;
158 MailboxList mailboxList;
159};
160typedef QList<Address> AddressList;
161
162} // namespace KMime::Types
163
164} // namespace KMime
165
166Q_DECLARE_TYPEINFO(KMime::Types::Mailbox, Q_RELOCATABLE_TYPE);
167Q_DECLARE_TYPEINFO(KMime::Types::Address, Q_RELOCATABLE_TYPE);
168Q_DECLARE_TYPEINFO(KMime::Types::AddrSpec, Q_RELOCATABLE_TYPE);
169
170
Represents an (email address, display name) pair according RFC 2822, section 3.4.
Definition types.h:38
Quoting
Describes how display names should be quoted.
Definition types.h:91
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.