Mailcommon

filteractionredirect.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 "filteractionredirect.h"
9 #include "kernel/mailkernel.h"
10 #include "mailcommon_debug.h"
11 #include "util/mailutil.h"
12 
13 #include <MessageComposer/MessageFactoryNG>
14 #include <MessageComposer/MessageSender>
15 #include <MessageComposer/Util>
16 
17 #include <KLocalizedString>
18 
19 using namespace MailCommon;
20 
21 FilterAction *FilterActionRedirect::newAction()
22 {
23  return new FilterActionRedirect;
24 }
25 
26 FilterActionRedirect::FilterActionRedirect(QObject *parent)
27  : FilterActionWithAddress(QStringLiteral("redirect"), i18n("Redirect To"), parent)
28 {
29 }
30 
31 FilterAction::ReturnCode FilterActionRedirect::process(ItemContext &context, bool) const
32 {
33  if (isEmpty()) {
34  return ErrorButGoOn;
35  }
36 
38 
39  MessageComposer::MessageFactoryNG factory(msg, context.item().id());
40  factory.setFolderIdentity(Util::folderIdentity(context.item()));
41  factory.setIdentityManager(KernelIf->identityManager());
42 
43  KMime::Message::Ptr rmsg = factory.createRedirect(mParameter);
44  if (!rmsg) {
45  return ErrorButGoOn;
46  }
47 
48  sendMDN(context.item(), KMime::MDN::Dispatched);
49 
50  if (!KernelIf->msgSender()->send(rmsg, MessageComposer::MessageSender::SendLater)) {
51  qCDebug(MAILCOMMON_LOG) << "FilterAction: could not redirect message (sending failed)";
52  return ErrorButGoOn; // error: couldn't send
53  }
54 
55  return GoOn;
56 }
57 
58 SearchRule::RequiredPart FilterActionRedirect::requiredPart() const
59 {
61 }
62 
63 QString FilterActionRedirect::sieveCode() const
64 {
65  const QString result = QStringLiteral("redirect \"%1\";").arg(mParameter);
66  return result;
67 }
68 
69 QString FilterActionRedirect::informationAboutNotValidAction() const
70 {
71  return i18n("Email address was missing.");
72 }
Abstract base class for filter actions with a mail address as parameter.
MAILCOMMON_EXPORT uint folderIdentity(const Akonadi::Item &item)
Returns the identity of the folder that contains the given Akonadi::Item.
Definition: mailutil.cpp:148
Abstract base class for mail filter actions.
Definition: filteraction.h:38
QString i18n(const char *text, const TYPE &arg...)
RequiredPart
Possible required parts.
Definition: searchrule.h:68
A helper class for the filtering process.
Definition: itemcontext.h:26
ReturnCode
Describes the possible return codes of filter processing:
Definition: filteraction.h:45
Id id() const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
@ CompleteMessage
Whole message.
Definition: searchrule.h:71
Akonadi::Item & item()
Returns the item of the context.
Definition: itemcontext.cpp:18
QString message
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.