KIdentityManagement

identity.h
1 /*
2  SPDX-FileCopyrightText: 2002-2004 Marc Mutz <[email protected]>
3  SPDX-FileCopyrightText: 2007 Tom Albers <[email protected]>
4  Author: Stefan Taferner <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #pragma once
10 
11 #include "kidentitymanagement_export.h"
12 #include "signature.h"
13 
14 #include <QHash>
15 #include <QString>
16 #include <QStringList>
17 #include <QVariant>
18 #include <QVector>
19 
20 namespace KIdentityManagement
21 {
22 class Identity;
23 }
24 class KConfigGroup;
25 class QDataStream;
26 class QMimeData;
27 
28 namespace KIdentityManagement
29 {
30 static const char s_uoid[] = "uoid";
31 static const char s_identity[] = "Identity";
32 static const char s_name[] = "Name";
33 static const char s_organization[] = "Organization";
34 static const char s_pgps[] = "PGP Signing Key";
35 static const char s_pgpe[] = "PGP Encryption Key";
36 static const char s_smimes[] = "SMIME Signing Key";
37 static const char s_smimee[] = "SMIME Encryption Key";
38 static const char s_prefcrypt[] = "Preferred Crypto Message Format";
39 static const char s_primaryEmail[] = "Email Address";
40 static const char s_replyto[] = "Reply-To Address";
41 static const char s_bcc[] = "Bcc";
42 static const char s_cc[] = "Cc";
43 static const char s_vcard[] = "VCardFile";
44 static const char s_transport[] = "Transport";
45 static const char s_fcc[] = "Fcc";
46 static const char s_drafts[] = "Drafts";
47 static const char s_templates[] = "Templates";
48 static const char s_dict[] = "Dictionary";
49 static const char s_xface[] = "X-Face";
50 static const char s_xfaceenabled[] = "X-FaceEnabled";
51 static const char s_face[] = "Face";
52 static const char s_faceenabled[] = "FaceEnabled";
53 static const char s_signature[] = "Signature";
54 static const char s_emailAliases[] = "Email Aliases";
55 static const char s_attachVcard[] = "Attach Vcard";
56 static const char s_autocorrectionLanguage[] = "Autocorrection Language";
57 static const char s_disabledFcc[] = "Disable Fcc";
58 static const char s_pgpautosign[] = "Pgp Auto Sign";
59 static const char s_pgpautoencrypt[] = "Pgp Auto Encrypt";
60 static const char s_defaultDomainName[] = "Default Domain";
61 static const char s_autocryptEnabled[] = "Autocrypt";
62 
63 KIDENTITYMANAGEMENT_EXPORT QDataStream &operator<<(QDataStream &stream, const KIdentityManagement::Identity &ident);
64 KIDENTITYMANAGEMENT_EXPORT QDataStream &operator>>(QDataStream &stream, KIdentityManagement::Identity &ident);
65 
66 /** User identity information */
67 class KIDENTITYMANAGEMENT_EXPORT Identity
68 {
69  // only the identity manager should be able to construct and
70  // destruct us, but then we get into problems with using
71  // QValueList<Identity> and especially qHeapSort().
72  friend class IdentityManager;
73 
74  friend KIDENTITYMANAGEMENT_EXPORT QDataStream &operator<<(QDataStream &stream, const KIdentityManagement::Identity &ident);
75  friend KIDENTITYMANAGEMENT_EXPORT QDataStream &operator>>(QDataStream &stream, KIdentityManagement::Identity &ident);
76 
77 public:
78  using List = QVector<Identity>;
79 
80  /** Constructor */
81  explicit Identity(const QString &id = QString(),
82  const QString &realName = QString(),
83  const QString &emailAddr = QString(),
84  const QString &organization = QString(),
85  const QString &replyToAddress = QString());
86 
87  /** used for comparison */
88  bool operator==(const Identity &other) const;
89 
90  /** used for comparison */
91  bool operator!=(const Identity &other) const;
92 
93  /** used for sorting */
94  bool operator<(const Identity &other) const;
95 
96  /** used for sorting */
97  bool operator>(const Identity &other) const;
98 
99  /** used for sorting */
100  bool operator<=(const Identity &other) const;
101 
102  /** used for sorting */
103  bool operator>=(const Identity &other) const;
104 
105  /** Tests if there are enough values set to allow mailing */
106  Q_REQUIRED_RESULT bool mailingAllowed() const;
107 
108  /** Identity/nickname for this collection */
109  Q_REQUIRED_RESULT QString identityName() const;
110 
111  /** Identity/nickname for this collection */
112  void setIdentityName(const QString &name);
113 
114  /** @return whether this identity is the default identity */
115  Q_REQUIRED_RESULT bool isDefault() const;
116 
117  /** Unique Object Identifier for this identity */
118  Q_REQUIRED_RESULT uint uoid() const;
119 
120  /** Full name of the user */
121  Q_REQUIRED_RESULT QString fullName() const;
122  void setFullName(const QString &);
123 
124  /** The user's organization (optional) */
125  Q_REQUIRED_RESULT QString organization() const;
126  void setOrganization(const QString &);
127 
128  /** The user's OpenPGP encryption key */
129  Q_REQUIRED_RESULT QByteArray pgpEncryptionKey() const;
130  void setPGPEncryptionKey(const QByteArray &key);
131 
132  /** The user's OpenPGP signing key */
133  Q_REQUIRED_RESULT QByteArray pgpSigningKey() const;
134  void setPGPSigningKey(const QByteArray &key);
135 
136  /** The user's S/MIME encryption key */
137  Q_REQUIRED_RESULT QByteArray smimeEncryptionKey() const;
138  void setSMIMEEncryptionKey(const QByteArray &key);
139 
140  /** The user's S/MIME signing key */
141  Q_REQUIRED_RESULT QByteArray smimeSigningKey() const;
142  void setSMIMESigningKey(const QByteArray &key);
143 
144  Q_REQUIRED_RESULT QString preferredCryptoMessageFormat() const;
145  void setPreferredCryptoMessageFormat(const QString &);
146 
147  /**
148  * primary email address (without the user name - only name\@host).
149  * The primary email address is used for all outgoing mail.
150  *
151  * @since 4.6
152  */
153  Q_REQUIRED_RESULT QString primaryEmailAddress() const;
154  void setPrimaryEmailAddress(const QString &email);
155 
156  /**
157  * email address aliases
158  *
159  * @since 4.6
160  */
161  Q_REQUIRED_RESULT const QStringList emailAliases() const;
162  void setEmailAliases(const QStringList &aliases);
163 
164  /**
165  * @param addr the email address to check
166  * @return true if this identity contains the email address @p addr, either as primary address
167  * or as alias
168  *
169  * @since 4.6
170  */
171  Q_REQUIRED_RESULT bool matchesEmailAddress(const QString &addr) const;
172 
173  /** vCard to attach to outgoing emails */
174  Q_REQUIRED_RESULT QString vCardFile() const;
175  void setVCardFile(const QString &);
176 
177  /** email address in the format "username <[email protected]>" suitable
178  for the "From:" field of email messages. */
179  Q_REQUIRED_RESULT QString fullEmailAddr() const;
180 
181  /** email address for the ReplyTo: field */
182  Q_REQUIRED_RESULT QString replyToAddr() const;
183  void setReplyToAddr(const QString &);
184 
185  /** email addresses for the BCC: field */
186  Q_REQUIRED_RESULT QString bcc() const;
187  void setBcc(const QString &);
188 
189  /** email addresses for the CC: field
190  * @since 4.9
191  */
192  Q_REQUIRED_RESULT QString cc() const;
193  void setCc(const QString &);
194 
195  /**
196  *
197  * @since 4.10
198  */
199  Q_REQUIRED_RESULT bool attachVcard() const;
200  void setAttachVcard(bool attach);
201 
202  /**
203  * @since 4.10
204  */
205  QString autocorrectionLanguage() const;
206  void setAutocorrectionLanguage(const QString &language);
207 
208  /**
209  * @since 4.11
210  */
211  Q_REQUIRED_RESULT bool disabledFcc() const;
212  void setDisabledFcc(bool);
213 
214  /**
215  * @since 4.12
216  */
217  Q_REQUIRED_RESULT bool pgpAutoSign() const;
218  void setPgpAutoSign(bool);
219 
220  /**
221  * @since 5.4
222  */
223  Q_REQUIRED_RESULT bool pgpAutoEncrypt() const;
224  void setPgpAutoEncrypt(bool);
225 
226  /**
227  * @since 5.17
228  */
229  Q_REQUIRED_RESULT bool autocryptEnabled() const;
230  void setAutocryptEnabled(const bool);
231 
232  /**
233  * @since 4.14
234  */
235  Q_REQUIRED_RESULT QString defaultDomainName() const;
236  void setDefaultDomainName(const QString &domainName);
237 
238  void setSignature(const Signature &sig);
239  Q_REQUIRED_RESULT Signature &signature(); /* _not_ const! */
240 
241  /**
242  @return the signature with '-- \n' prepended to it if it is not
243  present already.
244  No newline in front of or after the signature is added.
245  @param ok if a valid bool pointer, it is set to @c true or @c false depending
246  on whether the signature could successfully be obtained.
247  */
248  Q_REQUIRED_RESULT QString signatureText(bool *ok = nullptr) const;
249 
250  /**
251  * @since 4.1
252  * @return true if the inlined signature is html formatted
253  */
254  Q_REQUIRED_RESULT bool signatureIsInlinedHtml() const;
255 
256  /** The transport that is set for this identity. Used to link a
257  transport with an identity. */
258  Q_REQUIRED_RESULT QString transport() const;
259  void setTransport(const QString &);
260 
261  /** The folder where sent messages from this identity will be
262  stored by default. */
263  Q_REQUIRED_RESULT QString fcc() const;
264  void setFcc(const QString &);
265 
266  /** The folder where draft messages from this identity will be
267  stored by default.
268  */
269  Q_REQUIRED_RESULT QString drafts() const;
270  void setDrafts(const QString &);
271 
272  /** The folder where template messages from this identity will be
273  stored by default.
274  */
275  Q_REQUIRED_RESULT QString templates() const;
276  void setTemplates(const QString &);
277 
278  /**
279  * Dictionary which should be used for spell checking
280  *
281  * Note that this is the localized language name (e.g. "British English"),
282  * _not_ the language code or dictionary name!
283  */
284  Q_REQUIRED_RESULT QString dictionary() const;
285  void setDictionary(const QString &);
286 
287  /** a X-Face header for this identity */
288  Q_REQUIRED_RESULT QString xface() const;
289  void setXFace(const QString &);
290  Q_REQUIRED_RESULT bool isXFaceEnabled() const;
291  void setXFaceEnabled(bool);
292 
293  /** a Face header for this identity */
294  Q_REQUIRED_RESULT QString face() const;
295  void setFace(const QString &);
296  Q_REQUIRED_RESULT bool isFaceEnabled() const;
297  void setFaceEnabled(bool);
298 
299  /** Get random properties
300  * @param key the key of the property to get
301  */
302  Q_REQUIRED_RESULT QVariant property(const QString &key) const;
303  /** Set random properties, when @p value is empty (for QStrings) or null,
304  the property is deleted. */
305  void setProperty(const QString &key, const QVariant &value);
306 
307  static const Identity &null();
308  /** Returns true when the identity contains no values, all null values or
309  only empty values */
310  Q_REQUIRED_RESULT bool isNull() const;
311 
312  Q_REQUIRED_RESULT static QString mimeDataType();
313  Q_REQUIRED_RESULT static bool canDecode(const QMimeData *);
314  void populateMimeData(QMimeData *) const;
315  static Identity fromMimeData(const QMimeData *);
316 
317  /** Read configuration from config. Group must be preset (or use
318  KConfigGroup). Called from IdentityManager. */
319  void readConfig(const KConfigGroup &);
320 
321  /** Write configuration to config. Group must be preset (or use
322  KConfigGroup). Called from IdentityManager. */
323  void writeConfig(KConfigGroup &) const;
324 
325  /** Set whether this identity is the default identity. Since this
326  affects all other identities, too (most notably, the old default
327  identity), only the IdentityManager can change this.
328  You should use
329  <pre>
330  kmkernel->identityManager()->setAsDefault( name_of_default )
331  </pre>
332  instead. */
333  void setIsDefault(bool flag);
334 
335  /** set the uiod
336  * @param aUoid the uoid to set
337  */
338  void setUoid(uint aUoid);
339 
340 protected:
341  /** during migration when it failed it can be a string => not a qlonglong akonadi::id => fix it*/
342  Q_REQUIRED_RESULT QString verifyAkonadiId(const QString &str) const;
343  /** @return true if the signature is read from the output of a command */
344  Q_REQUIRED_RESULT bool signatureIsCommand() const;
345 
346  /** @return true if the signature is read from a text file */
347  Q_REQUIRED_RESULT bool signatureIsPlainFile() const;
348 
349  /** @return true if the signature was specified directly */
350  Q_REQUIRED_RESULT bool signatureIsInline() const;
351 
352  /** name of the signature file (with path) */
353  Q_REQUIRED_RESULT QString signatureFile() const;
354  void setSignatureFile(const QString &);
355 
356  /** inline signature */
357  Q_REQUIRED_RESULT QString signatureInlineText() const;
358  void setSignatureInlineText(const QString &);
359 
360  /** Inline or signature from a file */
361  Q_REQUIRED_RESULT bool useSignatureFile() const;
362 
363  Signature mSignature;
364  bool mIsDefault = false;
365  QHash<QString, QVariant> mPropertiesMap;
366 };
367 }
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
User identity information.
Definition: identity.h:67
QCA_EXPORT void setProperty(const QString &name, const QVariant &value)
Abstraction of a signature (aka "footer").
Definition: signature.h:65
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
Manages the list of identities.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu May 26 2022 03:46:36 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.