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)];
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)];
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
581void Identity::setVCardFile(const QString &str)
582{
583 setProperty(QLatin1StringView(s_vcard), str);
584}
585
586void Identity::setAttachVcard(bool attachment)
587{
588 setProperty(QLatin1StringView(s_attachVcard), attachment);
589}
590
591void Identity::setReplyToAddr(const QString &str)
592{
593 setProperty(QLatin1StringView(s_replyto), str);
594}
595
596void Identity::setSignatureFile(const QString &str)
597{
598 mSignature.setPath(str, signatureIsCommand());
599}
600
601void Identity::setSignatureInlineText(const QString &str)
602{
603 mSignature.setText(str);
604}
605
606void Identity::setTransport(const QString &str)
607{
608 setProperty(QLatin1StringView(s_transport), str);
609}
610
611void Identity::setFcc(const QString &str)
612{
613 setProperty(QLatin1StringView(s_fcc), str);
614}
615
616void Identity::setDrafts(const QString &str)
617{
618 setProperty(QLatin1StringView(s_drafts), str);
619}
620
621void Identity::setTemplates(const QString &str)
622{
623 setProperty(QLatin1StringView(s_templates), str);
624}
625
626void Identity::setDictionary(const QString &str)
627{
628 setProperty(QLatin1StringView(s_dict), str);
629}
630
631void Identity::setBcc(const QString &str)
632{
633 setProperty(QLatin1StringView(s_bcc), str);
634}
635
636void Identity::setCc(const QString &str)
637{
638 setProperty(QLatin1StringView(s_cc), str);
639}
640
642{
643 mIsDefault = flag;
644}
645
646void Identity::setPreferredCryptoMessageFormat(const QString &str)
647{
648 setProperty(QLatin1StringView(s_prefcrypt), str);
649}
650
651void Identity::setXFace(const QString &str)
652{
653 QString strNew = str;
654 strNew.remove(QLatin1Char(' '));
655 strNew.remove(QLatin1Char('\n'));
656 strNew.remove(QLatin1Char('\r'));
657 setProperty(QLatin1StringView(s_xface), strNew);
658}
659
660void Identity::setXFaceEnabled(bool on)
661{
662 setProperty(QLatin1StringView(s_xfaceenabled), on);
663}
664
665void Identity::setFace(const QString &str)
666{
667 QString strNew = str;
668 strNew.remove(QLatin1Char(' '));
669 strNew.remove(QLatin1Char('\n'));
670 strNew.remove(QLatin1Char('\r'));
671 setProperty(QLatin1StringView(s_face), strNew);
672}
673
674void Identity::setFaceEnabled(bool on)
675{
676 setProperty(QLatin1StringView(s_faceenabled), on);
677}
678
679void Identity::setSignature(const Signature &sig)
680{
681 mSignature = sig;
682}
683
685{
686 const QString addrSpec = KEmailAddress::extractEmailAddress(addr).toLower();
687 if (addrSpec == primaryEmailAddress().toLower()) {
688 return true;
689 }
690
691 const QStringList lst = emailAliases();
692 for (const QString &alias : lst) {
693 if (alias.toLower() == addrSpec) {
694 return true;
695 }
696 }
697
698 return false;
699}
700
701void Identity::setAutocorrectionLanguage(const QString &language)
702{
703 setProperty(QLatin1StringView(s_autocorrectionLanguage), language);
704}
705
706bool Identity::disabledFcc() const
707{
708 const QVariant var = property(QLatin1StringView(s_disabledFcc));
709 if (var.isNull()) {
710 return false;
711 } else {
712 return var.toBool();
713 }
714}
715
716void Identity::setDisabledFcc(bool disable)
717{
718 setProperty(QLatin1StringView(s_disabledFcc), disable);
719}
720
721bool Identity::pgpAutoSign() const
722{
723 const QVariant var = property(QLatin1StringView(s_pgpautosign));
724 if (var.isNull()) {
725 return false;
726 } else {
727 return var.toBool();
728 }
729}
730
731void Identity::setPgpAutoSign(bool autoSign)
732{
733 setProperty(QLatin1StringView(s_pgpautosign), autoSign);
734}
735
736bool Identity::pgpAutoEncrypt() const
737{
738 const QVariant var = property(QLatin1StringView(s_pgpautoencrypt));
739 if (var.isNull()) {
740 return false;
741 } else {
742 return var.toBool();
743 }
744}
745
746void Identity::setPgpAutoEncrypt(bool autoEncrypt)
747{
748 setProperty(QLatin1StringView(s_pgpautoencrypt), autoEncrypt);
749}
750
751bool Identity::autocryptEnabled() const
752{
753 const auto var = property(QLatin1StringView(s_autocryptEnabled));
754 if (var.isNull()) {
755 return false;
756 } else {
757 return var.toBool();
758 }
759}
760
761void Identity::setAutocryptEnabled(const bool on)
762{
763 setProperty(QLatin1StringView(s_autocryptEnabled), on);
764}
765
766bool Identity::autocryptPrefer() const
767{
768 const auto var = property(QLatin1StringView(s_autocryptPrefer));
769 if (var.isNull()) {
770 return false;
771 } else {
772 return var.toBool();
773 }
774}
775
776void Identity::setAutocryptPrefer(const bool on)
777{
778 setProperty(QLatin1StringView(s_autocryptPrefer), on);
779}
780
781bool Identity::encryptionOverride() const
782{
783 const auto var = property(QLatin1StringView(s_encryptionOverride));
784 if (var.isNull()) {
785 return false;
786 } else {
787 return var.toBool();
788 }
789}
790
791void Identity::setEncryptionOverride(const bool on)
792{
793 setProperty(QLatin1StringView(s_encryptionOverride), on);
794}
795
796bool Identity::warnNotEncrypt() const
797{
798 const auto var = property(QLatin1StringView(s_warnnotencrypt));
799 if (var.isNull()) {
800 return false;
801 } else {
802 return var.toBool();
803 }
804}
805
806void Identity::setWarnNotEncrypt(const bool on)
807{
808 setProperty(QLatin1StringView(s_warnnotencrypt), on);
809}
810
811bool Identity::warnNotSign() const
812{
813 const auto var = property(QLatin1StringView(s_warnnotsign));
814 if (var.isNull()) {
815 return false;
816 } else {
817 return var.toBool();
818 }
819}
820
821void Identity::setWarnNotSign(const bool on)
822{
823 setProperty(QLatin1StringView(s_warnnotsign), on);
824}
825
826QString Identity::defaultDomainName() const
827{
828 return property(QLatin1StringView(s_defaultDomainName)).toString();
829}
830
831void Identity::setDefaultDomainName(const QString &domainName)
832{
833 setProperty(QLatin1StringView(s_defaultDomainName), domainName);
834}
835
837{
838 if (str.isEmpty()) {
839 return str;
840 }
841 bool ok = false;
842 const qlonglong val = str.toLongLong(&ok);
843 Q_UNUSED(val)
844 if (ok) {
845 return str;
846 } else {
847 return {};
848 }
849}
850
851#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:73
bool operator!=(const Identity &other) const
used for comparison
Definition identity.cpp:271
bool matchesEmailAddress(const QString &addr) const
Definition identity.cpp:684
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:641
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:836
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 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.