Warning, file /pim/mailcommon/src/collectionpage/collectionexpiryjob.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "collectionexpiryjob.h" 0008 #include "mailcommon_debug.h" 0009 #include "util/mailutil.h" 0010 0011 #include <Akonadi/CollectionModifyJob> 0012 0013 using namespace MailCommon; 0014 0015 CollectionExpiryJob::CollectionExpiryJob(QObject *parent) 0016 : QObject(parent) 0017 { 0018 } 0019 0020 CollectionExpiryJob::~CollectionExpiryJob() = default; 0021 0022 void CollectionExpiryJob::start() 0023 { 0024 if (mCollection.isValid()) { 0025 auto job = new Akonadi::CollectionModifyJob(mCollection, this); 0026 connect(job, &Akonadi::CollectionModifyJob::result, this, &CollectionExpiryJob::slotCollectionModified); 0027 } else { 0028 qCWarning(MAILCOMMON_LOG) << "Collection is not valid"; 0029 deleteLater(); 0030 } 0031 } 0032 0033 void CollectionExpiryJob::setCollection(const Akonadi::Collection &collection) 0034 { 0035 mCollection = collection; 0036 } 0037 0038 void CollectionExpiryJob::setExpireNow(bool expireNow) 0039 { 0040 mExpireNow = expireNow; 0041 } 0042 0043 void CollectionExpiryJob::slotCollectionModified(KJob *job) 0044 { 0045 if (job->error()) { 0046 qCWarning(MAILCOMMON_LOG) << " Error when we modified collection"; 0047 deleteLater(); 0048 return; 0049 } 0050 0051 // trigger immediate expiry if there is something to do 0052 if (mExpireNow) { 0053 auto modifiedJob = qobject_cast<Akonadi::CollectionModifyJob *>(job); 0054 if (modifiedJob) { 0055 MailCommon::Util::expireOldMessages(modifiedJob->collection(), true /*immediate*/); 0056 } else { 0057 qCWarning(MAILCOMMON_LOG) << " invalid pointer"; 0058 } 0059 } 0060 deleteLater(); 0061 } 0062 0063 #include "moc_collectionexpiryjob.cpp"