Messagelib

draftstatus.cpp
1/*
2 SPDX-FileCopyrightText: 2021 Sandro Knauß <sknauss@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "draftstatus.h"
8
9#include <MessageCore/AutocryptUtils>
10
11using namespace MessageComposer;
12
13void MessageComposer::removeDraftCryptoHeaders(const KMime::Message::Ptr &msg)
14{
15 DraftEncryptionState(msg).removeState();
16 DraftSignatureState(msg).removeState();
17 DraftCryptoMessageFormatState(msg).removeState();
18}
19
20DraftEncryptionState::DraftEncryptionState(const KMime::Message::Ptr &msg)
21 : mMsg(msg)
22{
23}
24
25void 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
32void DraftEncryptionState::removeState()
33{
34 mMsg->removeHeader("X-KMail-EncryptActionEnabled");
35}
36
37bool 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
47bool DraftEncryptionState::isDefined() const
48{
49 return mMsg->hasHeader("X-KMail-EncryptActionEnabled");
50}
51
52DraftSignatureState::DraftSignatureState(const KMime::Message::Ptr &msg)
53 : mMsg(msg)
54{
55}
56
57void 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
64void DraftSignatureState::removeState()
65{
66 mMsg->removeHeader("X-KMail-SignatureActionEnabled");
67}
68
69bool 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
79bool DraftSignatureState::isDefined() const
80{
81 return mMsg->hasHeader("X-KMail-SignatureActionEnabled");
82}
83
84DraftCryptoMessageFormatState::DraftCryptoMessageFormatState(const KMime::Message::Ptr &msg)
85 : mMsg(msg)
86{
87}
88
89void 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
96void DraftCryptoMessageFormatState::removeState()
97{
98 mMsg->removeHeader("X-KMail-CryptoMessageFormat");
99}
100
101Kleo::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
111bool DraftCryptoMessageFormatState::isDefined() const
112{
113 return mMsg->hasHeader("X-KMail-CryptoMessageFormat");
114}
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
QString number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:12:43 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.