Mailcommon

filteractionsetstatus.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 "filteractionsetstatus.h"
9 #include "mailcommon_debug.h"
10 #include <Akonadi/MessageStatus>
11 #include <KLocalizedString>
12 using namespace MailCommon;
13 
14 FilterAction *FilterActionSetStatus::newAction()
15 {
16  return new FilterActionSetStatus;
17 }
18 
19 FilterActionSetStatus::FilterActionSetStatus(QObject *parent)
20  : FilterActionStatus(QStringLiteral("set status"), i18n("Mark As"), parent)
21 {
22 }
23 
24 bool FilterActionSetStatus::isEmpty() const
25 {
26  const int index = mParameterList.indexOf(mParameter);
27  return index < 1;
28 }
29 
30 QString FilterActionSetStatus::informationAboutNotValidAction() const
31 {
32  return i18n("Status not specified.");
33 }
34 
35 FilterAction::ReturnCode FilterActionSetStatus::process(ItemContext &context, bool) const
36 {
37  const int index = mParameterList.indexOf(mParameter);
38  if (index < 1) {
39  return ErrorButGoOn;
40  }
41 
43  status.setStatusFromFlags(context.item().flags());
44 
45  Akonadi::MessageStatus oldStatus = status;
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 
60 SearchRule::RequiredPart FilterActionSetStatus::requiredPart() const
61 {
62  return SearchRule::Envelope;
63 }
64 
65 QString 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 
84 QStringList FilterActionSetStatus::sieveRequires() const
85 {
86  return QStringList() << QStringLiteral("imap4flags");
87 }
Flags flags() const
static const MessageStatus statusUnread()
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
NETWORKMANAGERQT_EXPORT NetworkManager::Status status()
A helper class for the filtering process.
Definition: itemcontext.h:26
ReturnCode
Describes the possible return codes of filter processing:
Definition: filteraction.h:45
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
void setFlags(const Flags &flags)
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 Oct 1 2022 04:00:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.