Akonadi Mime

messagequeuejob.h
1/*
2 SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "akonadi-mime_export.h"
10
11#include <Akonadi/DispatchModeAttribute>
12#include <Akonadi/SentActionAttribute>
13#include <Akonadi/SentBehaviourAttribute>
14#include <Akonadi/TransportAttribute>
15
16#include <QString>
17#include <QStringList>
18
19#include <KCompositeJob>
20
21#include <Akonadi/AddressAttribute>
22#include <Akonadi/Collection>
23
24#include <KMime/Message>
25
26#include <memory>
27
28namespace Akonadi
29{
30class MessageQueueJobPrivate;
31
32/**
33 @short Provides an interface for sending email.
34
35 This class takes a KMime::Message and some related info such as sender and
36 recipient addresses, and places the message in the outbox. The mail
37 dispatcher agent will then take it from there and send it.
38
39 This is the preferred way for applications to send email.
40
41 This job requires some options to be set before being started. Modify the
42 attributes of this job to change these options.
43
44 You need to set the transport of the transport attribute, the from address of
45 the address attribute and one of the to, cc or bcc addresses of the address
46 attribute. Also, you need to call setMessage().
47 Optionally, you can change the dispatch mode attribute or the sent behaviour
48 attribute.
49
50 Example:
51 @code
52
53 MessageQueueJob *job = new MessageQueueJob( this );
54 job->setMessage( msg ); // msg is a Message::Ptr
55 job->transportAttribute().setTransportId( TransportManager::self()->defaultTransportId() );
56 // Use the default dispatch mode.
57 // Use the default sent-behaviour.
58 job->addressAttribute().setFrom( from ); // from is a QString
59 job->addressAttribute().setTo( to ); // to is a QStringList
60 connect( job, SIGNAL(result(KJob*)), this, SLOT(jobResult(KJob*)) );
61 job->start();
62
63 @endcode
64
65 @see DispatchModeAttribute
66 @see SentActionAttribute
67 @see SentBehaviourAttribute
68 @see TransportAttribute
69 @see AddressAttribute
70
71 @author Constantin Berzan <exit3219@gmail.com>
72 @since 4.4
73*/
74class AKONADI_MIME_EXPORT MessageQueueJob : public KCompositeJob
75{
76 Q_OBJECT
77
78public:
79 /**
80 Creates a new MessageQueueJob.
81 @param parent the QObject parent
82 This is not an autostarting job; you need to call start() yourself.
83 */
84 explicit MessageQueueJob(QObject *parent = nullptr);
85
86 /**
87 Destroys the MessageQueueJob.
88 This job deletes itself after finishing.
89 */
90 ~MessageQueueJob() override;
91
92 /**
93 Returns the message to be sent.
94 */
95 [[nodiscard]] KMime::Message::Ptr message() const;
96
97 /**
98 Returns a reference to the dispatch mode attribute for this message.
99 Modify the returned attribute to change the dispatch mode.
100 */
101 DispatchModeAttribute &dispatchModeAttribute();
102
103 /**
104 Returns a reference to the address attribute for this message.
105 Modify the returned attribute to change the receivers or the from
106 address.
107 */
108 Akonadi::AddressAttribute &addressAttribute();
109
110 /**
111 Returns a reference to the transport attribute for this message.
112 Modify the returned attribute to change the transport used for
113 sending the mail.
114 */
115 TransportAttribute &transportAttribute();
116
117 /**
118 Returns a reference to the sent behaviour attribute for this message.
119 Modify the returned attribute to change the sent behaviour.
120 */
121 SentBehaviourAttribute &sentBehaviourAttribute();
122
123 /**
124 Returns a reference to the sent action attribute for this message.
125 Modify the returned attribute to change the sent actions.
126 */
127 SentActionAttribute &sentActionAttribute();
128
129 /**
130 Sets the message to be sent.
131 */
132 void setMessage(const KMime::Message::Ptr &message);
133
134 /**
135 Creates the item and places it in the outbox.
136 It is now queued for sending by the mail dispatcher agent.
137 */
138 void start() override;
139
140protected Q_SLOTS:
141 /**
142 Called when the ItemCreateJob subjob finishes.
143
144 (reimplemented from KCompositeJob)
145 */
146 void slotResult(KJob *) override;
147
148private:
149 friend class MessageQueueJobPrivate;
150 std::unique_ptr<MessageQueueJobPrivate> const d;
151};
152} // namespace MailTransport
Attribute storing the From, To, Cc, Bcc addresses of a message.
Attribute determining how and when a message from the outbox should be dispatched.
Provides an interface for sending email.
~MessageQueueJob() override
Destroys the MessageQueueJob.
An Attribute that stores the action to execute after sending.
Attribute determining what will happen to a message after it is sent.
Attribute determining which transport to use for sending a message.
Q_SCRIPTABLE Q_NOREPLY void start()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:28 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.