Mailcommon

searchruleencryption.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#include "searchruleencryption.h"
8#include "filter/filterlog.h"
9#include "util/cryptoutils.h"
11#include <KMime/Message>
12
13using namespace MailCommon;
14
15SearchRuleEncryption::SearchRuleEncryption(const QByteArray &field, Function func, const QString &contents)
16 : SearchRule(field, func, contents)
17{
18}
19
20SearchRuleEncryption::~SearchRuleEncryption() = default;
21
22bool SearchRuleEncryption::isEmpty() const
23{
24 // It's true or false, so it can't be empty
25 return false;
26}
27
28bool SearchRuleEncryption::matches(const Akonadi::Item &item) const
29{
30 const bool shouldBeEncrypted = (function() == FuncEquals);
31
32 if (!item.hasPayload<KMime::Message::Ptr>()) {
33 return false;
34 }
35 const auto msg = item.payload<KMime::Message::Ptr>();
36
37 const bool rc = (shouldBeEncrypted == CryptoUtils::isEncrypted(msg.data()));
38 if (FilterLog::instance()->isLogging()) {
39 QString msg = (rc ? QStringLiteral("<font color=#00FF00>1 = </font>") : QStringLiteral("<font color=#FF0000>0 = </font>"));
41 msg += QLatin1StringView(" ( <i>") + contents() + QLatin1StringView("</i> )"); // TODO change with locale?
43 }
44 return rc;
45}
46
47SearchRule::RequiredPart SearchRuleEncryption::requiredPart() const
48{
49 // We can't detect inline signatures just from headers, we need to inspect
50 // the entire body.
52}
bool hasPayload() const
T payload() const
KMail Filter Log Collector.
Definition filterlog.h:33
void add(const QString &entry, ContentType type)
Adds the given log entry under the given content type to the log.
@ RuleResult
Log all rule matching results.
Definition filterlog.h:53
static QString recode(const QString &plain)
Returns an escaped version of the log which can be used in a HTML document.
static FilterLog * instance()
Returns the single global instance of the filter log.
Definition filterlog.cpp:71
This class represents one search pattern rule.
Definition searchrule.h:24
Function function() const
Returns the filter function of the rule.
QString contents() const
Returns the contents of the rule.
RequiredPart
Possible required parts.
Definition searchrule.h:68
@ CompleteMessage
Whole message.
Definition searchrule.h:71
const QString asString() const
Returns the rule as string for debugging purpose.
The filter dialog.
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.