File indexing completed on 2024-05-19 05:17:27
0001 /* 0002 SPDX-FileCopyrightText: 2002-2004 Marc Mutz <mutz@kde.org> 0003 SPDX-FileCopyrightText: 2007 Tom Albers <tomalbers@kde.nl> 0004 Author: Stefan Taferner <taferner@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include "kidentitymanagementcore_export.h" 0012 #include "signature.h" 0013 0014 #include <QHash> 0015 #include <QList> 0016 #include <QString> 0017 #include <QStringList> 0018 #include <QVariant> 0019 0020 namespace KIdentityManagementCore 0021 { 0022 class Identity; 0023 } 0024 class KConfigGroup; 0025 class QDataStream; 0026 class QMimeData; 0027 0028 namespace KIdentityManagementCore 0029 { 0030 static const char s_uoid[] = "uoid"; 0031 static const char s_identity[] = "Identity"; 0032 static const char s_name[] = "Name"; 0033 static const char s_organization[] = "Organization"; 0034 static const char s_pgps[] = "PGP Signing Key"; 0035 static const char s_pgpe[] = "PGP Encryption Key"; 0036 static const char s_smimes[] = "SMIME Signing Key"; 0037 static const char s_smimee[] = "SMIME Encryption Key"; 0038 static const char s_prefcrypt[] = "Preferred Crypto Message Format"; 0039 static const char s_primaryEmail[] = "Email Address"; 0040 static const char s_replyto[] = "Reply-To Address"; 0041 static const char s_bcc[] = "Bcc"; 0042 static const char s_cc[] = "Cc"; 0043 static const char s_vcard[] = "VCardFile"; 0044 static const char s_transport[] = "Transport"; 0045 static const char s_fcc[] = "Fcc"; 0046 static const char s_drafts[] = "Drafts"; 0047 static const char s_templates[] = "Templates"; 0048 static const char s_dict[] = "Dictionary"; 0049 static const char s_xface[] = "X-Face"; 0050 static const char s_xfaceenabled[] = "X-FaceEnabled"; 0051 static const char s_face[] = "Face"; 0052 static const char s_faceenabled[] = "FaceEnabled"; 0053 static const char s_signature[] = "Signature"; 0054 static const char s_emailAliases[] = "Email Aliases"; 0055 static const char s_attachVcard[] = "Attach Vcard"; 0056 static const char s_autocorrectionLanguage[] = "Autocorrection Language"; 0057 static const char s_disabledFcc[] = "Disable Fcc"; 0058 static const char s_encryptionOverride[] = "Override Encryption Defaults"; 0059 static const char s_pgpautosign[] = "Pgp Auto Sign"; 0060 static const char s_pgpautoencrypt[] = "Pgp Auto Encrypt"; 0061 static const char s_warnnotsign[] = "Warn not Sign"; 0062 static const char s_warnnotencrypt[] = "Warn not Encrypt"; 0063 static const char s_defaultDomainName[] = "Default Domain"; 0064 static const char s_autocryptEnabled[] = "Autocrypt"; 0065 static const char s_autocryptPrefer[] = "Autocrypt Prefer"; 0066 0067 KIDENTITYMANAGEMENTCORE_EXPORT QDataStream &operator<<(QDataStream &stream, const KIdentityManagementCore::Identity &ident); 0068 KIDENTITYMANAGEMENTCORE_EXPORT QDataStream &operator>>(QDataStream &stream, KIdentityManagementCore::Identity &ident); 0069 0070 /** User identity information */ 0071 class KIDENTITYMANAGEMENTCORE_EXPORT Identity 0072 { 0073 Q_GADGET 0074 0075 Q_PROPERTY(bool mailingAllowed READ mailingAllowed) 0076 Q_PROPERTY(QString identityName READ identityName WRITE setIdentityName) 0077 Q_PROPERTY(QString fullName READ fullName WRITE setFullName) 0078 Q_PROPERTY(QString organization READ organization WRITE setOrganization) 0079 Q_PROPERTY(QByteArray pgpEncryptionKey READ pgpEncryptionKey WRITE setPGPEncryptionKey) 0080 Q_PROPERTY(QByteArray pgpSigningKey READ pgpSigningKey WRITE setPGPSigningKey) 0081 Q_PROPERTY(QByteArray smimeEncryptionKey READ smimeEncryptionKey WRITE setSMIMEEncryptionKey) 0082 Q_PROPERTY(QByteArray smimeSigningKey READ smimeSigningKey WRITE setSMIMESigningKey) 0083 Q_PROPERTY(QString preferredCryptoMessageFormat READ preferredCryptoMessageFormat WRITE setPreferredCryptoMessageFormat) 0084 Q_PROPERTY(QString primaryEmailAddress READ primaryEmailAddress WRITE setPrimaryEmailAddress) 0085 Q_PROPERTY(QStringList emailAliases READ emailAliases WRITE setEmailAliases) 0086 Q_PROPERTY(QString vCardFile READ vCardFile WRITE setVCardFile) 0087 Q_PROPERTY(QString fullEmailAddr READ fullEmailAddr) 0088 Q_PROPERTY(QString replyToAddr READ replyToAddr WRITE setReplyToAddr) 0089 Q_PROPERTY(QString bcc READ bcc WRITE setBcc) 0090 Q_PROPERTY(QString cc READ cc WRITE setCc) 0091 Q_PROPERTY(bool attachVcard READ attachVcard WRITE setAttachVcard) 0092 Q_PROPERTY(QString autocorrectionLanguage READ autocorrectionLanguage WRITE setAutocorrectionLanguage) 0093 Q_PROPERTY(bool disabledFcc READ disabledFcc WRITE setDisabledFcc) 0094 Q_PROPERTY(bool pgpAutoSign READ pgpAutoSign WRITE setPgpAutoSign) 0095 Q_PROPERTY(bool pgpAutoEncrypt READ pgpAutoEncrypt WRITE setPgpAutoEncrypt) 0096 Q_PROPERTY(bool autocryptEnabled READ autocryptEnabled WRITE setAutocryptEnabled) 0097 Q_PROPERTY(bool autocryptPrefer READ autocryptPrefer WRITE setAutocryptPrefer) 0098 Q_PROPERTY(bool encryptionOverride READ encryptionOverride WRITE setEncryptionOverride) 0099 Q_PROPERTY(bool warnNotSign READ warnNotSign WRITE setWarnNotSign) 0100 Q_PROPERTY(bool warnNotEncrypt READ warnNotEncrypt WRITE setWarnNotEncrypt) 0101 Q_PROPERTY(QString defaultDomainName READ defaultDomainName WRITE setDefaultDomainName) 0102 Q_PROPERTY(Signature signature READ signature WRITE setSignature) 0103 Q_PROPERTY(QString signatureText READ signatureText) 0104 Q_PROPERTY(bool signatureIsInlinedHtml READ signatureIsInlinedHtml) 0105 Q_PROPERTY(QString transport READ transport WRITE setTransport) 0106 Q_PROPERTY(QString fcc READ fcc WRITE setFcc) 0107 Q_PROPERTY(QString drafts READ drafts WRITE setDrafts) 0108 Q_PROPERTY(QString templates READ templates WRITE setTemplates) 0109 Q_PROPERTY(QString dictionary READ dictionary WRITE setDictionary) 0110 Q_PROPERTY(QString xface READ xface WRITE setXFace) 0111 Q_PROPERTY(bool isXFaceEnabled READ isXFaceEnabled WRITE setXFaceEnabled) 0112 Q_PROPERTY(QString face READ face WRITE setFace) 0113 Q_PROPERTY(bool isFaceEnabled READ isFaceEnabled WRITE setFaceEnabled) 0114 Q_PROPERTY(uint uoid READ uoid CONSTANT) 0115 Q_PROPERTY(bool isNull READ isNull) 0116 0117 // only the identity manager should be able to construct and 0118 // destruct us, but then we get into problems with using 0119 // QValueList<Identity> and especially qHeapSort(). 0120 friend class IdentityManager; 0121 0122 friend KIDENTITYMANAGEMENTCORE_EXPORT QDataStream &operator<<(QDataStream &stream, const KIdentityManagementCore::Identity &ident); 0123 friend KIDENTITYMANAGEMENTCORE_EXPORT QDataStream &operator>>(QDataStream &stream, KIdentityManagementCore::Identity &ident); 0124 0125 public: 0126 using List = QList<Identity>; 0127 using Id = uint; 0128 0129 /** Constructor */ 0130 explicit Identity(const QString &id = QString(), 0131 const QString &realName = QString(), 0132 const QString &emailAddr = QString(), 0133 const QString &organization = QString(), 0134 const QString &replyToAddress = QString()); 0135 0136 /** used for comparison */ 0137 bool operator==(const Identity &other) const; 0138 0139 /** used for comparison */ 0140 bool operator!=(const Identity &other) const; 0141 0142 /** used for sorting */ 0143 bool operator<(const Identity &other) const; 0144 0145 /** used for sorting */ 0146 bool operator>(const Identity &other) const; 0147 0148 /** used for sorting */ 0149 bool operator<=(const Identity &other) const; 0150 0151 /** used for sorting */ 0152 bool operator>=(const Identity &other) const; 0153 0154 /** Tests if there are enough values set to allow mailing */ 0155 [[nodiscard]] bool mailingAllowed() const; 0156 0157 /** Identity/nickname for this collection */ 0158 [[nodiscard]] QString identityName() const; 0159 0160 /** Identity/nickname for this collection */ 0161 void setIdentityName(const QString &name); 0162 0163 /** @return whether this identity is the default identity */ 0164 [[nodiscard]] bool isDefault() const; 0165 0166 /** Unique Object Identifier for this identity */ 0167 [[nodiscard]] uint uoid() const; 0168 0169 /** Full name of the user */ 0170 [[nodiscard]] QString fullName() const; 0171 void setFullName(const QString &); 0172 0173 /** The user's organization (optional) */ 0174 [[nodiscard]] QString organization() const; 0175 void setOrganization(const QString &); 0176 0177 /** The user's OpenPGP encryption key */ 0178 [[nodiscard]] QByteArray pgpEncryptionKey() const; 0179 void setPGPEncryptionKey(const QByteArray &key); 0180 0181 /** The user's OpenPGP signing key */ 0182 [[nodiscard]] QByteArray pgpSigningKey() const; 0183 void setPGPSigningKey(const QByteArray &key); 0184 0185 /** The user's S/MIME encryption key */ 0186 [[nodiscard]] QByteArray smimeEncryptionKey() const; 0187 void setSMIMEEncryptionKey(const QByteArray &key); 0188 0189 /** The user's S/MIME signing key */ 0190 [[nodiscard]] QByteArray smimeSigningKey() const; 0191 void setSMIMESigningKey(const QByteArray &key); 0192 0193 [[nodiscard]] QString preferredCryptoMessageFormat() const; 0194 void setPreferredCryptoMessageFormat(const QString &); 0195 0196 /** 0197 * The primary email address (without the user name - only name\@host). 0198 * 0199 * This email address is used for all outgoing mail. 0200 * 0201 * @since 4.6 0202 */ 0203 [[nodiscard]] QString primaryEmailAddress() const; 0204 void setPrimaryEmailAddress(const QString &email); 0205 0206 /** 0207 * The email address aliases 0208 * 0209 * @since 4.6 0210 */ 0211 [[nodiscard]] const QStringList emailAliases() const; 0212 void setEmailAliases(const QStringList &aliases); 0213 0214 /** 0215 * @param addr the email address to check 0216 * @return true if this identity contains the email address @p addr, either as primary address 0217 * or as alias 0218 * 0219 * @since 4.6 0220 */ 0221 [[nodiscard]] bool matchesEmailAddress(const QString &addr) const; 0222 0223 /** vCard to attach to outgoing emails */ 0224 [[nodiscard]] QString vCardFile() const; 0225 void setVCardFile(const QString &); 0226 0227 /** 0228 * The email address in the format "username <name@host>" suitable 0229 * for the "From:" field of email messages. 0230 */ 0231 [[nodiscard]] QString fullEmailAddr() const; 0232 0233 /** @return The email address for the ReplyTo: field */ 0234 [[nodiscard]] QString replyToAddr() const; 0235 void setReplyToAddr(const QString &); 0236 0237 /** @return The email addresses for the BCC: field */ 0238 [[nodiscard]] QString bcc() const; 0239 void setBcc(const QString &); 0240 0241 /** 0242 * @return The email addresses for the CC: field 0243 * @since 4.9 0244 */ 0245 [[nodiscard]] QString cc() const; 0246 void setCc(const QString &); 0247 0248 /** 0249 * @return true if the Vcard of this identity should be attached to outgoing mail. 0250 * @since 4.10 0251 */ 0252 [[nodiscard]] bool attachVcard() const; 0253 void setAttachVcard(bool attach); 0254 0255 /** 0256 * @return The default language for spell checking of this identity. 0257 * @since 4.10 0258 */ 0259 QString autocorrectionLanguage() const; 0260 void setAutocorrectionLanguage(const QString &language); 0261 0262 /** 0263 * @return true if Fcc is disabled for this identity. 0264 * @since 4.11 0265 */ 0266 [[nodiscard]] bool disabledFcc() const; 0267 void setDisabledFcc(bool); 0268 0269 /** 0270 * @return true if we should sign message sent by this identity by default. 0271 * @since 4.12 0272 */ 0273 [[nodiscard]] bool pgpAutoSign() const; 0274 void setPgpAutoSign(bool); 0275 0276 /** 0277 * @return true if we should encrypt message sent by this identity by default. 0278 * @since 5.4 0279 */ 0280 [[nodiscard]] bool pgpAutoEncrypt() const; 0281 void setPgpAutoEncrypt(bool); 0282 0283 /** 0284 * @return true if Autocrypt is enabled for this identity. 0285 * @since 5.17 0286 */ 0287 [[nodiscard]] bool autocryptEnabled() const; 0288 void setAutocryptEnabled(const bool); 0289 0290 /** 0291 * @return true if Autocrypt is preferred for this identity. 0292 * @since 5.22 0293 */ 0294 [[nodiscard]] bool autocryptPrefer() const; 0295 void setAutocryptPrefer(const bool); 0296 0297 /** 0298 * @return true if the warnNotSign and warnNotEncrypt identity configuration should 0299 * overwrite the global app-wide configuration. 0300 * @since 5.22 0301 */ 0302 [[nodiscard]] bool encryptionOverride() const; 0303 void setEncryptionOverride(const bool); 0304 0305 /** 0306 * @return true if we should warn if parts of the message this identity is about to send are not signed. 0307 * @since 5.22 0308 */ 0309 [[nodiscard]] bool warnNotSign() const; 0310 void setWarnNotSign(const bool); 0311 0312 /** 0313 * @return true if we should warn if parts of the message this identity is about to send are not encrypted. 0314 * @since 5.22 0315 */ 0316 [[nodiscard]] bool warnNotEncrypt() const; 0317 void setWarnNotEncrypt(const bool); 0318 0319 /** 0320 * @return The default domain name 0321 * @since 4.14 0322 */ 0323 [[nodiscard]] QString defaultDomainName() const; 0324 void setDefaultDomainName(const QString &domainName); 0325 0326 /** 0327 * @return The signature of the identity. 0328 * 0329 * @warning This method is not const. 0330 */ 0331 [[nodiscard]] Signature &signature(); 0332 void setSignature(const Signature &sig); 0333 0334 /** 0335 * @return the signature with '-- \n' prepended to it if it is not 0336 * present already. 0337 * No newline in front of or after the signature is added. 0338 * @param ok if a valid bool pointer, it is set to @c true or @c false depending 0339 * on whether the signature could successfully be obtained. 0340 */ 0341 [[nodiscard]] QString signatureText(bool *ok = nullptr) const; 0342 0343 /** 0344 * @return true if the inlined signature is html formatted 0345 * @since 4.1 0346 */ 0347 [[nodiscard]] bool signatureIsInlinedHtml() const; 0348 0349 /** The transport that is set for this identity. Used to link a 0350 transport with an identity. */ 0351 [[nodiscard]] QString transport() const; 0352 void setTransport(const QString &); 0353 0354 /** The folder where sent messages from this identity will be 0355 stored by default. */ 0356 [[nodiscard]] QString fcc() const; 0357 void setFcc(const QString &); 0358 0359 /** The folder where draft messages from this identity will be 0360 stored by default. 0361 */ 0362 [[nodiscard]] QString drafts() const; 0363 void setDrafts(const QString &); 0364 0365 /** The folder where template messages from this identity will be 0366 stored by default. 0367 */ 0368 [[nodiscard]] QString templates() const; 0369 void setTemplates(const QString &); 0370 0371 /** 0372 * Dictionary which should be used for spell checking 0373 * 0374 * Note that this is the localized language name (e.g. "British English"), 0375 * _not_ the language code or dictionary name! 0376 */ 0377 [[nodiscard]] QString dictionary() const; 0378 void setDictionary(const QString &); 0379 0380 /** a X-Face header for this identity */ 0381 [[nodiscard]] QString xface() const; 0382 void setXFace(const QString &); 0383 [[nodiscard]] bool isXFaceEnabled() const; 0384 void setXFaceEnabled(bool); 0385 0386 /** a Face header for this identity */ 0387 [[nodiscard]] QString face() const; 0388 void setFace(const QString &); 0389 [[nodiscard]] bool isFaceEnabled() const; 0390 void setFaceEnabled(bool); 0391 0392 /** Get random properties 0393 * @param key the key of the property to get 0394 */ 0395 [[nodiscard]] QVariant property(const QString &key) const; 0396 /** Set random properties, when @p value is empty (for QStrings) or null, 0397 the property is deleted. */ 0398 void setProperty(const QString &key, const QVariant &value); 0399 0400 static const Identity &null(); 0401 /** Returns true when the identity contains no values, all null values or 0402 only empty values */ 0403 [[nodiscard]] bool isNull() const; 0404 0405 [[nodiscard]] static QString mimeDataType(); 0406 [[nodiscard]] static bool canDecode(const QMimeData *); 0407 void populateMimeData(QMimeData *) const; 0408 static Identity fromMimeData(const QMimeData *); 0409 0410 /** Read configuration from config. Group must be preset (or use 0411 KConfigGroup). Called from IdentityManager. */ 0412 void readConfig(const KConfigGroup &); 0413 0414 /** Write configuration to config. Group must be preset (or use 0415 KConfigGroup). Called from IdentityManager. */ 0416 void writeConfig(KConfigGroup &) const; 0417 0418 /** Set whether this identity is the default identity. Since this 0419 affects all other identities, too (most notably, the old default 0420 identity), only the IdentityManager can change this. 0421 You should use 0422 <pre> 0423 kmkernel->identityManager()->setAsDefault( name_of_default ) 0424 </pre> 0425 instead. */ 0426 void setIsDefault(bool flag); 0427 0428 /** 0429 * Set the uiod 0430 * @param aUoid the uoid to set 0431 */ 0432 void setUoid(uint aUoid); 0433 0434 protected: 0435 /** during migration when it failed it can be a string => not a qlonglong akonadi::id => fix it*/ 0436 [[nodiscard]] QString verifyAkonadiId(const QString &str) const; 0437 /** @return true if the signature is read from the output of a command */ 0438 [[nodiscard]] bool signatureIsCommand() const; 0439 0440 /** @return true if the signature is read from a text file */ 0441 [[nodiscard]] bool signatureIsPlainFile() const; 0442 0443 /** @return true if the signature was specified directly */ 0444 [[nodiscard]] bool signatureIsInline() const; 0445 0446 /** name of the signature file (with path) */ 0447 [[nodiscard]] QString signatureFile() const; 0448 void setSignatureFile(const QString &); 0449 0450 /** inline signature */ 0451 [[nodiscard]] QString signatureInlineText() const; 0452 void setSignatureInlineText(const QString &); 0453 0454 /** Inline or signature from a file */ 0455 [[nodiscard]] bool useSignatureFile() const; 0456 0457 Signature mSignature; 0458 bool mIsDefault = false; 0459 QHash<QString, QVariant> mPropertiesMap; 0460 }; 0461 } 0462 0463 #ifndef UNITY_CMAKE_SUPPORT 0464 Q_DECLARE_METATYPE(KIdentityManagementCore::Identity) 0465 #endif