Messagelib

draftstatus.cpp
1 /*
2  SPDX-FileCopyrightText: 2021 Sandro KnauƟ <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "draftstatus.h"
8 
9 #include <MessageCore/AutocryptUtils>
10 
11 using namespace MessageComposer;
12 
13 void MessageComposer::removeDraftCryptoHeaders(const KMime::Message::Ptr &msg)
14 {
15  DraftEncryptionState(msg).removeState();
16  DraftSignatureState(msg).removeState();
17  DraftCryptoMessageFormatState(msg).removeState();
18 }
19 
20 DraftEncryptionState::DraftEncryptionState(const KMime::Message::Ptr &msg)
21  : mMsg(msg)
22 {
23 }
24 
25 void DraftEncryptionState::setState(bool encrypt)
26 {
27  auto hdr = new KMime::Headers::Generic("X-KMail-EncryptActionEnabled");
28  hdr->fromUnicodeString(encrypt ? QStringLiteral("true") : QStringLiteral("false"), "utf-8");
29  mMsg->setHeader(hdr);
30 }
31 
32 void DraftEncryptionState::removeState()
33 {
34  mMsg->removeHeader("X-KMail-EncryptActionEnabled");
35 }
36 
37 bool DraftEncryptionState::encryptionState() const
38 {
39  if (isDefined()) {
40  auto hdr = mMsg->headerByType("X-KMail-EncryptActionEnabled");
41  return hdr->as7BitString(false).contains("true");
42  }
43 
44  return false;
45 }
46 
47 bool DraftEncryptionState::isDefined() const
48 {
49  return mMsg->hasHeader("X-KMail-EncryptActionEnabled");
50 }
51 
52 DraftSignatureState::DraftSignatureState(const KMime::Message::Ptr &msg)
53  : mMsg(msg)
54 {
55 }
56 
57 void DraftSignatureState::setState(bool sign)
58 {
59  auto hdr = new KMime::Headers::Generic("X-KMail-SignatureActionEnabled");
60  hdr->fromUnicodeString(sign ? QStringLiteral("true") : QStringLiteral("false"), "utf-8");
61  mMsg->setHeader(hdr);
62 }
63 
64 void DraftSignatureState::removeState()
65 {
66  mMsg->removeHeader("X-KMail-SignatureActionEnabled");
67 }
68 
69 bool DraftSignatureState::signState() const
70 {
71  if (isDefined()) {
72  auto hdr = mMsg->headerByType("X-KMail-SignatureActionEnabled");
73  return hdr->as7BitString(false).contains("true");
74  }
75 
76  return false;
77 }
78 
79 bool DraftSignatureState::isDefined() const
80 {
81  return mMsg->hasHeader("X-KMail-SignatureActionEnabled");
82 }
83 
84 DraftCryptoMessageFormatState::DraftCryptoMessageFormatState(const KMime::Message::Ptr &msg)
85  : mMsg(msg)
86 {
87 }
88 
89 void DraftCryptoMessageFormatState::setState(Kleo::CryptoMessageFormat cryptoMessageFormat)
90 {
91  auto hdr = new KMime::Headers::Generic("X-KMail-CryptoMessageFormat");
92  hdr->fromUnicodeString(QString::number(cryptoMessageFormat), "utf-8");
93  mMsg->setHeader(hdr);
94 }
95 
96 void DraftCryptoMessageFormatState::removeState()
97 {
98  mMsg->removeHeader("X-KMail-CryptoMessageFormat");
99 }
100 
101 Kleo::CryptoMessageFormat DraftCryptoMessageFormatState::cryptoMessageFormatState() const
102 {
103  if (isDefined()) {
104  auto hdr = mMsg->headerByType("X-KMail-CryptoMessageFormat");
105  return static_cast<Kleo::CryptoMessageFormat>(hdr->asUnicodeString().toInt());
106  }
107 
108  return Kleo::AutoFormat;
109 }
110 
111 bool DraftCryptoMessageFormatState::isDefined() const
112 {
113  return mMsg->hasHeader("X-KMail-CryptoMessageFormat");
114 }
QString number(int n, int base)
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 23:04:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.