Mailcommon

filteractionsetstatus.cpp
1/*
2 * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <taferner@kde.org>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 *
6 */
7
8#include "filteractionsetstatus.h"
9#include "mailcommon_debug.h"
10#include <Akonadi/MessageStatus>
11#include <KLocalizedString>
12using namespace MailCommon;
13
14FilterAction *FilterActionSetStatus::newAction()
15{
16 return new FilterActionSetStatus;
17}
18
19FilterActionSetStatus::FilterActionSetStatus(QObject *parent)
20 : FilterActionStatus(QStringLiteral("set status"), i18n("Mark As"), parent)
21{
22}
23
24bool FilterActionSetStatus::isEmpty() const
25{
26 const int index = mParameterList.indexOf(mParameter);
27 return index < 1;
28}
29
30QString FilterActionSetStatus::informationAboutNotValidAction() const
31{
32 return i18n("Status not specified.");
33}
34
35FilterAction::ReturnCode FilterActionSetStatus::process(ItemContext &context, bool) const
36{
37 const int index = mParameterList.indexOf(mParameter);
38 if (index < 1) {
39 return ErrorButGoOn;
40 }
41
44
46 const Akonadi::MessageStatus newStatus = FilterActionStatus::statuses[index - 1];
47 if (newStatus == Akonadi::MessageStatus::statusUnread()) {
48 status.setRead(false);
49 } else {
50 status.set(newStatus);
51 }
52 if (oldStatus != status) {
53 context.item().setFlags(status.statusFlags());
54 context.setNeedsFlagStore();
55 }
56
57 return GoOn;
58}
59
60SearchRule::RequiredPart FilterActionSetStatus::requiredPart() const
61{
63}
64
65QString FilterActionSetStatus::sieveCode() const
66{
67 QString flagCode;
68 const QString parameter = argsAsString();
69 if (parameter == QLatin1Char('R')) {
70 flagCode = QStringLiteral("\\\\Seen");
71 } else if (parameter == QLatin1Char('D')) {
72 flagCode = QStringLiteral("\\\\Deleted");
73 } else if (parameter == QLatin1Char('A')) {
74 flagCode = QStringLiteral("\\\\Answered");
75 } else {
76 qCDebug(MAILCOMMON_LOG) << " FilterActionSetStatus::sieveCode() unknown flags" << parameter;
77 flagCode = parameter;
78 }
79
80 const QString result = QStringLiteral("setflag \"%1\";").arg(flagCode);
81 return result;
82}
83
84QStringList FilterActionSetStatus::sieveRequires() const
85{
86 return QStringList() << QStringLiteral("imap4flags");
87}
88
89#include "moc_filteractionsetstatus.cpp"
Flags flags() const
void setFlags(const Flags &flags)
static const MessageStatus statusUnread()
void setStatusFromFlags(const QSet< QByteArray > &flags)
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 i18n(const char *text, const TYPE &arg...)
The filter dialog.
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.