Messagelib

composerviewbase.h
1/*
2 SPDX-FileCopyrightText: 2010 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
3 SPDX-FileCopyrightText: 2010 Leo Franchi <lfranchi@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#pragma once
9
10#include "MessageComposer/Recipient"
11#include "messagecomposer/messagesender.h"
12#include "messagecomposer_export.h"
13#include <Akonadi/Collection>
14#include <Akonadi/Item>
15#include <KMime/Message>
16
17#include <Libkleo/Enum>
18#include <QList>
19#include <QObject>
20#include <QUrl>
21
22class QTimer;
23class KJob;
24class QWidget;
25
26class ComposerViewBaseTest;
27
28namespace Sonnet
29{
30class DictionaryComboBox;
31}
32
33namespace Akonadi
34{
36}
37
38namespace MailTransport
39{
40class TransportComboBox;
41}
42namespace KIdentityManagementWidgets
43{
44class IdentityCombo;
45}
46namespace KIdentityManagementCore
47{
48class Identity;
49class IdentityManager;
50}
51
52namespace Kleo
53{
54class ExpiryChecker;
55class KeyResolver;
56}
57
58namespace MessageComposer
59{
60class RecipientsEditor;
61class RichTextComposerNg;
62class InfoPart;
63class GlobalPart;
64class Composer;
65class AttachmentControllerBase;
66class AttachmentModel;
67class SignatureController;
68class SendLaterInfo;
69/**
70 * @brief The ComposerViewBase class
71 */
72class MESSAGECOMPOSER_EXPORT ComposerViewBase : public QObject
73{
74 Q_OBJECT
75public:
76 explicit ComposerViewBase(QObject *parent = nullptr, QWidget *widget = nullptr);
77 ~ComposerViewBase() override;
78
79 enum Confirmation {
80 LetUserConfirm,
81 NoConfirmationNeeded,
82 };
83 enum MissingAttachment {
84 NoMissingAttachmentFound,
85 FoundMissingAttachmentAndSending,
86 FoundMissingAttachmentAndAddedAttachment,
87 FoundMissingAttachmentAndCancel,
88 };
89
90 enum FailedType {
91 Sending,
92 AutoSave,
93 };
94
95 /**
96 * Set the message to be opened in the composer window, and set the internal data structures to
97 * keep track of it.
98 */
99 void setMessage(const KMime::Message::Ptr &newMsg, bool allowDecryption);
100
101 void updateTemplate(const KMime::Message::Ptr &msg);
102
103 /**
104 * Send the message with the specified method, saving it in the specified folder.
105 */
106 void send(MessageComposer::MessageSender::SendMethod method, MessageComposer::MessageSender::SaveIn saveIn, bool checkMailDispatcher = true);
107
108 /**
109 * Returns true if there is at least one composer job running.
110 */
111 [[nodiscard]] bool isComposing() const;
112
113 /**
114 * Add the given attachment to the message.
115 */
116 void addAttachment(const QUrl &url, const QString &comment, bool sync);
117 void addAttachment(const QString &name, const QString &filename, const QString &charset, const QByteArray &data, const QByteArray &mimeType);
118 void addAttachmentPart(KMime::Content *part);
119
120 void fillComposer(MessageComposer::Composer *composer);
121
122 /**
123 * Header fields in recipients editor.
124 */
125 [[nodiscard]] QString to() const;
126 [[nodiscard]] QString cc() const;
127 [[nodiscard]] QString bcc() const;
128 [[nodiscard]] QString from() const;
129 [[nodiscard]] QString replyTo() const;
130 [[nodiscard]] QString subject() const;
131
132 [[nodiscard]] const KIdentityManagementCore::Identity &currentIdentity() const;
133 [[nodiscard]] bool autocryptEnabled() const;
134
135 /**
136 * The following are for setting the various options and widgets in the
137 * composer.
138 */
139 void setAttachmentModel(MessageComposer::AttachmentModel *model);
140 [[nodiscard]] MessageComposer::AttachmentModel *attachmentModel();
141
142 void setAttachmentController(MessageComposer::AttachmentControllerBase *controller);
143 [[nodiscard]] MessageComposer::AttachmentControllerBase *attachmentController();
144
145 void setRecipientsEditor(MessageComposer::RecipientsEditor *recEditor);
146 [[nodiscard]] MessageComposer::RecipientsEditor *recipientsEditor();
147
148 void setSignatureController(MessageComposer::SignatureController *sigController);
149 [[nodiscard]] MessageComposer::SignatureController *signatureController();
150
151 void setIdentityCombo(KIdentityManagementWidgets::IdentityCombo *identCombo);
152 [[nodiscard]] KIdentityManagementWidgets::IdentityCombo *identityCombo();
153
154 void setIdentityManager(KIdentityManagementCore::IdentityManager *identMan);
155 [[nodiscard]] KIdentityManagementCore::IdentityManager *identityManager();
156
157 void setEditor(MessageComposer::RichTextComposerNg *editor);
158 [[nodiscard]] MessageComposer::RichTextComposerNg *editor() const;
159
160 void setTransportCombo(MailTransport::TransportComboBox *transpCombo);
161 [[nodiscard]] MailTransport::TransportComboBox *transportComboBox() const;
162
163 void setFccCombo(Akonadi::CollectionComboBox *fcc);
164 [[nodiscard]] Akonadi::CollectionComboBox *fccCombo() const;
165 void setFcc(const Akonadi::Collection &id);
166
167 [[nodiscard]] Sonnet::DictionaryComboBox *dictionary() const;
168 void setDictionary(Sonnet::DictionaryComboBox *dictionary);
169
170 /**
171 * Widgets for editing differ in client classes, so
172 * values are set before sending.
173 */
174 void setFrom(const QString &from);
175 void setSubject(const QString &subject);
176
177 /**
178 * The following are various settings the user can modify when composing a message. If they are not set,
179 * the default values will be used.
180 */
181 void setCryptoOptions(bool sign, bool encrypt, Kleo::CryptoMessageFormat format, bool neverEncryptDrafts = false);
182 void setMDNRequested(bool mdnRequested);
183 void setUrgent(bool urgent);
184
185 void setAutoSaveInterval(int interval);
186 void setCustomHeader(const QMap<QByteArray, QString> &customHeader);
187
188 /**
189 * Enables/disables autosaving depending on the value of the autosave
190 * interval.
191 */
192 void updateAutoSave();
193
194 /**
195 * Sets the filename to use when autosaving something. This is used when the client recovers
196 * the autosave files: It calls this method, so that the composer uses the same filename again.
197 * That way, the recovered autosave file is properly cleaned up in cleanupAutoSave():
198 */
199 void setAutoSaveFileName(const QString &fileName);
200
201 /**
202 * Stop autosaving and delete the autosaved message.
203 */
204 void cleanupAutoSave();
205
206 void setParentWidgetForGui(QWidget *);
207
208 /**
209 * Check if the mail has references to attachments, but no attachments are added to it.
210 * If missing attachments are found, a dialog to add new attachments is shown.
211 * @param attachmentKeywords a list with the keywords that indicate an attachment should be present
212 * @return NoMissingAttachmentFound, if there is attachment in email
213 * FoundMissingAttachmentAndCancelSending, if mail might miss attachment but sending
214 * FoundMissingAttachmentAndAddedAttachment, if mail might miss attachment and we added an attachment
215 * FoundMissingAttachmentAndCancel, if mail might miss attachment and cancel sending
216 */
217 [[nodiscard]] ComposerViewBase::MissingAttachment checkForMissingAttachments(const QStringList &attachmentKeywords);
218
219 [[nodiscard]] bool hasMissingAttachments(const QStringList &attachmentKeywords);
220
221 void setSendLaterInfo(SendLaterInfo *info);
222 [[nodiscard]] SendLaterInfo *sendLaterInfo() const;
223 void saveMailSettings();
224
225 [[nodiscard]] QDate followUpDate() const;
226 void setFollowUpDate(const QDate &followUpDate);
227
228 void clearFollowUp();
229
230 [[nodiscard]] Akonadi::Collection followUpCollection() const;
231 void setFollowUpCollection(const Akonadi::Collection &followUpCollection);
232
233 [[nodiscard]] KMime::Message::Ptr msg() const;
234
235 [[nodiscard]] bool requestDeleveryConfirmation() const;
236 void setRequestDeleveryConfirmation(bool requestDeleveryConfirmation);
237
238 [[nodiscard]] std::shared_ptr<Kleo::ExpiryChecker> expiryChecker();
239
240public Q_SLOTS:
241 void identityChanged(const KIdentityManagementCore::Identity &ident, const KIdentityManagementCore::Identity &oldIdent, bool msgCleared = false);
242
243 /**
244 * Save the message.
245 */
246 void autoSaveMessage();
247
248Q_SIGNALS:
249 /**
250 * Message sending completed successfully.
251 */
253 /**
254 * Message sending failed with given error message.
255 */
256 void failed(const QString &errorMessage, MessageComposer::ComposerViewBase::FailedType type = Sending);
257
258 /**
259 * The composer was modified. This can happen behind the users' back
260 * when, for example, and autosaved message was recovered.
261 */
262 void modified(bool isModified);
263
264 /**
265 * Enabling or disabling HTML in the editor is affected
266 * by various client options, so when that would otherwise happen,
267 * hand it off to the client to enact it for real.
268 */
269 void disableHtml(MessageComposer::ComposerViewBase::Confirmation);
270 void enableHtml();
271 void tooManyRecipient(bool);
272
273private:
274 void slotEmailAddressResolved(KJob *);
275 void slotSendComposeResult(KJob *);
276 void slotQueueResult(KJob *job);
277 void slotCreateItemResult(KJob *);
278 void slotAutoSaveComposeResult(KJob *job);
279 void slotFccCollectionCheckResult(KJob *job);
280 void slotSaveMessage(KJob *job);
281
282 [[nodiscard]] Akonadi::Collection defaultSpecialTarget() const;
283 /**
284 * Searches the mime tree, where root is the root node, for embedded images,
285 * extracts them froom the body and adds them to the editor.
286 */
287 void collectImages(KMime::Content *root);
288 [[nodiscard]] bool inlineSigningEncryptionSelected() const;
289 /**
290 * Applies the user changes to the message object of the composer
291 * and signs/encrypts the message if activated.
292 * Disables the controls of the composer window.
293 */
294 void readyForSending();
295
296 enum RecipientExpansion {
297 UseExpandedRecipients,
298 UseUnExpandedRecipients,
299 };
300 void fillComposer(MessageComposer::Composer *composer, ComposerViewBase::RecipientExpansion expansion, bool autoresize);
301 [[nodiscard]] QList<MessageComposer::Composer *> generateCryptoMessages(bool &wasCanceled);
302 void fillGlobalPart(MessageComposer::GlobalPart *globalPart);
303 void fillInfoPart(MessageComposer::InfoPart *part, RecipientExpansion expansion);
304 void queueMessage(const KMime::Message::Ptr &message, MessageComposer::Composer *composer);
305 void saveMessage(const KMime::Message::Ptr &message, MessageComposer::MessageSender::SaveIn saveIn);
306 void saveRecentAddresses(const KMime::Message::Ptr &ptr);
307 void
308 updateRecipients(const KIdentityManagementCore::Identity &ident, const KIdentityManagementCore::Identity &oldIdent, MessageComposer::Recipient::Type type);
309
310 void markAllAttachmentsForSigning(bool sign);
311 void markAllAttachmentsForEncryption(bool encrypt);
312 bool determineWhetherToSign(bool doSignCompletely, Kleo::KeyResolver *keyResolver, bool signSomething, bool &result, bool &canceled);
313 bool determineWhetherToEncrypt(bool doEncryptCompletely,
314 Kleo::KeyResolver *keyResolver,
315 bool encryptSomething,
316 bool signSomething,
317 bool &result,
318 bool &canceled);
319
320 /**
321 * Writes out autosave data to the disk from the KMime::Message message.
322 * Also appends the msgNum to the filename as a message can have a number of
323 * KMime::Messages
324 */
325 void writeAutoSaveToDisk(const KMime::Message::Ptr &message);
326
327 /**
328 * Returns the autosave interval in milliseconds (as needed for QTimer).
329 */
330 int autoSaveInterval() const;
331
332 /**
333 * Initialize autosaving (timer and filename).
334 */
335 void initAutoSave();
336 void addFollowupReminder(const QString &messageId);
337 void addSendLaterItem(const Akonadi::Item &item);
338
339 bool addKeysToContext(const QString &gnupgHome,
340 const QList<QPair<QStringList, std::vector<GpgME::Key>>> &data,
341 const std::map<QByteArray, QString> &autocryptMap);
342
343 void setAkonadiLookupEnabled(bool akonadiLookupEnabled);
344
346 MessageComposer::AttachmentControllerBase *m_attachmentController = nullptr;
347 MessageComposer::AttachmentModel *m_attachmentModel = nullptr;
348 MessageComposer::SignatureController *m_signatureController = nullptr;
349 MessageComposer::RecipientsEditor *m_recipientsEditor = nullptr;
350 KIdentityManagementWidgets::IdentityCombo *m_identityCombo = nullptr;
351 KIdentityManagementCore::IdentityManager *m_identMan = nullptr;
352 MessageComposer::RichTextComposerNg *m_editor = nullptr;
353 MailTransport::TransportComboBox *m_transport = nullptr;
354 Sonnet::DictionaryComboBox *m_dictionary = nullptr;
355 Akonadi::CollectionComboBox *m_fccCombo = nullptr;
356 Akonadi::Collection m_fccCollection;
357 QWidget *m_parentWidget = nullptr;
358
359 // List of active composer jobs. For example, saving as draft, autosaving and printing
360 // all create a composer, which is added to this list as long as it is active.
361 // Used mainly to prevent closing the window if a composer is active
363
364 bool m_sign = false;
365 bool m_encrypt = false;
366 bool m_neverEncrypt = false;
367 bool m_mdnRequested = false;
368 bool m_urgent = false;
369 bool m_requestDeleveryConfirmation = false;
370 bool m_akonadiLookupEnabled = true;
371 Kleo::CryptoMessageFormat m_cryptoMessageFormat;
372 QString mExpandedFrom;
373 QString m_from;
374 QString m_subject;
375 QStringList mExpandedTo, mExpandedCc, mExpandedBcc, mExpandedReplyTo;
376 QMap<QByteArray, QString> m_customHeader;
377
378 int m_pendingQueueJobs = 0;
379
380 QTimer *m_autoSaveTimer = nullptr;
381 QString m_autoSaveUUID;
382 bool m_autoSaveErrorShown = false; // Stops an error message being shown every time autosave is executed.
383 int m_autoSaveInterval;
384
385 MessageComposer::MessageSender::SendMethod mSendMethod;
386 MessageComposer::MessageSender::SaveIn mSaveIn;
387
388 std::shared_ptr<Kleo::ExpiryChecker> mExpiryChecker;
389
390 QDate mFollowUpDate;
391 Akonadi::Collection mFollowUpCollection;
392
393 std::unique_ptr<SendLaterInfo> mSendLaterInfo;
394
395 friend ComposerViewBaseTest;
396};
397} // namespace
The AttachmentModel class.
The ComposerViewBase class.
void failed(const QString &errorMessage, MessageComposer::ComposerViewBase::FailedType type=Sending)
Message sending failed with given error message.
void sentSuccessfully(Akonadi::Item::Id id)
Message sending completed successfully.
void disableHtml(MessageComposer::ComposerViewBase::Confirmation)
Enabling or disabling HTML in the editor is affected by various client options, so when that would ot...
void modified(bool isModified)
The composer was modified.
The Composer class.
Definition composer.h:35
The GlobalPart class.
Definition globalpart.h:20
The InfoPart class contains the message header.
Definition infopart.h:22
The RecipientsEditor class.
The RichTextComposerNg class.
Send later information.
The SignatureController class Controls signature (the footer thing, not the crypto thing) operations ...
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:54:19 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.