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

KDE's Doxygen guidelines are available online.