Mailcommon

filteractionsendfakedisposition.cpp
1 /*
2  * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <[email protected]>
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 
13 using namespace MailCommon;
14 
15 // if you change this list, also update
16 // the count in argsFromString
17 static 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 };
25 static const int numMDNs = sizeof(mdns) / sizeof(*mdns);
26 
27 FilterActionSendFakeDisposition::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 
44 FilterAction *FilterActionSendFakeDisposition::newAction()
45 {
46  return new FilterActionSendFakeDisposition;
47 }
48 
49 bool FilterActionSendFakeDisposition::isEmpty() const
50 {
51  const int index = mParameterList.indexOf(mParameter);
52  return index < 1;
53 }
54 
55 FilterAction::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
63  if (context.item().hasAttribute<Akonadi::MDNStateAttribute>()) {
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 
74 SearchRule::RequiredPart FilterActionSendFakeDisposition::requiredPart() const
75 {
77 }
78 
79 void 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 
98 QString 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 
108 QString FilterActionSendFakeDisposition::displayString() const
109 {
110  return label() + QLatin1String(" \"") + mParameter + QLatin1String("\"");
111 }
112 
113 QString FilterActionSendFakeDisposition::informationAboutNotValidAction() const
114 {
115  return i18n("Fake type undefined.");
116 }
const T * attribute() const
Abstract base class for filter actions with a fixed set of string parameters.
bool hasAttribute() const
Abstract base class for mail filter actions.
Definition: filteraction.h:38
QString i18n(const char *text, const TYPE &arg...)
void setNeedsFlagStore()
Marks that the item's flags has been changed and needs to be written back.
Definition: itemcontext.cpp:43
RequiredPart
Possible required parts.
Definition: searchrule.h:68
int length() const const
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
A helper class for the filtering process.
Definition: itemcontext.h:26
QString label(StandardShortcut id)
ReturnCode
Describes the possible return codes of filter processing:
Definition: filteraction.h:45
@ CompleteMessage
Whole message.
Definition: searchrule.h:71
QString i18nc(const char *context, const char *text, const TYPE &arg...)
Akonadi::Item & item()
Returns the item of the context.
Definition: itemcontext.cpp:18
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Sep 24 2022 03:58:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.