File indexing completed on 2024-06-23 05:15:11

0001 /*
0002   SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
0003 
0004   SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "mailtransport_export.h"
0010 
0011 #include <QStringList>
0012 
0013 #include <KCompositeJob>
0014 
0015 #include <memory>
0016 
0017 class QBuffer;
0018 
0019 namespace MailTransport
0020 {
0021 class Transport;
0022 class TransportJobPrivate;
0023 
0024 /**
0025   Abstract base class for all mail transport jobs.
0026   This is a job that is supposed to send exactly one mail.
0027 
0028   @deprecated Use MessageQueueJob for sending e-mail.
0029 */
0030 class MAILTRANSPORT_DEPRECATED_EXPORT TransportJob : public KCompositeJob
0031 {
0032     Q_OBJECT
0033     friend class TransportManager;
0034 
0035 public:
0036     /**
0037       Deletes this transport job.
0038     */
0039     ~TransportJob() override;
0040 
0041     /**
0042       Sets the sender of the mail.
0043       @p sender must be the plain email address, not including display name.
0044     */
0045     void setSender(const QString &sender);
0046 
0047     /**
0048       Sets the "To" receiver(s) of the mail.
0049       @p to must be the plain email address(es), not including display name.
0050     */
0051     void setTo(const QStringList &to);
0052 
0053     /**
0054       Sets the "Cc" receiver(s) of the mail.
0055       @p cc must be the plain email address(es), not including display name.
0056     */
0057     void setCc(const QStringList &cc);
0058 
0059     /**
0060       Sets the "Bcc" receiver(s) of the mail.
0061       @p bcc must be the plain email address(es), not including display name.
0062     */
0063     void setBcc(const QStringList &bcc);
0064 
0065     /**
0066       Sets the content of the mail.
0067     */
0068     void setData(const QByteArray &data);
0069 
0070     /**
0071       Starts this job. It is recommended to not call this method directly but use
0072       TransportManager::schedule() to execute the job instead.
0073 
0074       @see TransportManager::schedule()
0075     */
0076     void start() override;
0077 
0078     /**
0079       Returns the Transport object containing the mail transport settings.
0080     */
0081     Transport *transport() const;
0082 
0083     /**
0084        Sets the content of the mail.
0085     */
0086     void setDeliveryStatusNotification(bool enabled);
0087 
0088 protected:
0089     /**
0090       Creates a new mail transport job.
0091       @param transport The transport configuration. This must be a deep copy of
0092       a Transport object, the job takes the ownership of this object.
0093       @param parent The parent object.
0094       @see TransportManager::createTransportJob()
0095     */
0096     explicit TransportJob(Transport *transport, QObject *parent = nullptr);
0097 
0098     /**
0099       Returns the sender of the mail.
0100     */
0101     [[nodiscard]] QString sender() const;
0102 
0103     /**
0104       Returns the "To" receiver(s) of the mail.
0105     */
0106     [[nodiscard]] QStringList to() const;
0107 
0108     /**
0109       Returns the "Cc" receiver(s) of the mail.
0110     */
0111     [[nodiscard]] QStringList cc() const;
0112 
0113     /**
0114       Returns the "Bcc" receiver(s) of the mail.
0115     */
0116     [[nodiscard]] QStringList bcc() const;
0117 
0118     /**
0119       Returns the data of the mail.
0120     */
0121     [[nodiscard]] QByteArray data() const;
0122 
0123     /**
0124       Returns a QBuffer opened on the message data. This is useful for
0125       processing the data in smaller chunks.
0126     */
0127     QBuffer *buffer();
0128 
0129     /**
0130       Do the actual work, implement in your subclass.
0131     */
0132     virtual void doStart() = 0;
0133 
0134     /**
0135       Returns true if DSN is enabled.
0136     */
0137     [[nodiscard]] bool deliveryStatusNotification() const;
0138 
0139 private:
0140     //@cond PRIVATE
0141     std::unique_ptr<TransportJobPrivate> const d;
0142     //@endcond
0143 };
0144 } // namespace MailTransport