Mailcommon

filteractioncopy.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 "filteractioncopy.h"
9 
10 #include "kernel/mailkernel.h"
11 #include "util/mailutil.h"
12 
13 #include <Akonadi/ItemCopyJob>
14 #include <KLocalizedString>
15 
16 using namespace MailCommon;
17 
18 FilterActionCopy::FilterActionCopy(QObject *parent)
19  : FilterActionWithFolder(QStringLiteral("copy"), i18n("Copy Into Folder"), parent)
20 {
21 }
22 
23 FilterAction::ReturnCode FilterActionCopy::process(ItemContext &context, bool) const
24 {
25  // copy the message 1:1
26  auto job = new Akonadi::ItemCopyJob(context.item(), mFolder, nullptr);
27  connect(job, &Akonadi::ItemCopyJob::result, this, &FilterActionCopy::jobFinished);
28 
29  return GoOn;
30 }
31 
32 void FilterActionCopy::jobFinished(KJob *job)
33 {
34  if (job->error()) {
35  qCritical() << "Error while moving mail: " << job->errorString();
36  }
37 }
38 
39 SearchRule::RequiredPart FilterActionCopy::requiredPart() const
40 {
41  return SearchRule::Envelope;
42 }
43 
44 FilterAction *FilterActionCopy::newAction()
45 {
46  return new FilterActionCopy;
47 }
48 
49 QString FilterActionCopy::sieveCode() const
50 {
51  QString path;
52  if (KernelIf->collectionModel()) {
53  path = MailCommon::Util::fullCollectionPath(mFolder);
54  } else {
55  path = QString::number(mFolder.id());
56  }
57  const QString result = QStringLiteral("fileinto :copy \"%1\";").arg(path);
58  return result;
59 }
60 
61 QStringList FilterActionCopy::sieveRequires() const
62 {
63  return QStringList() << QStringLiteral("fileinto") << QStringLiteral("copy");
64 }
65 
66 QString FilterActionCopy::informationAboutNotValidAction() const
67 {
68  return i18n("Folder destination was not defined.");
69 }
Abstract base class for filter actions with a mail folder as parameter.
QString number(int n, int base)
void result(KJob *job)
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
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
virtual QString errorString() const
int error() const
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.