KMime

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

KDE's Doxygen guidelines are available online.