File indexing completed on 2024-11-10 04:50:02
0001 /* 0002 * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <taferner@kde.org> 0003 * SPDX-FileCopyrightText: 2012 Andras Mantia <amantia@kde.org> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 * 0007 */ 0008 0009 #include "filteraction.h" 0010 0011 #include "../kernel/mailkernel.h" 0012 #include "mailcommon_debug.h" 0013 #include "util/mailutil.h" 0014 #include <MessageComposer/MDNAdviceDialog> 0015 #include <MessageComposer/MDNAdviceHelper> 0016 0017 #include <MessageComposer/MessageFactoryNG> 0018 #include <MessageComposer/MessageSender> 0019 #include <MessageComposer/Util> 0020 #include <MessageViewer/MessageViewerSettings> 0021 0022 #include <KLocalizedString> 0023 0024 using namespace MailCommon; 0025 0026 FilterAction::FilterAction(const QString &name, const QString &label, QObject *parent) 0027 : QObject(parent) 0028 , mName(name) 0029 , mLabel(label) 0030 { 0031 } 0032 0033 FilterAction::~FilterAction() = default; 0034 0035 QString FilterAction::label() const 0036 { 0037 return mLabel; 0038 } 0039 0040 QString FilterAction::name() const 0041 { 0042 return mName; 0043 } 0044 0045 bool FilterAction::isEmpty() const 0046 { 0047 return false; 0048 } 0049 0050 QString FilterAction::informationAboutNotValidAction() const 0051 { 0052 return {}; 0053 } 0054 0055 FilterAction *FilterAction::newAction() 0056 { 0057 return nullptr; 0058 } 0059 0060 QWidget *FilterAction::createParamWidget(QWidget *parent) const 0061 { 0062 auto w = new QWidget(parent); 0063 w->setObjectName(QLatin1StringView("empty_widget")); 0064 return w; 0065 } 0066 0067 void FilterAction::applyParamWidgetValue(QWidget *) 0068 { 0069 } 0070 0071 void FilterAction::setParamWidgetValue(QWidget *) const 0072 { 0073 } 0074 0075 void FilterAction::clearParamWidget(QWidget *) const 0076 { 0077 } 0078 0079 bool FilterAction::argsFromStringInteractive(const QString &argsStr, const QString &filterName) 0080 { 0081 Q_UNUSED(filterName) 0082 argsFromString(argsStr); 0083 return false; 0084 } 0085 0086 QString FilterAction::argsAsStringReal() const 0087 { 0088 return argsAsString(); 0089 } 0090 0091 bool FilterAction::folderRemoved(const Akonadi::Collection &, const Akonadi::Collection &) 0092 { 0093 return false; 0094 } 0095 0096 void FilterAction::sendMDN(const Akonadi::Item &item, KMime::MDN::DispositionType type, const QList<KMime::MDN::DispositionModifier> &modifiers) 0097 { 0098 const KMime::Message::Ptr msg = MessageComposer::Util::message(item); 0099 if (!msg) { 0100 return; 0101 } 0102 0103 const QPair<bool, KMime::MDN::SendingMode> mdnSend = MessageComposer::MDNAdviceHelper::instance()->checkAndSetMDNInfo(item, type, true); 0104 if (mdnSend.first) { 0105 const int quote = MessageViewer::MessageViewerSettings::self()->quoteMessage(); 0106 QString receiptTo; 0107 if (auto hrd = msg->headerByType("Disposition-Notification-To")) { 0108 receiptTo = hrd->asUnicodeString(); 0109 } 0110 if (receiptTo.isEmpty()) { 0111 return; 0112 } 0113 MessageComposer::MessageFactoryNG factory(msg, Akonadi::Item().id()); 0114 factory.setIdentityManager(KernelIf->identityManager()); 0115 factory.setFolderIdentity(MailCommon::Util::folderIdentity(item)); 0116 0117 const KMime::Message::Ptr mdn = factory.createMDN(KMime::MDN::AutomaticAction, type, mdnSend.second, quote, modifiers); 0118 if (mdn) { 0119 if (!KernelIf->msgSender()->send(mdn, MessageComposer::MessageSender::SendLater)) { 0120 qCDebug(MAILCOMMON_LOG) << "Sending failed."; 0121 } 0122 } 0123 } 0124 } 0125 0126 QStringList FilterAction::sieveRequires() const 0127 { 0128 return {}; 0129 } 0130 0131 QString FilterAction::sieveCode() const 0132 { 0133 return i18n("### \"action '%1' not supported\"", name()); 0134 } 0135 0136 #include "moc_filteraction.cpp"