File indexing completed on 2024-11-10 04:50:03
0001 /* 0002 * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <taferner@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 * 0006 */ 0007 0008 #include "filteractioncopy.h" 0009 0010 #include "kernel/mailkernel.h" 0011 #include "util/mailutil.h" 0012 0013 #include <Akonadi/ItemCopyJob> 0014 #include <KLocalizedString> 0015 0016 using namespace MailCommon; 0017 0018 FilterActionCopy::FilterActionCopy(QObject *parent) 0019 : FilterActionWithFolder(QStringLiteral("copy"), i18n("Copy Into Folder"), parent) 0020 { 0021 } 0022 0023 FilterAction::ReturnCode FilterActionCopy::process(ItemContext &context, bool) const 0024 { 0025 // copy the message 1:1 0026 auto job = new Akonadi::ItemCopyJob(context.item(), mFolder, nullptr); 0027 connect(job, &Akonadi::ItemCopyJob::result, this, &FilterActionCopy::jobFinished); 0028 0029 return GoOn; 0030 } 0031 0032 void FilterActionCopy::jobFinished(KJob *job) 0033 { 0034 if (job->error()) { 0035 qCritical() << "Error while moving mail: " << job->errorString(); 0036 } 0037 } 0038 0039 SearchRule::RequiredPart FilterActionCopy::requiredPart() const 0040 { 0041 return SearchRule::Envelope; 0042 } 0043 0044 FilterAction *FilterActionCopy::newAction() 0045 { 0046 return new FilterActionCopy; 0047 } 0048 0049 QString FilterActionCopy::sieveCode() const 0050 { 0051 QString path; 0052 if (KernelIf->collectionModel()) { 0053 path = MailCommon::Util::fullCollectionRemoveIdPath(mFolder); 0054 } else { 0055 path = QString::number(mFolder.id()); 0056 } 0057 const QString result = QStringLiteral("fileinto :copy \"%1\";").arg(path); 0058 return result; 0059 } 0060 0061 QStringList FilterActionCopy::sieveRequires() const 0062 { 0063 return QStringList() << QStringLiteral("fileinto") << QStringLiteral("copy"); 0064 } 0065 0066 QString FilterActionCopy::informationAboutNotValidAction() const 0067 { 0068 return i18n("Folder destination was not defined."); 0069 } 0070 0071 #include "moc_filteractioncopy.cpp"