KIdentityManagement

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

KDE's Doxygen guidelines are available online.