File indexing completed on 2024-11-24 04:50:44

0001 /*
0002   SPDX-FileCopyrightText: 1998 Barry D Benowitz <b.benowitz@telesciences.com>
0003   SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org>
0004   SPDX-FileCopyrightText: 2009 Allen Winter <winter@kde.org>
0005   SPDX-FileCopyrightText: 2023 Aakarsh MJ <mj.akarsh@gmail.com>
0006 
0007   SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include "mailheadermodel.h"
0013 #include <KMime/KMimeMessage>
0014 #include <QObject>
0015 
0016 namespace KIdentityManagementCore
0017 {
0018 class Identity;
0019 class IdentityModel;
0020 }
0021 
0022 namespace Kleo
0023 {
0024 class KeyResolver;
0025 }
0026 
0027 namespace MessageComposer
0028 {
0029 class Composer;
0030 class ContactPreference;
0031 }
0032 
0033 namespace MailTransport
0034 {
0035 class Transport;
0036 }
0037 
0038 namespace GpgME
0039 {
0040 class Key;
0041 }
0042 
0043 class KJob;
0044 
0045 namespace Akonadi
0046 {
0047 
0048 class MailClient : public QObject
0049 {
0050     Q_OBJECT
0051 
0052     struct MessageData {
0053         QString from;
0054         QStringList to;
0055         QStringList cc;
0056         QStringList bcc;
0057         QString subject;
0058         QString body;
0059     };
0060 
0061 public:
0062     enum Result { ResultSuccess, ResultNoAttendees, ResultReallyNoAttendees, ResultErrorCreatingTransport, ResultErrorFetchingTransport, ResultQueueJobError };
0063 
0064     explicit MailClient(QObject *parent = nullptr);
0065     ~MailClient() override;
0066 
0067     Q_INVOKABLE void send(KIdentityManagementCore::IdentityModel *identityModel, MailHeaderModel *header, const QString &subject, const QString &body);
0068 
0069 private:
0070     std::unique_ptr<MessageComposer::Composer>
0071     populateComposer(const MessageData &msg, KIdentityManagementCore::IdentityModel *identityModel, int *transportId);
0072 
0073     void queueMessage(const int transport,
0074                       const MessageComposer::Composer *composer,
0075                       const KIdentityManagementCore::Identity &identity,
0076                       const KMime::Message::Ptr &message);
0077 
0078     void handleQueueJobFinished(KJob *job);
0079     QVector<QByteArray> m_charsets;
0080 
0081 Q_SIGNALS:
0082     void finished(Akonadi::MailClient::Result result, const QString &errorString);
0083 };
0084 }
0085 
0086 Q_DECLARE_METATYPE(Akonadi::MailClient::Result)