Mailcommon

searchruleencryption.cpp
1 /*
2  SPDX-FileCopyrightText: 2017 Daniel Vr├ítil <[email protected]>
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 
13 using namespace MailCommon;
14 
15 SearchRuleEncryption::SearchRuleEncryption(const QByteArray &field, Function func, const QString &contents)
16  : SearchRule(field, func, contents)
17 {
18 }
19 
20 SearchRuleEncryption::~SearchRuleEncryption() = default;
21 
22 bool SearchRuleEncryption::isEmpty() const
23 {
24  // It's true or false, so it can't be empty
25  return false;
26 }
27 
28 bool 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>"));
40  msg += FilterLog::recode(asString());
41  msg += QLatin1String(" ( <i>") + contents() + QLatin1String("</i> )"); // TODO change with locale?
43  }
44  return rc;
45 }
46 
47 SearchRule::RequiredPart SearchRuleEncryption::requiredPart() const
48 {
49  // We can't detect inline signatures just from headers, we need to inspect
50  // the entire body.
52 }
static QString recode(const QString &plain)
Returns an escaped version of the log which can be used in a HTML document.
Definition: filterlog.cpp:189
@ RuleResult
Log all rule matching results.
Definition: filterlog.h:53
KMail Filter Log Collector.
Definition: filterlog.h:32
bool hasPayload() const
RequiredPart
Possible required parts.
Definition: searchrule.h:68
static FilterLog * instance()
Returns the single global instance of the filter log.
Definition: filterlog.cpp:72
This class represents one search pattern rule.
Definition: searchrule.h:23
bool isLogging() const
Returns whether the filter log is currently active.
Definition: filterlog.cpp:81
@ CompleteMessage
Whole message.
Definition: searchrule.h:71
void add(const QString &entry, ContentType type)
Adds the given log entry under the given content type to the log.
Definition: filterlog.cpp:129
The filter dialog.
T payload() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Oct 1 2022 04:00:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.