Mailcommon

searchruleinvitation.cpp
1/*
2 SPDX-FileCopyrightText: 2024 Laurent Montel <montel@kde.org
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "searchruleinvitation.h"
8#include "filter/filterlog.h"
10#include <Akonadi/MessageStatus>
11#include <KMime/Message>
12
13using namespace MailCommon;
14
15SearchRuleInvitation::SearchRuleInvitation(const QByteArray &field, Function func, const QString &contents)
16 : SearchRule(field, func, contents)
17{
18}
19
20SearchRuleInvitation::~SearchRuleInvitation() = default;
21
22bool SearchRuleInvitation::isEmpty() const
23{
24 // It's true or false, so it can't be empty
25 return false;
26}
27
28bool SearchRuleInvitation::matches(const Akonadi::Item &item) const
29{
30 if (!item.hasPayload<KMime::Message::Ptr>()) {
31 return false;
32 }
35 bool rc = false;
36 switch (function()) {
37 case FuncEquals:
39 rc = true;
40 }
41 break;
42 case FuncNotEqual:
44 rc = true;
45 }
46 break;
47 default:
48 break;
49 }
50
51 if (FilterLog::instance()->isLogging()) {
52 QString msg = (rc ? QStringLiteral("<font color=#00FF00>1 = </font>") : QStringLiteral("<font color=#FF0000>0 = </font>"));
54 msg += QLatin1StringView(" ( <i>") + contents() + QLatin1StringView("</i> )"); // TODO change with locale?
56 }
57 return rc;
58}
59
60SearchRule::RequiredPart SearchRuleInvitation::requiredPart() const
61{
63}
64
65void SearchRuleInvitation::addQueryTerms(Akonadi::SearchTerm &groupTerm, bool &emptyIsNotAnError) const
66{
67 using namespace Akonadi;
68 emptyIsNotAnError = true;
69 EmailSearchTerm term(EmailSearchTerm::MessageStatus, MessageStatus::statusHasInvitation().statusFlags().values().first(), akonadiComparator());
70 term.setIsNegated(isNegated());
71 groupTerm.addSubTerm(term);
72}
Flags flags() const
bool hasPayload() const
static const MessageStatus statusHasInvitation()
void setStatusFromFlags(const QSet< QByteArray > &flags)
void addSubTerm(const SearchTerm &term)
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.
Akonadi::SearchTerm::Condition akonadiComparator() const
Converts the rule function into the corresponding Akonadi query operator.
RequiredPart
Possible required parts.
Definition searchrule.h:70
bool isNegated() const
Helper that returns whether the rule has a negated function.
const QString asString() const
Returns the rule as string for debugging purpose.
Q_SCRIPTABLE CaptureState status()
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.