Mailcommon

filteraction.cpp
1 /*
2  * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <[email protected]>
3  * SPDX-FileCopyrightText: 2012 Andras Mantia <[email protected]>
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  *
7  */
8 
9 #include "filteraction.h"
10 
11 #include "../kernel/mailkernel.h"
12 #include "mailcommon_debug.h"
13 #include "util/mailutil.h"
14 #include <MessageComposer/MDNAdviceDialog>
15 #include <MessageComposer/MDNAdviceHelper>
16 
17 #include <MessageComposer/MessageFactoryNG>
18 #include <MessageComposer/MessageSender>
19 #include <MessageComposer/Util>
20 #include <MessageViewer/MessageViewerSettings>
21 
22 #include <KLocalizedString>
23 
24 using namespace MailCommon;
25 
26 FilterAction::FilterAction(const QString &name, const QString &label, QObject *parent)
27  : QObject(parent)
28  , mName(name)
29  , mLabel(label)
30 {
31 }
32 
33 FilterAction::~FilterAction() = default;
34 
36 {
37  return mLabel;
38 }
39 
41 {
42  return mName;
43 }
44 
46 {
47  return false;
48 }
49 
50 QString FilterAction::informationAboutNotValidAction() const
51 {
52  return {};
53 }
54 
56 {
57  return nullptr;
58 }
59 
61 {
62  auto w = new QWidget(parent);
63  w->setObjectName(QStringLiteral("empty_widget"));
64  return w;
65 }
66 
68 {
69 }
70 
72 {
73 }
74 
76 {
77 }
78 
79 bool FilterAction::argsFromStringInteractive(const QString &argsStr, const QString &filterName)
80 {
81  Q_UNUSED(filterName)
82  argsFromString(argsStr);
83  return false;
84 }
85 
86 QString FilterAction::argsAsStringReal() const
87 {
88  return argsAsString();
89 }
90 
92 {
93  return false;
94 }
95 
96 void FilterAction::sendMDN(const Akonadi::Item &item, KMime::MDN::DispositionType type, const QVector<KMime::MDN::DispositionModifier> &modifiers)
97 {
99  if (!msg) {
100  return;
101  }
102 
103  const QPair<bool, KMime::MDN::SendingMode> mdnSend = MessageComposer::MDNAdviceHelper::instance()->checkAndSetMDNInfo(item, type, true);
104  if (mdnSend.first) {
105  const int quote = MessageViewer::MessageViewerSettings::self()->quoteMessage();
106  QString receiptTo;
107  if (auto hrd = msg->headerByType("Disposition-Notification-To")) {
108  receiptTo = hrd->asUnicodeString();
109  }
110  if (receiptTo.isEmpty()) {
111  return;
112  }
114  factory.setIdentityManager(KernelIf->identityManager());
116 
117  const KMime::Message::Ptr mdn = factory.createMDN(KMime::MDN::AutomaticAction, type, mdnSend.second, quote, modifiers);
118  if (mdn) {
119  if (!KernelIf->msgSender()->send(mdn, MessageComposer::MessageSender::SendLater)) {
120  qCDebug(MAILCOMMON_LOG) << "Sending failed.";
121  }
122  }
123  }
124 }
125 
126 QStringList FilterAction::sieveRequires() const
127 {
128  return {};
129 }
130 
131 QString FilterAction::sieveCode() const
132 {
133  return i18n("### \"action '%1' not supported\"", name());
134 }
virtual void setParamWidgetValue(QWidget *paramWidget) const
The filter action shall set it's widget's contents from it's parameter.
void setFolderIdentity(uint folderIdentityId)
MAILCOMMON_EXPORT uint folderIdentity(const Akonadi::Item &item)
Returns the identity of the folder that contains the given Akonadi::Item.
Definition: mailutil.cpp:149
~FilterAction() override
Destroys the filter action.
QString name() const
Returns identifier name, ie.
Abstract base class for mail filter actions.
Definition: filteraction.h:38
QString i18n(const char *text, const TYPE &arg...)
virtual bool folderRemoved(const Akonadi::Collection &aFolder, const Akonadi::Collection &aNewFolder)
Called from the filter when a folder is removed.
virtual void clearParamWidget(QWidget *paramWidget) const
The filter action shall clear it's parameter widget's contents.
QString label() const
Returns i18n'd label, ie.
static FilterAction * newAction()
Static function that creates a filter action of this type.
bool isEmpty() const const
virtual void applyParamWidgetValue(QWidget *paramWidget)
The filter action shall set it's parameter from the widget's contents.
void setIdentityManager(KIdentityManagement::IdentityManager *ident)
virtual bool argsFromStringInteractive(const QString &argsStr, const QString &filterName)
Read extra arguments from given string.
virtual QWidget * createParamWidget(QWidget *parent) const
Creates a widget for setting the filter action parameter.
FilterAction(const QString &name, const QString &label, QObject *parent=nullptr)
Creates a new filter action.
KMime::Message::Ptr createMDN(KMime::MDN::ActionMode a, KMime::MDN::DispositionType d, KMime::MDN::SendingMode s, int mdnQuoteOriginal=0, const QVector< KMime::MDN::DispositionModifier > &m=QVector< KMime::MDN::DispositionModifier >())
virtual void argsFromString(const QString &argsStr)=0
Read extra arguments from given string.
static void sendMDN(const Akonadi::Item &item, KMime::MDN::DispositionType d, const QVector< KMime::MDN::DispositionModifier > &m=QVector< KMime::MDN::DispositionModifier >())
Automates the sending of MDNs from filter actions.
QObject * parent() const const
QString message
The filter dialog.
virtual QString argsAsString() const =0
Return extra arguments as string.
virtual bool isEmpty() const
Determines whether this action is valid.
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.