Mailcommon

filteractionunsetstatus.cpp
1/*
2
3 SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#include "filteractionunsetstatus.h"
9#include "mailcommon_debug.h"
10#include <KLocalizedString>
11using namespace MailCommon;
12
13FilterAction *FilterActionUnsetStatus::newAction()
14{
15 return new FilterActionUnsetStatus;
16}
17
18FilterActionUnsetStatus::FilterActionUnsetStatus(QObject *parent)
19 : FilterActionStatus(QStringLiteral("unset status"), i18nc("action: to unset the status", "Unset Status"), parent)
20{
21}
22
23bool FilterActionUnsetStatus::checkIsValid(int &index) const
24{
25 index = mParameterList.indexOf(mParameter);
26 return index < 1;
27}
28
29bool FilterActionUnsetStatus::isEmpty() const
30{
31 int index = 0;
32 return checkIsValid(index);
33}
34
35QString FilterActionUnsetStatus::informationAboutNotValidAction() const
36{
37 return i18n("Status not defined.");
38}
39
40FilterAction::ReturnCode FilterActionUnsetStatus::process(ItemContext &context, bool) const
41{
42 int index = 0;
43 if (checkIsValid(index)) {
44 return ErrorButGoOn;
45 }
46
49
50 Akonadi::MessageStatus newStatus = FilterActionStatus::statuses[index - 1];
51 // Laurent unread status doesn't exist. And crash if we use "const Akonadi::Item::Flag flag = *(flags.begin());" etc. => if we unset "unread" we set read
52 if (newStatus == Akonadi::MessageStatus::statusUnread()) {
54 newStatus.setRead(true);
55 if (oldStatus != newStatus) {
56 context.item().setFlags(newStatus.statusFlags());
57 context.setNeedsFlagStore();
58 }
59 return GoOn;
60 }
61
62 QSet<QByteArray> flags = newStatus.statusFlags();
63 const Akonadi::Item::Flag flag = *(flags.begin());
64 if (context.item().hasFlag(flag)) {
65 context.item().clearFlag(flag);
66 context.setNeedsFlagStore();
67 }
68 return GoOn;
69}
70
71SearchRule::RequiredPart FilterActionUnsetStatus::requiredPart() const
72{
74}
75
76QString FilterActionUnsetStatus::sieveCode() const
77{
78 QString flagCode;
79 const QString parameter = argsAsString();
80 if (parameter == QLatin1Char('R')) {
81 flagCode = QStringLiteral("\\\\Seen");
82 } else if (parameter == QLatin1Char('D')) {
83 flagCode = QStringLiteral("\\\\Deleted");
84 } else if (parameter == QLatin1Char('A')) {
85 flagCode = QStringLiteral("\\\\Answered");
86 } else {
87 qCDebug(MAILCOMMON_LOG) << " FilterActionSetStatus::sieveCode() unknown flags" << parameter;
88 flagCode = parameter;
89 }
90
91 const QString result = QStringLiteral("removeflag \"%1\";").arg(flagCode);
92 return result;
93}
94
95QStringList FilterActionUnsetStatus::sieveRequires() const
96{
97 return QStringList() << QStringLiteral("imap4flags");
98}
99
100#include "moc_filteractionunsetstatus.cpp"
bool hasFlag(const QByteArray &name) const
void clearFlag(const QByteArray &name)
Flags flags() const
void setFlags(const Flags &flags)
static const MessageStatus statusUnread()
void setRead(bool read=true)
void setStatusFromFlags(const QSet< QByteArray > &flags)
QSet< QByteArray > statusFlags() const
Abstract base class for mail filter actions.
ReturnCode
Describes the possible return codes of filter processing:
@ ErrorButGoOn
A non-critical error occurred.
@ GoOn
Go on with applying filter actions.
A helper class for the filtering process.
Definition itemcontext.h:27
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
Q_SCRIPTABLE CaptureState status()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
The filter dialog.
iterator begin()
QString arg(Args &&... args) const const
qsizetype indexOf(const QRegularExpression &re, qsizetype from) const const
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.