Mailcommon

filteractionsendfakedisposition.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 "filteractionsendfakedisposition.h"
9
10#include <Akonadi/MDNStateAttribute>
11#include <KLocalizedString>
12
13using namespace MailCommon;
14
15// if you change this list, also update
16// the count in argsFromString
17static const KMime::MDN::DispositionType mdns[] = {
18 KMime::MDN::Displayed,
19 KMime::MDN::Deleted,
20 KMime::MDN::Dispatched,
21 KMime::MDN::Processed,
22 KMime::MDN::Denied,
23 KMime::MDN::Failed,
24};
25static const int numMDNs = sizeof(mdns) / sizeof(*mdns);
26
27FilterActionSendFakeDisposition::FilterActionSendFakeDisposition(QObject *parent)
28 : FilterActionWithStringList(QStringLiteral("fake mdn"), i18n("Send Fake MDN"), parent)
29{
30 // if you change this list, also update
31 // mdns above
32 mParameterList.append(QString());
33 mParameterList.append(i18nc("MDN type", "Ignore"));
34 mParameterList.append(i18nc("MDN type", "Displayed"));
35 mParameterList.append(i18nc("MDN type", "Deleted"));
36 mParameterList.append(i18nc("MDN type", "Dispatched"));
37 mParameterList.append(i18nc("MDN type", "Processed"));
38 mParameterList.append(i18nc("MDN type", "Denied"));
39 mParameterList.append(i18nc("MDN type", "Failed"));
40
41 mParameter = mParameterList.at(0);
42}
43
44FilterAction *FilterActionSendFakeDisposition::newAction()
45{
46 return new FilterActionSendFakeDisposition;
47}
48
49bool FilterActionSendFakeDisposition::isEmpty() const
50{
51 const int index = mParameterList.indexOf(mParameter);
52 return index < 1;
53}
54
55FilterAction::ReturnCode FilterActionSendFakeDisposition::process(ItemContext &context, bool) const
56{
57 const int index = mParameterList.indexOf(mParameter);
58 if (index < 1) {
59 return ErrorButGoOn;
60 }
61
62 if (index == 1) { // ignore
65 context.setNeedsFlagStore();
66 }
67 } else { // send
68 sendMDN(context.item(), mdns[index - 2]); // skip first two entries: "" and "ignore"
69 }
70
71 return GoOn;
72}
73
74SearchRule::RequiredPart FilterActionSendFakeDisposition::requiredPart() const
75{
77}
78
79void FilterActionSendFakeDisposition::argsFromString(const QString &argsStr)
80{
81 if (argsStr.length() == 1) {
82 if (argsStr[0] == QLatin1Char('I')) { // ignore
83 mParameter = mParameterList.at(1);
84 return;
85 }
86
87 for (int i = 0; i < numMDNs; ++i) {
88 if (char(mdns[i]) == argsStr[0]) { // send
89 mParameter = mParameterList.at(i + 2);
90 return;
91 }
92 }
93 }
94
95 mParameter = mParameterList.at(0);
96}
97
98QString FilterActionSendFakeDisposition::argsAsString() const
99{
100 const int index = mParameterList.indexOf(mParameter);
101 if (index < 1) {
102 return {};
103 }
104
105 return {QChar(index < 2 ? 'I' : char(mdns[index - 2]))};
106}
107
108QString FilterActionSendFakeDisposition::displayString() const
109{
110 return label() + QLatin1StringView(" \"") + mParameter + QLatin1StringView("\"");
111}
112
113QString FilterActionSendFakeDisposition::informationAboutNotValidAction() const
114{
115 return i18n("Fake type undefined.");
116}
117
118#include "moc_filteractionsendfakedisposition.cpp"
bool hasAttribute() const
const T * attribute() const
Abstract base class for filter actions with a fixed set of string parameters.
Abstract base class for mail filter actions.
static void sendMDN(const Akonadi::Item &item, KMime::MDN::DispositionType d, const QList< KMime::MDN::DispositionModifier > &m=QList< KMime::MDN::DispositionModifier >())
Automates the sending of MDNs from filter actions.
ReturnCode
Describes the possible return codes of filter processing:
@ ErrorButGoOn
A non-critical error occurred.
@ GoOn
Go on with applying filter actions.
QString label() const
Returns i18n'd label, ie.
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
@ CompleteMessage
Whole message.
Definition searchrule.h:71
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
The filter dialog.
const_reference at(qsizetype i) const const
qsizetype length() 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.