Incidenceeditor

opencomposerjob.cpp
1/*
2 * SPDX-FileCopyrightText: 2014 Sandro Knauß <knauss@kolabsys.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#include "opencomposerjob.h"
8
9#include <KLocalizedString>
10
11#include <QDBusConnectionInterface>
12#include <QDBusInterface>
13
14using namespace IncidenceEditorNG;
15
16OpenComposerJob::OpenComposerJob(QObject *parent,
17 const QString &to,
18 const QString &cc,
19 const QString &bcc,
20 const KMime::Message::Ptr &message,
22 : KJob(parent)
23 , mTo(to)
24 , mCc(cc)
25 , mBcc(bcc)
26 , mMessage(message)
27 , mIdentity(identity)
28{
29}
30
31OpenComposerJob::~OpenComposerJob() = default;
32
33void OpenComposerJob::start()
34{
35 Q_ASSERT(mMessage);
36
37 unsigned int identity = mIdentity.uoid();
38
39 QString subject = mMessage->subject()->asUnicodeString();
40 QString body = QString::fromUtf8(mMessage->contents()[0]->body());
41
42 QList<QVariant> messages;
43
44 if (mMessage->contents().count() == 1) {
45 const QString messageFile;
46 const QStringList attachmentPaths;
47 const QStringList customHeaders;
48 const QString replyTo;
49 const QString inReplyTo;
50 bool hidden = false;
51
52 messages << mTo << mCc << mBcc << subject << body << hidden << messageFile << attachmentPaths << customHeaders << replyTo << inReplyTo;
53 } else {
54 KMime::Content *attachment(mMessage->contents().at(1));
55 QString attachName = attachment->contentType()->name();
56 QByteArray attachCte = attachment->contentTransferEncoding()->as7BitString(false);
57 QByteArray attachType = attachment->contentType()->mediaType();
58 QByteArray attachSubType = attachment->contentType()->subType();
59 QByteArray attachContDisp = attachment->contentDisposition()->as7BitString(false);
60 QByteArray attachCharset = attachment->contentType()->charset();
61
62 QByteArray attachParamAttr = "method";
63 QString attachParamValue = attachment->contentType()->parameter("method");
64 QByteArray attachData = attachment->encodedBody();
65
66 messages << mTo << mCc << mBcc << subject << body << attachName << attachCte << attachData << attachType << attachSubType << attachParamAttr
67 << attachParamValue << attachContDisp << attachCharset << identity;
68 }
69
70 // with D-Bus autostart, this will start kmail if it's not running yet
71 QDBusInterface kmailObj(QStringLiteral("org.kde.kmail"), QStringLiteral("/KMail"), QStringLiteral("org.kde.kmail.kmail"));
72
73 QDBusReply<int> composerDbusPath = kmailObj.callWithArgumentList(QDBus::AutoDetect, QStringLiteral("openComposer"), messages);
74
75 if (!composerDbusPath.isValid()) {
76 setError(KJob::UserDefinedError);
77 setErrorText(i18nc("errormessage: dbus is running but still no connection kmail", "Cannot connect to email service"));
78 }
79 emitResult();
80}
81
82#include "moc_opencomposerjob.cpp"
void setErrorText(const QString &errorText)
void emitResult()
void setError(int errorCode)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
bool isValid() const const
QString fromUtf8(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 13 2024 11:52:53 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.