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

KDE's Doxygen guidelines are available online.