Mailcommon

filteraction.cpp
1/*
2 * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <taferner@kde.org>
3 * SPDX-FileCopyrightText: 2012 Andras Mantia <amantia@kde.org>
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
24using namespace MailCommon;
25
26FilterAction::FilterAction(const QString &name, const QString &label, QObject *parent)
27 : QObject(parent)
28 , mName(name)
29 , mLabel(label)
30{
31}
32
34
36{
37 return mLabel;
38}
39
41{
42 return mName;
43}
44
46{
47 return false;
48}
49
50QString FilterAction::informationAboutNotValidAction() const
51{
52 return {};
53}
54
56{
57 return nullptr;
58}
59
61{
62 auto w = new QWidget(parent);
63 w->setObjectName(QLatin1StringView("empty_widget"));
64 return w;
65}
66
70
74
78
79bool FilterAction::argsFromStringInteractive(const QString &argsStr, const QString &filterName)
80{
81 Q_UNUSED(filterName)
82 argsFromString(argsStr);
83 return false;
84}
85
86QString FilterAction::argsAsStringReal() const
87{
88 return argsAsString();
89}
90
92{
93 return false;
94}
95
96void FilterAction::sendMDN(const Akonadi::Item &item, KMime::MDN::DispositionType type, const QList<KMime::MDN::DispositionModifier> &modifiers)
97{
98 const KMime::Message::Ptr msg = MessageComposer::Util::message(item);
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
126QStringList FilterAction::sieveRequires() const
127{
128 return {};
129}
130
131QString FilterAction::sieveCode() const
132{
133 return i18n("### \"action '%1' not supported\"", name());
134}
135
136#include "moc_filteraction.cpp"
Abstract base class for mail filter actions.
virtual void clearParamWidget(QWidget *paramWidget) const
The filter action shall clear it's parameter widget's contents.
virtual void argsFromString(const QString &argsStr)=0
Read extra arguments from given string.
~FilterAction() override
Destroys the filter action.
FilterAction(const QString &name, const QString &label, QObject *parent=nullptr)
Creates a new filter action.
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.
QString name() const
Returns identifier name, ie.
virtual QWidget * createParamWidget(QWidget *parent) const
Creates a widget for setting the filter action parameter.
virtual QString argsAsString() const =0
Return extra arguments as string.
static FilterAction * newAction()
Static function that creates a filter action of this type.
virtual void applyParamWidgetValue(QWidget *paramWidget)
The filter action shall set it's parameter from the widget's contents.
QString label() const
Returns i18n'd label, ie.
virtual void setParamWidgetValue(QWidget *paramWidget) const
The filter action shall set it's widget's contents from it's parameter.
virtual bool isEmpty() const
Determines whether this action is valid.
virtual bool argsFromStringInteractive(const QString &argsStr, const QString &filterName)
Read extra arguments from given string.
virtual bool folderRemoved(const Akonadi::Collection &aFolder, const Akonadi::Collection &aNewFolder)
Called from the filter when a folder is removed.
void setIdentityManager(KIdentityManagementCore::IdentityManager *ident)
void setFolderIdentity(uint folderIdentityId)
KMime::Message::Ptr createMDN(KMime::MDN::ActionMode a, KMime::MDN::DispositionType d, KMime::MDN::SendingMode s, int mdnQuoteOriginal=0, const QList< KMime::MDN::DispositionModifier > &m=QList< KMime::MDN::DispositionModifier >())
QString i18n(const char *text, const TYPE &arg...)
MAILCOMMON_EXPORT uint folderIdentity(const Akonadi::Item &item)
Returns the identity of the folder that contains the given Akonadi::Item.
Definition mailutil.cpp:176
The filter dialog.
QObject * parent() const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:53:25 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.