File indexing completed on 2024-04-28 05:36:50

0001 /*
0002  * SPDX-FileCopyrightText: 2017 Red Hat Inc
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  *
0006  * SPDX-FileCopyrightText: 2017 Jan Grulich <jgrulich@redhat.com>
0007  */
0008 
0009 #include "email.h"
0010 #include "email_debug.h"
0011 
0012 #include <QUrl>
0013 
0014 #include <KEMailClientLauncherJob>
0015 
0016 EmailPortal::EmailPortal(QObject *parent)
0017     : QDBusAbstractAdaptor(parent)
0018 {
0019 }
0020 
0021 uint EmailPortal::ComposeEmail(const QDBusObjectPath &handle, const QString &app_id, const QString &window, const QVariantMap &options, QVariantMap &results)
0022 {
0023     Q_UNUSED(results)
0024 
0025     qCDebug(XdgDesktopPortalKdeEmail) << "ComposeEmail called with parameters:";
0026     qCDebug(XdgDesktopPortalKdeEmail) << "    handle: " << handle.path();
0027     qCDebug(XdgDesktopPortalKdeEmail) << "    app_id: " << app_id;
0028     qCDebug(XdgDesktopPortalKdeEmail) << "    window: " << window;
0029     qCDebug(XdgDesktopPortalKdeEmail) << "    options: " << options;
0030 
0031     const QStringList addresses = options.contains(QStringLiteral("address")) ? options.value(QStringLiteral("address")).toStringList()
0032                                                                               : options.value(QStringLiteral("addresses")).toStringList();
0033 
0034     KEMailClientLauncherJob job;
0035     job.setTo(addresses);
0036     job.setCc(options.value(QStringLiteral("cc")).toStringList());
0037     job.setBcc(options.value(QStringLiteral("bcc")).toStringList());
0038     job.setSubject(options.value(QStringLiteral("subject")).toString());
0039     job.setBody(options.value(QStringLiteral("body")).toString());
0040 
0041     const QStringList attachmentStrings = options.value(QStringLiteral("attachments")).toStringList();
0042     QList<QUrl> attachments;
0043     for (const QString &attachment : attachmentStrings) {
0044         attachments << QUrl(attachment);
0045     }
0046     job.setAttachments(attachments);
0047 
0048     return job.exec();
0049 }