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

KDE's Doxygen guidelines are available online.