Messagelib

messagefactoryng.h
1/*
2 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
3 SPDX-FileCopyrightText: 2010 Leo Franchi <lfranchi@kde.org>
4 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
5
6 SPDX-License-Identifier: GPL-2.0-or-later
7*/
8
9#pragma once
10
11#include "messagecomposer_export.h"
12#include <KMime/KMimeMessage>
13#include <KMime/MDN>
14
15#include <Akonadi/Collection>
16#include <Akonadi/Item>
17#include <Akonadi/MessageStatus>
18#include <QList>
19
20namespace KIdentityManagementCore
21{
22class IdentityManager;
23}
24
25namespace MessageComposer
26{
27/**
28 * Enumeration that defines the available reply "modes"
29 */
31 ReplySmart = 0, //< Attempt to automatically guess the best recipient for the reply
32 ReplyAuthor, //< Reply to the author of the message (possibly NOT the mailing list, if any)
33 ReplyList, //< Reply to the mailing list (and not the author of the message)
34 ReplyAll, //< Reply to author and all the recipients in CC
35 ReplyNone, //< Don't set reply addresses: they will be set manually
36};
37
38enum MDNAdvice {
39 MDNIgnore,
40 MDNSendDenied,
41 MDNSend,
42};
43/**
44 * Contains various factory methods for creating new messages such as replies, MDNs, forwards, etc.
45 */
46class MESSAGECOMPOSER_EXPORT MessageFactoryNG : public QObject
47{
48 Q_OBJECT
49public:
50 /// Small helper structure which encapsulates the KMime::Message created when creating a reply, and
51 /// the reply mode
52 struct MessageReply {
53 KMime::Message::Ptr msg = nullptr; ///< The actual reply message
54 bool replyAll = false; ///< If true, the "reply all" template was used, otherwise the normal reply
55 /// template
56 };
57
58 explicit MessageFactoryNG(const KMime::Message::Ptr &origMsg,
61 QObject *parent = nullptr);
62 ~MessageFactoryNG() override;
63
64 /**
65 * Create a new message that is a reply to this message, filling all
66 * required header fields with the proper values. The returned message
67 * is not stored in any folder. Marks this message as replied.
68 *
69 */
70 void createReplyAsync();
71
72 /** Create a new message that is a forward of this message, filling all
73 required header fields with the proper values. The returned message
74 is not stored in any folder. Marks this message as forwarded. */
75 void createForwardAsync();
76
77 /**
78 * Create a forward from the given list of messages, attaching each
79 * message to be forwarded to the new forwarded message.
80 *
81 * If no list is passed, use the original message passed in the MessageFactoryNG
82 * constructor.
83 */
84 [[nodiscard]] QPair<KMime::Message::Ptr, QList<KMime::Content *>> createAttachedForward(const Akonadi::Item::List &items = Akonadi::Item::List());
85
86 /** Create a new message that is a redirect to this message, filling all
87 required header fields with the proper values. The returned message
88 is not stored in any folder. Marks this message as replied.
89 Redirects differ from forwards so they are forwarded to some other
90 user, mail is not changed and the reply-to field is set to
91 the email address of the original sender.
92 */
93 [[nodiscard]] KMime::Message::Ptr createRedirect(const QString &toStr,
94 const QString &ccStr = QString(),
95 const QString &bccStr = QString(),
96 int transportId = -1,
97 const QString &fcc = QString(),
98 int identity = -1);
99
100 [[nodiscard]] KMime::Message::Ptr createResend();
101
102 /** Create a new message that is a delivery receipt of this message,
103 filling required header fields with the proper values. The
104 returned message is not stored in any folder. */
105 [[nodiscard]] KMime::Message::Ptr createDeliveryReceipt();
106
107 /** Create a new message that is a MDN for this message, filling all
108 required fields with proper values. The returned message is not
109 stored in any folder.
110
111 @param a Use AutomaticAction for filtering and ManualAction for
112 user-induced events.
113 @param d See docs for KMime::MDN::DispositionType
114 @param s See docs for KMime::MDN::SendingMode (in KMail, use MDNAdvideDialog to ask the user for this parameter)
115 @param m See docs for KMime::MDN::DispositionModifier
116
117 @return The notification message or 0, if none should be sent, as well as the state of the MDN operation.
118 **/
119 [[nodiscard]] KMime::Message::Ptr createMDN(KMime::MDN::ActionMode a,
120 KMime::MDN::DispositionType d,
121 KMime::MDN::SendingMode s,
122 int mdnQuoteOriginal = 0,
124
125 /**
126 * Create a new forwarded MIME digest. If the user is trying to forward multiple messages
127 * at once all inline, they can choose to have them be compiled into a single digest
128 * message.
129 *
130 * This will return a header message and individual message parts to be set as
131 * attachments.
132 *
133 * @param msgs List of messages to be composed into a digest
134 */
135 [[nodiscard]] QPair<KMime::Message::Ptr, KMime::Content *> createForwardDigestMIME(const Akonadi::Item::List &items);
136
137 /**
138 * Set the identity manager to be used when creating messages.
139 * Required to be set before create* is called, otherwise the created messages
140 * might have the wrong identity data.
141 */
142 void setIdentityManager(KIdentityManagementCore::IdentityManager *ident);
143
144 /**
145 * Set the reply strategy to use. Default is ReplySmart.
146 */
147 void setReplyStrategy(MessageComposer::ReplyStrategy replyStrategy);
148
149 /**
150 * Set the selection to be used to base the reply on.
151 */
152 void setSelection(const QString &selection);
153
154 /**
155 * Whether to quote the original message in the reply.
156 * Default is to quote.
157 */
158 void setQuote(bool quote);
159
160 /**
161 * Set the template to be used when creating the reply. Default is to not
162 * use any template at all.
163 */
164 void setTemplate(const QString &templ);
165
166 /**
167 * Set extra mailinglist addresses to send the created message to.
168 * Any mailing-list addresses specified in the original message
169 * itself will be added by MessageFactoryNG, so no need to add those manually.
170 */
171 void setMailingListAddresses(const KMime::Types::Mailbox::List &listAddresses);
172
173 /**
174 * Set the identity that is set for the folder in which the given message is.
175 * It is used as a fallback when finding the identity if it can't be found in
176 * any other way.
177 * @param folderIdentityId an uoid of KIdentityManagementCore::Identity
178 */
179 void setFolderIdentity(uint folderIdentityId);
180
181 /**
182 * Whether or not to put the reply to a message in the same folder as the message itself.
183 * If so, specify the folder id in which to put them. Default is -1, which means to not put
184 * replies in the same folder at all.
185 */
186 void putRepliesInSameFolder(Akonadi::Item::Id parentColId = -1);
187
188 /**
189 * When creating MDNs, the user needs to be asked for confirmation in specific
190 * cases according to RFC 2298.
191 */
192 [[nodiscard]] static bool MDNRequested(const KMime::Message::Ptr &msg);
193
194 /**
195 * If sending an MDN requires confirmation due to multiple addresses.
196 *
197 * RFC 2298: [ Confirmation from the user SHOULD be obtained (or no
198 * MDN sent) ] if there is more than one distinct address in the
199 * Disposition-Notification-To header.
200 */
201 [[nodiscard]] static bool MDNConfirmMultipleRecipients(const KMime::Message::Ptr &msg);
202
203 /**
204 *
205 * If sending an MDN requires confirmation due to discrepancy between MDN
206 * header and Return-Path header.
207 *
208 * RFC 2298: MDNs SHOULD NOT be sent automatically if the address in
209 * the Disposition-Notification-To header differs from the address
210 * in the Return-Path header. [...] Confirmation from the user
211 * SHOULD be obtained (or no MDN sent) if there is no Return-Path
212 * header in the message [...]
213 */
214 [[nodiscard]] static bool MDNReturnPathEmpty(const KMime::Message::Ptr &msg);
215 [[nodiscard]] static bool MDNReturnPathNotInRecieptTo(const KMime::Message::Ptr &msg);
216
217 /**
218 * If the MDN headers contain options that KMail can't parse
219 */
220 [[nodiscard]] static bool MDNMDNUnknownOption(const KMime::Message::Ptr &msg);
221
222 [[nodiscard]] bool replyAsHtml() const;
223 void setReplyAsHtml(bool replyAsHtml);
224
225Q_SIGNALS:
226 void createReplyDone(const MessageComposer::MessageFactoryNG::MessageReply &reply);
227 void createForwardDone(const KMime::Message::Ptr &msg);
228
229private:
230 MESSAGECOMPOSER_NO_EXPORT void slotCreateReplyDone(const KMime::Message::Ptr &msg, bool replyAll);
231 MESSAGECOMPOSER_NO_EXPORT void slotCreateForwardDone(const KMime::Message::Ptr &msg);
232 /** @return the UOID of the identity for this message.
233 Searches the "x-kmail-identity" header and if that fails,
234 searches with KIdentityManagementCore::IdentityManager::identityForAddress()
235 **/
236 [[nodiscard]] MESSAGECOMPOSER_NO_EXPORT uint identityUoid(const KMime::Message::Ptr &msg);
237
238 [[nodiscard]] MESSAGECOMPOSER_NO_EXPORT QString replaceHeadersInString(const KMime::Message::Ptr &msg, const QString &s);
239
240 [[nodiscard]] MESSAGECOMPOSER_NO_EXPORT QByteArray getRefStr(const KMime::Message::Ptr &msg);
241 MESSAGECOMPOSER_NO_EXPORT KMime::Content *createForwardAttachmentMessage(const KMime::Message::Ptr &fwdMsg);
242
243 KIdentityManagementCore::IdentityManager *mIdentityManager = nullptr;
244 // Required parts to create messages
245 KMime::Message::Ptr mOrigMsg;
246 uint mFolderId;
247 Akonadi::Item::Id mParentFolderId;
248
249 Akonadi::Collection mCollection;
250
251 // Optional settings the calling class may set
252 MessageComposer::ReplyStrategy mReplyStrategy;
253 QString mSelection;
254 QString mTemplate;
255 bool mQuote = true;
256 bool mReplyAsHtml = false;
257 KMime::Types::Mailbox::List mMailingListAddresses;
259};
260}
261
262Q_DECLARE_METATYPE(MessageComposer::ReplyStrategy)
Contains various factory methods for creating new messages such as replies, MDNs, forwards,...
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
ReplyStrategy
Enumeration that defines the available reply "modes".
Small helper structure which encapsulates the KMime::Message created when creating a reply,...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:12:43 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.