File indexing completed on 2024-12-22 04:56:51

0001 /*
0002     SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <Akonadi/Item>
0010 #include <KJob>
0011 namespace Akonadi
0012 {
0013 class Item;
0014 class AgentInstance;
0015 }
0016 class QDBusInterface;
0017 /**
0018  * @short A job to send a mail
0019  *
0020  * This class takes a prevalidated Item with all the required attributes,
0021  * sends it using MailTransport, and then stores the result of the sending
0022  * operation in the item.
0023  */
0024 class SendJob : public KJob
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     /**
0030      * Creates a new send job.
0031      *
0032      * @param mItem The item to send.
0033      * @param parent The parent object.
0034      */
0035     explicit SendJob(const Akonadi::Item &mItem, QObject *parent = nullptr);
0036 
0037     /**
0038      * Destroys the send job.
0039      */
0040     ~SendJob() override;
0041 
0042     /**
0043      * Starts the job.
0044      */
0045     void start() override;
0046 
0047     /**
0048      * If this function is called before the job is started, the SendJob will
0049      * just mark the item as aborted, instead of sending it.
0050      * Do not call this function more than once.
0051      */
0052     void setMarkAborted();
0053 
0054     /**
0055      * Aborts sending the item.
0056      *
0057      * This will give the item an ErrorAttribute of "aborted".
0058      * (No need to call setMarkAborted() if you call abort().)
0059      */
0060     void abort();
0061 
0062 private Q_SLOTS:
0063     void transportPercent(KJob *job, unsigned long percent);
0064     void resourceResult(qlonglong itemId, int result, const QString &message);
0065 
0066 private:
0067     void doAkonadiTransport();
0068     void doTraditionalTransport();
0069     void doPostJob(bool transportSuccess, const QString &transportMessage);
0070     void storeResult(bool success, const QString &message = QString());
0071     void abortPostJob();
0072     [[nodiscard]] bool filterItem(int filterset);
0073 
0074     // slots
0075     void doTransport();
0076     void transportResult(KJob *job);
0077     void resourceProgress(const Akonadi::AgentInstance &instance);
0078     void postJobResult(KJob *job);
0079     void doEmitResult(KJob *job);
0080     void slotSentMailCollectionFetched(KJob *job);
0081 
0082     Akonadi::Item mItem;
0083     QString mResourceId;
0084     KJob *mCurrentJob = nullptr;
0085     QDBusInterface *mInterface = nullptr;
0086     bool mAborting = false;
0087 };