Mailcommon

filteractiondecrypt.cpp
1/*
2 * SPDX-FileCopyrightText: 2017 Daniel Vrátil <dvratil@kde.org>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 *
6 */
7
8#include "filteractiondecrypt.h"
9#include "mailcommon_debug.h"
10#include "util/cryptoutils.h"
11
12#include <KColorScheme>
13#include <KLocalizedString>
14
15#include <KMime/Message>
16
17#include <gpgme++/decryptionresult.h>
18
19#include <Akonadi/MessageFlags>
20
21#include <QLabel>
22#include <QVBoxLayout>
23
24using namespace MailCommon;
25
26FilterActionDecrypt::FilterActionDecrypt(QObject *parent)
27 : FilterActionWithCrypto(QStringLiteral("decrypt"), i18n("Decrypt"), parent)
28{
29}
30
31FilterActionDecrypt::~FilterActionDecrypt() = default;
32
33FilterAction *FilterActionDecrypt::newAction()
34{
35 return new FilterActionDecrypt();
36}
37
38QString FilterActionDecrypt::displayString() const
39{
40 return i18n("Decrypt");
41}
42
43QString FilterActionDecrypt::argsAsString() const
44{
45 return {};
46}
47
48void FilterActionDecrypt::argsFromString(const QString &)
49{
50}
51
52SearchRule::RequiredPart FilterActionDecrypt::requiredPart() const
53{
55}
56
57FilterAction::ReturnCode FilterActionDecrypt::process(ItemContext &context, bool) const
58{
59 auto &item = context.item();
60 if (!item.hasPayload<KMime::Message::Ptr>()) {
61 return ErrorNeedComplete;
62 }
63
64 auto msg = item.payload<KMime::Message::Ptr>();
65 if (!isEncrypted(msg.data())) {
66 qCDebug(MAILCOMMON_LOG) << "Message not encrypted";
67 return GoOn;
68 }
69
70 bool wasEncrypted;
71 auto nec = CryptoUtils::decryptMessage(msg, wasEncrypted);
72 if (!nec) {
73 return wasEncrypted ? ErrorButGoOn : GoOn;
74 }
75
76 context.item().setPayload(nec);
78 context.setNeedsPayloadStore();
79 context.setNeedsFlagStore();
80 return GoOn;
81}
82
83QWidget *FilterActionDecrypt::createParamWidget(QWidget *parent) const
84{
85 auto w = new QWidget(parent);
86 auto l = new QVBoxLayout(w);
87
88 auto lbl = new QLabel(w);
89
90 QPalette palette = lbl->palette();
91 palette.setColor(lbl->foregroundRole(), KColorScheme(QPalette::Normal).foreground(KColorScheme::NegativeText).color());
92 lbl->setPalette(palette);
93 lbl->setWordWrap(true);
94
95 lbl->setText(i18n("<b>Warning:</b> Decrypted emails may be uploaded to a server!"));
96 lbl->setToolTip(
97 i18n("<p>If the email folder that you are filtering into is connected to a remote "
98 "account (like an IMAP-Server) the decrypted content will go there.</p>"));
99 l->addWidget(lbl);
100
101 return w;
102}
103
104#include "moc_filteractiondecrypt.cpp"
void clearFlag(const QByteArray &name)
void setPayload(const T &p)
T payload() const
Abstract base class for mail filter actions.
ReturnCode
Describes the possible return codes of filter processing:
@ ErrorNeedComplete
Could not process because a complete message is needed.
@ ErrorButGoOn
A non-critical error occurred.
@ GoOn
Go on with applying filter actions.
A helper class for the filtering process.
Definition itemcontext.h:27
void setNeedsPayloadStore()
Marks that the item's payload has been changed and needs to be written back.
Akonadi::Item & item()
Returns the item of the context.
void setNeedsFlagStore()
Marks that the item's flags has been changed and needs to be written back.
RequiredPart
Possible required parts.
Definition searchrule.h:68
@ CompleteMessage
Whole message.
Definition searchrule.h:71
QString i18n(const char *text, const TYPE &arg...)
AKONADI_MIME_EXPORT const char Encrypted[]
The filter dialog.
QObject * parent() const const
void setColor(ColorGroup group, ColorRole role, const QColor &color)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.