1 /*
2     SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
3 
4     Based on KMail code by:
5     SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <taferner@kde.org>
6 
7     SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #pragma once
11 
12 #include <KSMTP/Session>
13 #include <transportjob.h>
14 
15 #include <memory>
16 
17 namespace KIO
18 {
19 class Job;
20 class Slave;
21 }
22 
23 namespace KGAPI2
24 {
25 class AccountPromise;
26 }
27 
28 class SmtpJobPrivate;
29 
30 namespace MailTransport
31 {
32 /**
33   Mail transport job for SMTP.
34   Internally, all jobs for a specific transport are queued to use the same
35   KIO::Slave. This avoids multiple simultaneous connections to the server,
36   which is not always allowed. Also, re-using an already existing connection
37   avoids the login overhead and can improve performance.
38 
39   Precommands are automatically executed, once per opening a connection to the
40   server (not necessarily once per message).
41 */
42 class SmtpJob : public TransportJob
43 {
44     Q_OBJECT
45 public:
46     /**
47       Creates a SmtpJob.
48       @param transport The transport settings.
49       @param parent The parent object.
50     */
51     explicit SmtpJob(Transport *transport, QObject *parent = nullptr);
52 
53     /**
54       Deletes this job.
55     */
56     ~SmtpJob() override;
57 
58 protected:
59     void doStart() override;
60     bool doKill() override;
61 
62 protected Q_SLOTS:
63     void slotResult(KJob *job) override;
64     void sessionStateChanged(KSmtp::Session::State state);
65 
66 private:
67     void startPasswordRetrieval(bool forceRefresh = false);
68     void onTokenRequestFinished(KGAPI2::AccountPromise *result);
69     void startSmtpJob();
70     void startLoginJob();
71     void startSendJob();
72 
73 private:
74     friend class ::SmtpJobPrivate;
75     std::unique_ptr<SmtpJobPrivate> const d;
76 };
77 } // namespace MailTransport
78 
79