File indexing completed on 2024-11-17 04:51:14
0001 /* 0002 SPDX-FileCopyrightText: 2017 Daniel Vrátil <dvratil@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "searchruleencryption.h" 0008 #include "filter/filterlog.h" 0009 #include "util/cryptoutils.h" 0010 using MailCommon::FilterLog; 0011 #include <KMime/Message> 0012 0013 using namespace MailCommon; 0014 0015 SearchRuleEncryption::SearchRuleEncryption(const QByteArray &field, Function func, const QString &contents) 0016 : SearchRule(field, func, contents) 0017 { 0018 } 0019 0020 SearchRuleEncryption::~SearchRuleEncryption() = default; 0021 0022 bool SearchRuleEncryption::isEmpty() const 0023 { 0024 // It's true or false, so it can't be empty 0025 return false; 0026 } 0027 0028 bool SearchRuleEncryption::matches(const Akonadi::Item &item) const 0029 { 0030 const bool shouldBeEncrypted = (function() == FuncEquals); 0031 0032 if (!item.hasPayload<KMime::Message::Ptr>()) { 0033 return false; 0034 } 0035 const auto msg = item.payload<KMime::Message::Ptr>(); 0036 0037 const bool rc = (shouldBeEncrypted == CryptoUtils::isEncrypted(msg.data())); 0038 if (FilterLog::instance()->isLogging()) { 0039 QString msg = (rc ? QStringLiteral("<font color=#00FF00>1 = </font>") : QStringLiteral("<font color=#FF0000>0 = </font>")); 0040 msg += FilterLog::recode(asString()); 0041 msg += QLatin1StringView(" ( <i>") + contents() + QLatin1StringView("</i> )"); // TODO change with locale? 0042 FilterLog::instance()->add(msg, FilterLog::RuleResult); 0043 } 0044 return rc; 0045 } 0046 0047 SearchRule::RequiredPart SearchRuleEncryption::requiredPart() const 0048 { 0049 // We can't detect inline signatures just from headers, we need to inspect 0050 // the entire body. 0051 return SearchRule::CompleteMessage; 0052 }