KIdentityManagement

identity.cpp
1/*
2 SPDX-FileCopyrightText: 2002-2004 Marc Mutz <mutz@kde.org>
3 SPDX-FileCopyrightText: 2007 Tom Albers <tomalbers@kde.nl>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "identity.h"
9using namespace Qt::Literals::StringLiterals;
10
11#include "kidentitymanagementcore_debug.h"
12#include <KConfigGroup>
13#include <KEmailAddress>
14
15#include <QByteArray>
16#include <QHostInfo>
17#include <QMimeData>
18
19using namespace KIdentityManagementCore;
20
21static Identity *identityNull = nullptr;
22
23Q_DECLARE_METATYPE(KIdentityManagementCore::Signature)
24
25Identity::Identity(const QString &id, const QString &fullName, const QString &emailAddr, const QString &organization, const QString &replyToAddr)
26{
27 qRegisterMetaType<Signature>();
28 setProperty(QLatin1StringView(s_uoid), 0);
29 setProperty(QLatin1StringView(s_identity), id);
30 setProperty(QLatin1StringView(s_name), fullName);
31 setProperty(QLatin1StringView(s_primaryEmail), emailAddr);
32 setProperty(QLatin1StringView(s_organization), organization);
33 setProperty(QLatin1StringView(s_replyto), replyToAddr);
34 // FIXME KF6: Sonnet::defaultLanguageName is gone
35 // setDictionary( Sonnet::defaultLanguageName() );
36 setProperty(QLatin1StringView(s_disabledFcc), false);
37 setProperty(QLatin1StringView(s_defaultDomainName), QHostInfo::localHostName());
38}
39
40const Identity &Identity::null()
41{
42 if (!identityNull) {
43 identityNull = new Identity;
44 }
45 return *identityNull;
46}
47
48bool Identity::isNull() const
49{
51
52 while (i != mPropertiesMap.constEnd()) {
53 const QString &key = i.key();
54 // Take into account that the defaultDomainName for a null identity is not empty
55 if (key == QLatin1StringView(s_defaultDomainName)) {
56 ++i;
57 continue;
58 }
59 // Take into account that the dictionary for a null identity is not empty
60 if (key == QLatin1StringView(s_dict)) {
61 ++i;
62 continue;
63 }
64 // Take into account that disableFcc == false for a null identity
65 if (key == QLatin1StringView(s_disabledFcc) && i.value().toBool() == false) {
66 ++i;
67 continue;
68 }
69 // The uoid is 0 by default, so ignore this
70 if (!(key == QLatin1StringView(s_uoid) && i.value().toUInt() == 0)) {
71 if (!i.value().isNull() || (i.value().metaType().id() == QMetaType::QString && !i.value().toString().isEmpty())) {
72 return false;
73 }
74 }
75 ++i;
76 }
77
78 return true;
79}
80
82{
83 // get all keys and convert them to our QHash.
84 QMap<QString, QString> entries = config.entryMap();
87 while (i != end) {
88 const QString &key = i.key();
89 if (key == QLatin1StringView(s_emailAliases) || key == QLatin1StringView(s_activities)) {
90 // HACK: Read s_emailAliases as a stringlist
91 mPropertiesMap.insert(key, config.readEntry(key, QStringList()));
92 } else {
93 mPropertiesMap.insert(key, config.readEntry(key));
94 }
95 ++i;
96 }
97 // needs to update to v5.21.41
98 // Check if we update to to encryption override mode
99 // before we had only auto_encrypt and auto_sign and no global setting
100 if (!mPropertiesMap.contains(QLatin1StringView(s_encryptionOverride)) && !mPropertiesMap.contains(QLatin1StringView(s_warnnotencrypt))
101 && !mPropertiesMap.contains(QLatin1StringView(s_warnnotsign))) {
102 setEncryptionOverride(true);
103 }
104 mSignature.readConfig(config);
105}
106
108{
111 while (i != end) {
112 config.writeEntry(i.key(), i.value());
113 qCDebug(KIDENTITYMANAGEMENT_LOG) << "Store:" << i.key() << ":" << i.value();
114 ++i;
115 }
116 if (!mPropertiesMap.contains(QLatin1StringView(s_encryptionOverride))) {
117 config.writeEntry(QLatin1StringView(s_encryptionOverride), false);
118 qCDebug(KIDENTITYMANAGEMENT_LOG) << "Add" << s_encryptionOverride << ":" << false;
119 }
120 mSignature.writeConfig(config);
121}
122
123bool Identity::mailingAllowed() const
124{
125 return !property(QLatin1StringView(s_primaryEmail)).toString().isEmpty();
126}
127
128QString Identity::mimeDataType()
129{
130 return QStringLiteral("application/x-kmail-identity-drag");
131}
132
133bool Identity::canDecode(const QMimeData *md)
134{
135 if (md) {
136 return md->hasFormat(mimeDataType());
137 } else {
138 return false;
139 }
140}
141
142void Identity::populateMimeData(QMimeData *md) const
143{
144 QByteArray a;
145 {
147 s << *this;
148 }
149 md->setData(mimeDataType(), a);
150}
151
152Identity Identity::fromMimeData(const QMimeData *md)
153{
154 Identity i;
155 if (canDecode(md)) {
156 QByteArray ba = md->data(mimeDataType());
158 s >> i;
159 }
160 return i;
161}
162
163// ------------------ Operators --------------------------//
164
165QDataStream &KIdentityManagementCore::operator<<(QDataStream &stream, const KIdentityManagementCore::Identity &i)
166{
167 return stream << static_cast<quint32>(i.uoid()) << i.mPropertiesMap[QLatin1StringView(s_identity)] << i.mPropertiesMap[QLatin1StringView(s_name)]
168 << i.mPropertiesMap[QLatin1StringView(s_organization)] << i.mPropertiesMap[QLatin1StringView(s_pgps)]
169 << i.mPropertiesMap[QLatin1StringView(s_pgpe)] << i.mPropertiesMap[QLatin1StringView(s_smimes)]
170 << i.mPropertiesMap[QLatin1StringView(s_smimee)] << i.mPropertiesMap[QLatin1StringView(s_primaryEmail)]
171 << i.mPropertiesMap[QLatin1StringView(s_emailAliases)] << i.mPropertiesMap[QLatin1StringView(s_replyto)]
172 << i.mPropertiesMap[QLatin1StringView(s_bcc)] << i.mPropertiesMap[QLatin1StringView(s_vcard)]
173 << i.mPropertiesMap[QLatin1StringView(s_transport)] << i.mPropertiesMap[QLatin1StringView(s_fcc)]
174 << i.mPropertiesMap[QLatin1StringView(s_drafts)] << i.mPropertiesMap[QLatin1StringView(s_templates)] << i.mSignature
175 << i.mPropertiesMap[QLatin1StringView(s_dict)] << i.mPropertiesMap[QLatin1StringView(s_xface)]
176 << i.mPropertiesMap[QLatin1StringView(s_xfaceenabled)] << i.mPropertiesMap[QLatin1StringView(s_face)]
177 << i.mPropertiesMap[QLatin1StringView(s_faceenabled)] << i.mPropertiesMap[QLatin1StringView(s_prefcrypt)]
178 << i.mPropertiesMap[QLatin1StringView(s_cc)] << i.mPropertiesMap[QLatin1StringView(s_attachVcard)]
179 << i.mPropertiesMap[QLatin1StringView(s_autocorrectionLanguage)] << i.mPropertiesMap[QLatin1StringView(s_disabledFcc)]
180 << i.mPropertiesMap[QLatin1StringView(s_defaultDomainName)] << i.mPropertiesMap[QLatin1StringView(s_autocryptEnabled)]
181 << i.mPropertiesMap[QLatin1StringView(s_autocryptPrefer)] << i.mPropertiesMap[QLatin1StringView(s_encryptionOverride)]
182 << i.mPropertiesMap[QLatin1StringView(s_pgpautosign)] << i.mPropertiesMap[QLatin1StringView(s_pgpautoencrypt)]
183 << i.mPropertiesMap[QLatin1StringView(s_warnnotencrypt)] << i.mPropertiesMap[QLatin1StringView(s_warnnotsign)]
184 << i.mPropertiesMap[QLatin1StringView(s_activities)] << i.mPropertiesMap[QLatin1StringView(s_enabledActivities)];
185}
186
187QDataStream &KIdentityManagementCore::operator>>(QDataStream &stream, KIdentityManagementCore::Identity &i)
188{
189 quint32 uoid;
190 stream >> uoid >> i.mPropertiesMap[QLatin1StringView(s_identity)] >> i.mPropertiesMap[QLatin1StringView(s_name)]
191 >> i.mPropertiesMap[QLatin1StringView(s_organization)] >> i.mPropertiesMap[QLatin1StringView(s_pgps)] >> i.mPropertiesMap[QLatin1StringView(s_pgpe)]
192 >> i.mPropertiesMap[QLatin1StringView(s_smimes)] >> i.mPropertiesMap[QLatin1StringView(s_smimee)] >> i.mPropertiesMap[QLatin1StringView(s_primaryEmail)]
193 >> i.mPropertiesMap[QLatin1StringView(s_emailAliases)] >> i.mPropertiesMap[QLatin1StringView(s_replyto)] >> i.mPropertiesMap[QLatin1StringView(s_bcc)]
194 >> i.mPropertiesMap[QLatin1StringView(s_vcard)] >> i.mPropertiesMap[QLatin1StringView(s_transport)] >> i.mPropertiesMap[QLatin1StringView(s_fcc)]
195 >> i.mPropertiesMap[QLatin1StringView(s_drafts)] >> i.mPropertiesMap[QLatin1StringView(s_templates)] >> i.mSignature
196 >> i.mPropertiesMap[QLatin1StringView(s_dict)] >> i.mPropertiesMap[QLatin1StringView(s_xface)] >> i.mPropertiesMap[QLatin1StringView(s_xfaceenabled)]
197 >> i.mPropertiesMap[QLatin1StringView(s_face)] >> i.mPropertiesMap[QLatin1StringView(s_faceenabled)] >> i.mPropertiesMap[QLatin1StringView(s_prefcrypt)]
198 >> i.mPropertiesMap[QLatin1StringView(s_cc)] >> i.mPropertiesMap[QLatin1StringView(s_attachVcard)]
199 >> i.mPropertiesMap[QLatin1StringView(s_autocorrectionLanguage)] >> i.mPropertiesMap[QLatin1StringView(s_disabledFcc)]
200 >> i.mPropertiesMap[QLatin1StringView(s_defaultDomainName)] >> i.mPropertiesMap[QLatin1StringView(s_autocryptEnabled)]
201 >> i.mPropertiesMap[QLatin1StringView(s_autocryptPrefer)] >> i.mPropertiesMap[QLatin1StringView(s_encryptionOverride)]
202 >> i.mPropertiesMap[QLatin1StringView(s_pgpautosign)] >> i.mPropertiesMap[QLatin1StringView(s_pgpautoencrypt)]
203 >> i.mPropertiesMap[QLatin1StringView(s_warnnotencrypt)] >> i.mPropertiesMap[QLatin1StringView(s_warnnotsign)]
204 >> i.mPropertiesMap[QLatin1StringView(s_activities)] >> i.mPropertiesMap[QLatin1StringView(s_enabledActivities)];
205
206 i.setProperty(QLatin1StringView(s_uoid), uoid);
207 return stream;
208}
209
210bool Identity::operator<(const Identity &other) const
211{
212 if (isDefault()) {
213 return true;
214 }
215 if (other.isDefault()) {
216 return false;
217 }
218 return identityName() < other.identityName();
219}
220
221bool Identity::operator>(const Identity &other) const
222{
223 if (isDefault()) {
224 return false;
225 }
226 if (other.isDefault()) {
227 return true;
228 }
229 return identityName() > other.identityName();
230}
231
232bool Identity::operator<=(const Identity &other) const
233{
234 return !operator>(other);
235}
236
237bool Identity::operator>=(const Identity &other) const
238{
239 return !operator<(other);
240}
241
242bool Identity::operator==(const Identity &other) const
243{
244 // The deserializer fills in the QHash will lots of invalid variants, which
245 // is OK, but the CTOR doesn't fill the hash with the missing fields, so
246 // regular mPropertiesMap == other.mPropertiesMap comparison will fail.
247 // This algo considers both maps equal even if one map does not contain the
248 // key and the other one contains the key but with an invalid value
249 for (const auto &pair : {qMakePair(mPropertiesMap, other.mPropertiesMap), qMakePair(other.mPropertiesMap, mPropertiesMap)}) {
250 const auto lhs = pair.first;
251 const auto rhs = pair.second;
252 for (auto lhsIt = lhs.constBegin(), lhsEnd = lhs.constEnd(); lhsIt != lhsEnd; ++lhsIt) {
253 const auto rhsIt = rhs.constFind(lhsIt.key());
254 // Does the other map contain the key?
255 if (rhsIt == rhs.constEnd()) {
256 // It does not, so check if our value is invalid, if yes, consider it
257 // equal to not present and continue
258 if (lhsIt->isValid()) {
259 return false;
260 }
261 } else if (lhsIt.value() != rhsIt.value()) {
262 // Both maps have the key, but different value -> different maps
263 return false;
264 }
265 }
266 }
267
268 return mSignature == other.mSignature;
269}
270
271bool Identity::operator!=(const Identity &other) const
272{
273 return !operator==(other);
274}
275
276// --------------------- Getters -----------------------------//
277
279{
280 if (key == QLatin1StringView(s_signature)) {
281 return QVariant::fromValue(mSignature);
282 } else {
283 return mPropertiesMap.value(key);
284 }
285}
286
287QString Identity::fullEmailAddr() const
288{
289 const QString name = mPropertiesMap.value(QLatin1StringView(s_name)).toString();
290 const QString mail = mPropertiesMap.value(QLatin1StringView(s_primaryEmail)).toString();
291
292 if (name.isEmpty()) {
293 return mail;
294 }
295
296 const QString specials(QStringLiteral("()<>@,.;:[]"));
297
298 QString result;
299
300 // add DQUOTE's if necessary:
301 bool needsQuotes = false;
302 const int nameLength(name.length());
303 for (int i = 0; i < nameLength; i++) {
304 if (specials.contains(name[i])) {
305 needsQuotes = true;
306 } else if (name[i] == QLatin1Char('\\') || name[i] == QLatin1Char('"')) {
307 needsQuotes = true;
308 result += QLatin1Char('\\');
309 }
310 result += name[i];
311 }
312
313 if (needsQuotes) {
314 result.insert(0, QLatin1Char('"'));
315 result += QLatin1Char('"');
316 }
317
318 result += " <"_L1 + mail + QLatin1Char('>');
319
320 return result;
321}
322
323QString Identity::identityName() const
324{
325 return property(QLatin1StringView(s_identity)).toString();
326}
327
328QString Identity::signatureText(bool *ok) const
329{
330 return mSignature.withSeparator(ok);
331}
332
333bool Identity::signatureIsInlinedHtml() const
334{
335 return mSignature.isInlinedHtml();
336}
337
339{
340 return mIsDefault;
341}
342
343uint Identity::uoid() const
344{
345 return property(QLatin1StringView(s_uoid)).toInt();
346}
347
348QString Identity::fullName() const
349{
350 return property(QLatin1StringView(s_name)).toString();
351}
352
353QString Identity::organization() const
354{
355 return property(QLatin1StringView(s_organization)).toString();
356}
357
358QByteArray Identity::pgpEncryptionKey() const
359{
360 return property(QLatin1StringView(s_pgpe)).toByteArray();
361}
362
363QByteArray Identity::pgpSigningKey() const
364{
365 return property(QLatin1StringView(s_pgps)).toByteArray();
366}
367
368QByteArray Identity::smimeEncryptionKey() const
369{
370 return property(QLatin1StringView(s_smimee)).toByteArray();
371}
372
373QByteArray Identity::smimeSigningKey() const
374{
375 return property(QLatin1StringView(s_smimes)).toByteArray();
376}
377
378QString Identity::preferredCryptoMessageFormat() const
379{
380 return property(QLatin1StringView(s_prefcrypt)).toString();
381}
382
383QString Identity::primaryEmailAddress() const
384{
385 return property(QLatin1StringView(s_primaryEmail)).toString();
386}
387
388const QStringList Identity::emailAliases() const
389{
390 return property(QLatin1StringView(s_emailAliases)).toStringList();
391}
392
393QString Identity::vCardFile() const
394{
395 return property(QLatin1StringView(s_vcard)).toString();
396}
397
398bool Identity::attachVcard() const
399{
400 return property(QLatin1StringView(s_attachVcard)).toBool();
401}
402
403QString Identity::replyToAddr() const
404{
405 return property(QLatin1StringView(s_replyto)).toString();
406}
407
408QString Identity::bcc() const
409{
410 return property(QLatin1StringView(s_bcc)).toString();
411}
412
413QString Identity::cc() const
414{
415 return property(QLatin1StringView(s_cc)).toString();
416}
417
418Signature &Identity::signature()
419{
420 return mSignature;
421}
422
423bool Identity::isXFaceEnabled() const
424{
425 return property(QLatin1StringView(s_xfaceenabled)).toBool();
426}
427
428QString Identity::xface() const
429{
430 return property(QLatin1StringView(s_xface)).toString();
431}
432
433bool Identity::isFaceEnabled() const
434{
435 return property(QLatin1StringView(s_faceenabled)).toBool();
436}
437
438QString Identity::face() const
439{
440 return property(QLatin1StringView(s_face)).toString();
441}
442
443QString Identity::dictionary() const
444{
445 return property(QLatin1StringView(s_dict)).toString();
446}
447
448QString Identity::templates() const
449{
450 const QString str = property(QLatin1StringView(s_templates)).toString();
451 return verifyAkonadiId(str);
452}
453
454QString Identity::drafts() const
455{
456 const QString str = property(QLatin1StringView(s_drafts)).toString();
457 return verifyAkonadiId(str);
458}
459
460QString Identity::fcc() const
461{
462 const QString str = property(QLatin1StringView(s_fcc)).toString();
463 return verifyAkonadiId(str);
464}
465
466QString Identity::transport() const
467{
468 return property(QLatin1StringView(s_transport)).toString();
469}
470
472{
473 return mSignature.type() == Signature::FromCommand;
474}
475
477{
478 return mSignature.type() == Signature::FromFile;
479}
480
482{
483 return mSignature.type() == Signature::Inlined;
484}
485
490
492{
493 return mSignature.text();
494}
495
497{
498 return mSignature.path();
499}
500
501QString Identity::autocorrectionLanguage() const
502{
503 return property(QLatin1StringView(s_autocorrectionLanguage)).toString();
504}
505
506// --------------------- Setters -----------------------------//
507
508void Identity::setProperty(const QString &key, const QVariant &value)
509{
510 if (key == QLatin1StringView(s_signature)) {
511 mSignature = value.value<Signature>();
512 } else {
513 if (value.isNull() || (value.metaType().id() == QMetaType::QString && value.toString().isEmpty())) {
514 mPropertiesMap.remove(key);
515 } else {
516 mPropertiesMap.insert(key, value);
517 }
518 }
519}
520
521void Identity::setUoid(uint aUoid)
522{
523 setProperty(QLatin1StringView(s_uoid), aUoid);
524}
525
527{
528 setProperty(QLatin1StringView(s_identity), name);
529}
530
531void Identity::setFullName(const QString &str)
532{
533 setProperty(QLatin1StringView(s_name), str);
534}
535
536void Identity::setOrganization(const QString &str)
537{
538 setProperty(QLatin1StringView(s_organization), str);
539}
540
541void Identity::setPGPSigningKey(const QByteArray &str)
542{
544}
545
546void Identity::setPGPEncryptionKey(const QByteArray &str)
547{
549}
550
551void Identity::setSMIMESigningKey(const QByteArray &str)
552{
554}
555
556void Identity::setSMIMEEncryptionKey(const QByteArray &str)
557{
559}
560
561void Identity::setPrimaryEmailAddress(const QString &email)
562{
563 setProperty(QLatin1StringView(s_primaryEmail), email);
564}
565
566void Identity::setEmailAliases(const QStringList &aliases)
567{
568 setProperty(QLatin1StringView(s_emailAliases), aliases);
569}
570
571const QStringList Identity::activities() const
572{
573 return property(QLatin1StringView(s_activities)).toStringList();
574}
575
576void Identity::setActivities(const QStringList &a)
577{
578 setProperty(QLatin1StringView(s_activities), a);
579}
580
581bool Identity::enabledActivities() const
582{
583 return property(QLatin1StringView(s_enabledActivities)).toBool();
584}
585
586void Identity::setEnabledActivities(bool a)
587{
588 setProperty(QLatin1StringView(s_enabledActivities), a);
589}
590
591void Identity::setVCardFile(const QString &str)
592{
593 setProperty(QLatin1StringView(s_vcard), str);
594}
595
596void Identity::setAttachVcard(bool attachment)
597{
598 setProperty(QLatin1StringView(s_attachVcard), attachment);
599}
600
601void Identity::setReplyToAddr(const QString &str)
602{
603 setProperty(QLatin1StringView(s_replyto), str);
604}
605
606void Identity::setSignatureFile(const QString &str)
607{
608 mSignature.setPath(str, signatureIsCommand());
609}
610
611void Identity::setSignatureInlineText(const QString &str)
612{
613 mSignature.setText(str);
614}
615
616void Identity::setTransport(const QString &str)
617{
618 setProperty(QLatin1StringView(s_transport), str);
619}
620
621void Identity::setFcc(const QString &str)
622{
623 setProperty(QLatin1StringView(s_fcc), str);
624}
625
626void Identity::setDrafts(const QString &str)
627{
628 setProperty(QLatin1StringView(s_drafts), str);
629}
630
631void Identity::setTemplates(const QString &str)
632{
633 setProperty(QLatin1StringView(s_templates), str);
634}
635
636void Identity::setDictionary(const QString &str)
637{
638 setProperty(QLatin1StringView(s_dict), str);
639}
640
641void Identity::setBcc(const QString &str)
642{
643 setProperty(QLatin1StringView(s_bcc), str);
644}
645
646void Identity::setCc(const QString &str)
647{
648 setProperty(QLatin1StringView(s_cc), str);
649}
650
652{
653 mIsDefault = flag;
654}
655
656void Identity::setPreferredCryptoMessageFormat(const QString &str)
657{
658 setProperty(QLatin1StringView(s_prefcrypt), str);
659}
660
661void Identity::setXFace(const QString &str)
662{
663 QString strNew = str;
664 strNew.remove(QLatin1Char(' '));
665 strNew.remove(QLatin1Char('\n'));
666 strNew.remove(QLatin1Char('\r'));
667 setProperty(QLatin1StringView(s_xface), strNew);
668}
669
670void Identity::setXFaceEnabled(bool on)
671{
672 setProperty(QLatin1StringView(s_xfaceenabled), on);
673}
674
675void Identity::setFace(const QString &str)
676{
677 QString strNew = str;
678 strNew.remove(QLatin1Char(' '));
679 strNew.remove(QLatin1Char('\n'));
680 strNew.remove(QLatin1Char('\r'));
681 setProperty(QLatin1StringView(s_face), strNew);
682}
683
684void Identity::setFaceEnabled(bool on)
685{
686 setProperty(QLatin1StringView(s_faceenabled), on);
687}
688
689void Identity::setSignature(const Signature &sig)
690{
691 mSignature = sig;
692}
693
695{
696 const QString addrSpec = KEmailAddress::extractEmailAddress(addr).toLower();
697 if (addrSpec == primaryEmailAddress().toLower()) {
698 return true;
699 }
700
701 const QStringList lst = emailAliases();
702 for (const QString &alias : lst) {
703 if (alias.toLower() == addrSpec) {
704 return true;
705 }
706 }
707
708 return false;
709}
710
711void Identity::setAutocorrectionLanguage(const QString &language)
712{
713 setProperty(QLatin1StringView(s_autocorrectionLanguage), language);
714}
715
716bool Identity::disabledFcc() const
717{
718 const QVariant var = property(QLatin1StringView(s_disabledFcc));
719 if (var.isNull()) {
720 return false;
721 } else {
722 return var.toBool();
723 }
724}
725
726void Identity::setDisabledFcc(bool disable)
727{
728 setProperty(QLatin1StringView(s_disabledFcc), disable);
729}
730
731bool Identity::pgpAutoSign() const
732{
733 const QVariant var = property(QLatin1StringView(s_pgpautosign));
734 if (var.isNull()) {
735 return false;
736 } else {
737 return var.toBool();
738 }
739}
740
741void Identity::setPgpAutoSign(bool autoSign)
742{
743 setProperty(QLatin1StringView(s_pgpautosign), autoSign);
744}
745
746bool Identity::pgpAutoEncrypt() const
747{
748 const QVariant var = property(QLatin1StringView(s_pgpautoencrypt));
749 if (var.isNull()) {
750 return false;
751 } else {
752 return var.toBool();
753 }
754}
755
756void Identity::setPgpAutoEncrypt(bool autoEncrypt)
757{
758 setProperty(QLatin1StringView(s_pgpautoencrypt), autoEncrypt);
759}
760
761bool Identity::autocryptEnabled() const
762{
763 const auto var = property(QLatin1StringView(s_autocryptEnabled));
764 if (var.isNull()) {
765 return false;
766 } else {
767 return var.toBool();
768 }
769}
770
771void Identity::setAutocryptEnabled(const bool on)
772{
773 setProperty(QLatin1StringView(s_autocryptEnabled), on);
774}
775
776bool Identity::autocryptPrefer() const
777{
778 const auto var = property(QLatin1StringView(s_autocryptPrefer));
779 if (var.isNull()) {
780 return false;
781 } else {
782 return var.toBool();
783 }
784}
785
786void Identity::setAutocryptPrefer(const bool on)
787{
788 setProperty(QLatin1StringView(s_autocryptPrefer), on);
789}
790
791bool Identity::encryptionOverride() const
792{
793 const auto var = property(QLatin1StringView(s_encryptionOverride));
794 if (var.isNull()) {
795 return false;
796 } else {
797 return var.toBool();
798 }
799}
800
801void Identity::setEncryptionOverride(const bool on)
802{
803 setProperty(QLatin1StringView(s_encryptionOverride), on);
804}
805
806bool Identity::warnNotEncrypt() const
807{
808 const auto var = property(QLatin1StringView(s_warnnotencrypt));
809 if (var.isNull()) {
810 return false;
811 } else {
812 return var.toBool();
813 }
814}
815
816void Identity::setWarnNotEncrypt(const bool on)
817{
818 setProperty(QLatin1StringView(s_warnnotencrypt), on);
819}
820
821bool Identity::warnNotSign() const
822{
823 const auto var = property(QLatin1StringView(s_warnnotsign));
824 if (var.isNull()) {
825 return false;
826 } else {
827 return var.toBool();
828 }
829}
830
831void Identity::setWarnNotSign(const bool on)
832{
833 setProperty(QLatin1StringView(s_warnnotsign), on);
834}
835
836QString Identity::defaultDomainName() const
837{
838 return property(QLatin1StringView(s_defaultDomainName)).toString();
839}
840
841void Identity::setDefaultDomainName(const QString &domainName)
842{
843 setProperty(QLatin1StringView(s_defaultDomainName), domainName);
844}
845
847{
848 if (str.isEmpty()) {
849 return str;
850 }
851 bool ok = false;
852 const qlonglong val = str.toLongLong(&ok);
853 Q_UNUSED(val)
854 if (ok) {
855 return str;
856 } else {
857 return {};
858 }
859}
860
861#include "moc_identity.cpp"
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
QString readEntry(const char *key, const char *aDefault=nullptr) const
QMap< QString, QString > entryMap() const
User identity information.
Definition identity.h:74
bool operator!=(const Identity &other) const
used for comparison
Definition identity.cpp:271
bool matchesEmailAddress(const QString &addr) const
Definition identity.cpp:694
bool operator==(const Identity &other) const
used for comparison
Definition identity.cpp:242
void setUoid(uint aUoid)
Set the uiod.
Definition identity.cpp:521
QString signatureFile() const
name of the signature file (with path)
Definition identity.cpp:496
bool operator<=(const Identity &other) const
used for sorting
Definition identity.cpp:232
void setIsDefault(bool flag)
Set whether this identity is the default identity.
Definition identity.cpp:651
QVariant property(const QString &key) const
Get random properties.
Definition identity.cpp:278
QString signatureInlineText() const
inline signature
Definition identity.cpp:491
bool operator>=(const Identity &other) const
used for sorting
Definition identity.cpp:237
void writeConfig(KConfigGroup &) const
Write configuration to config.
Definition identity.cpp:107
void setProperty(const QString &key, const QVariant &value)
Set random properties, when value is empty (for QStrings) or null, the property is deleted.
Definition identity.cpp:508
void readConfig(const KConfigGroup &)
Read configuration from config.
Definition identity.cpp:81
Identity(const QString &id=QString(), const QString &realName=QString(), const QString &emailAddr=QString(), const QString &organization=QString(), const QString &replyToAddress=QString())
Constructor.
Definition identity.cpp:25
bool useSignatureFile() const
Inline or signature from a file.
Definition identity.cpp:486
bool operator<(const Identity &other) const
used for sorting
Definition identity.cpp:210
bool operator>(const Identity &other) const
used for sorting
Definition identity.cpp:221
void setIdentityName(const QString &name)
Identity/nickname for this collection.
Definition identity.cpp:526
QString verifyAkonadiId(const QString &str) const
during migration when it failed it can be a string => not a qlonglong akonadi::id => fix it
Definition identity.cpp:846
Abstraction of a signature (aka "footer").
Definition signature.h:61
void setPath(const QString &path, bool isExecutable=false)
Set the signature URL and mark this signature as being of "from file" resp.
void setText(const QString &text)
Set the signature text and mark this signature as being of "inline text" type.
QString withSeparator(bool *ok=nullptr, QString *errorMessage=nullptr) const
KCODECS_EXPORT QByteArray extractEmailAddress(const QByteArray &address)
QByteArray toLower() const const
const_iterator constBegin() const const
const_iterator constEnd() const const
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
bool remove(const Key &key)
T value(const Key &key) const const
QString localHostName()
const_iterator constBegin() const const
const_iterator constEnd() const const
int id() const const
QByteArray data(const QString &mimeType) const const
virtual bool hasFormat(const QString &mimeType) const const
void setData(const QString &mimeType, const QByteArray &data)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString & insert(qsizetype position, QChar ch)
bool isEmpty() const const
qsizetype length() const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
qlonglong toLongLong(bool *ok, int base) const const
QVariant fromValue(T &&value)
bool isNull() const const
QMetaType metaType() const const
bool toBool() const const
QByteArray toByteArray() const const
int toInt(bool *ok) const const
QString toString() const const
QStringList toStringList() const const
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:11:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.