8#include "job/encryptjob.h"
10#include "contentjobbase_p.h"
11#include "job/protectedheadersjob.h"
12#include "utils/util_p.h"
14#include <QGpgME/EncryptJob>
15#include <QGpgME/Protocol>
17#include "messagecomposer_debug.h"
19#include <gpgme++/encryptionresult.h>
20#include <gpgme++/global.h>
21#include <gpgme++/signingresult.h>
26class MessageComposer::EncryptJobPrivate :
public ContentJobBasePrivate
30 : ContentJobBasePrivate(qq)
36 std::vector<GpgME::Key> keys;
37 Kleo::CryptoMessageFormat format;
41 bool protectedHeaders =
true;
42 bool protectedHeadersObvoscate =
false;
45 bool binaryHint(Kleo::CryptoMessageFormat f)
48 case Kleo::SMIMEFormat:
49 case Kleo::SMIMEOpaqueFormat:
52 case Kleo::OpenPGPMIMEFormat:
53 case Kleo::InlineOpenPGPFormat:
58 GpgME::SignatureMode signingMode(Kleo::CryptoMessageFormat f)
61 case Kleo::SMIMEOpaqueFormat:
62 return GpgME::NormalSignatureMode;
63 case Kleo::InlineOpenPGPFormat:
64 return GpgME::Clearsigned;
66 case Kleo::SMIMEFormat:
67 case Kleo::OpenPGPMIMEFormat:
68 return GpgME::Detached;
75EncryptJob::EncryptJob(
QObject *parent)
80EncryptJob::~EncryptJob() =
default;
90void EncryptJob::setCryptoMessageFormat(Kleo::CryptoMessageFormat format)
97void EncryptJob::setEncryptionKeys(
const std::vector<GpgME::Key> &keys)
104void EncryptJob::setRecipients(
const QStringList &recipients)
108 d->recipients = recipients;
111void EncryptJob::setSkeletonMessage(
KMime::Message *skeletonMessage)
115 d->skeletonMessage = skeletonMessage;
118void EncryptJob::setProtectedHeaders(
bool protectedHeaders)
122 d->protectedHeaders = protectedHeaders;
125void EncryptJob::setProtectedHeadersObvoscate(
bool protectedHeadersObvoscate)
129 d->protectedHeadersObvoscate = protectedHeadersObvoscate;
132void EncryptJob::setGnupgHome(
const QString &path)
143 return d->recipients;
146std::vector<GpgME::Key> EncryptJob::encryptionKeys()
const
153void EncryptJob::doStart()
156 Q_ASSERT(d->resultContent ==
nullptr);
158 if (d->keys.size() == 0) {
159 qCDebug(MESSAGECOMPOSER_LOG) <<
"HELP! Encrypt job but have no keys to encrypt with.";
165 if (!d->content || !d->content->hasContent()) {
166 if (d->subjobContents.size() == 1) {
167 d->content = d->subjobContents.constFirst();
171 if (d->protectedHeaders && d->skeletonMessage && d->format & Kleo::OpenPGPMIMEFormat) {
173 pJob->setContent(d->content);
174 pJob->setSkeletonMessage(d->skeletonMessage);
175 pJob->setObvoscate(d->protectedHeadersObvoscate);
180 d->content = pJob->content();
188void EncryptJob::slotResult(
KJob *job)
192 ContentJobBase::slotResult(job);
200 pjob->setContent(cjob->content());
204 ContentJobBase::slotResult(job);
207void EncryptJob::process()
213 if (!d->content || !d->content->hasContent()) {
214 Q_ASSERT(d->subjobContents.size() == 1);
215 d->content = d->subjobContents.constFirst();
218 const QGpgME::Protocol *proto =
nullptr;
219 if (d->format & Kleo::AnyOpenPGP) {
220 proto = QGpgME::openpgp();
221 }
else if (d->format & Kleo::AnySMIME) {
222 proto = QGpgME::smime();
224 qCDebug(MESSAGECOMPOSER_LOG) <<
"HELP! Encrypt job but have protocol to encrypt with.";
233 if (d->format & Kleo::InlineOpenPGPFormat) {
239 qCDebug(MESSAGECOMPOSER_LOG) <<
"got backend, starting job";
240 QGpgME::EncryptJob *eJob = proto->encryptJob(!d->binaryHint(d->format), d->format == Kleo::InlineOpenPGPFormat);
242 if (!d->gnupgHome.isEmpty()) {
243 QGpgME::Job::context(eJob)->setEngineHomeDirectory(d->gnupgHome.toUtf8().constData());
248 &QGpgME::EncryptJob::result,
250 [
this, d](
const GpgME::EncryptionResult &
result,
const QByteArray &cipherText,
const QString &auditLogAsHtml,
const GpgME::Error &auditLogError) {
251 Q_UNUSED(auditLogAsHtml)
252 Q_UNUSED(auditLogError)
259 d->resultContent = MessageComposer::Util::composeHeadersAndBody(d->content, cipherText, d->format,
false);
273#include "moc_encryptjob.cpp"
const QList< KJob * > & subjobs() const
void setErrorText(const QString &errorText)
void setError(int errorCode)
Content * content(const ContentIndex &index) const
QByteArray encodedContent(bool useCrLf=false) const
The ContentJobBase class.
virtual void doStart()
Reimplement to do additional stuff before processing children, such as adding more subjobs.
bool appendSubjob(ContentJobBase *job)
This is meant to be used instead of KCompositeJob::addSubjob(), making it possible to add subjobs fro...
KMime::Content * content() const
Get the resulting KMime::Content that the ContentJobBase has generated.
Encrypt the contents of a message .
QString path(const QString &relativePath)
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
QString fromLocal8Bit(QByteArrayView str)