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 <Libkleo/Formatting>
19#include "messagecomposer_debug.h"
21#include <gpgme++/encryptionresult.h>
22#include <gpgme++/global.h>
23#include <gpgme++/signingresult.h>
28class MessageComposer::EncryptJobPrivate :
public ContentJobBasePrivate
32 : ContentJobBasePrivate(qq)
38 std::vector<GpgME::Key> keys;
39 Kleo::CryptoMessageFormat format;
43 bool protectedHeaders =
true;
44 bool protectedHeadersObvoscate =
false;
47 bool binaryHint(Kleo::CryptoMessageFormat f)
50 case Kleo::SMIMEFormat:
51 case Kleo::SMIMEOpaqueFormat:
54 case Kleo::OpenPGPMIMEFormat:
55 case Kleo::InlineOpenPGPFormat:
60 GpgME::SignatureMode signingMode(Kleo::CryptoMessageFormat f)
63 case Kleo::SMIMEOpaqueFormat:
64 return GpgME::NormalSignatureMode;
65 case Kleo::InlineOpenPGPFormat:
66 return GpgME::Clearsigned;
68 case Kleo::SMIMEFormat:
69 case Kleo::OpenPGPMIMEFormat:
70 return GpgME::Detached;
77EncryptJob::EncryptJob(
QObject *parent)
82EncryptJob::~EncryptJob() =
default;
92void EncryptJob::setCryptoMessageFormat(Kleo::CryptoMessageFormat format)
99void EncryptJob::setEncryptionKeys(
const std::vector<GpgME::Key> &keys)
106void EncryptJob::setRecipients(
const QStringList &recipients)
110 d->recipients = recipients;
113void EncryptJob::setSkeletonMessage(
KMime::Message *skeletonMessage)
117 d->skeletonMessage = skeletonMessage;
120void EncryptJob::setProtectedHeaders(
bool protectedHeaders)
124 d->protectedHeaders = protectedHeaders;
127void EncryptJob::setProtectedHeadersObvoscate(
bool protectedHeadersObvoscate)
131 d->protectedHeadersObvoscate = protectedHeadersObvoscate;
134void EncryptJob::setGnupgHome(
const QString &path)
145 return d->recipients;
148std::vector<GpgME::Key> EncryptJob::encryptionKeys()
const
155void EncryptJob::doStart()
158 Q_ASSERT(d->resultContent ==
nullptr);
160 if (d->keys.size() == 0) {
161 qCDebug(MESSAGECOMPOSER_LOG) <<
"HELP! Encrypt job but have no keys to encrypt with.";
167 if (!d->content || !d->content->hasContent()) {
168 if (d->subjobContents.size() == 1) {
169 d->content = d->subjobContents.constFirst();
173 if (d->protectedHeaders && d->skeletonMessage && d->format & Kleo::OpenPGPMIMEFormat) {
175 pJob->setContent(d->content);
176 pJob->setSkeletonMessage(d->skeletonMessage);
177 pJob->setObvoscate(d->protectedHeadersObvoscate);
182 d->content = pJob->content();
190void EncryptJob::slotResult(
KJob *job)
194 ContentJobBase::slotResult(job);
202 pjob->setContent(cjob->content());
206 ContentJobBase::slotResult(job);
209void EncryptJob::process()
215 if (!d->content || !d->content->hasContent()) {
216 Q_ASSERT(d->subjobContents.size() == 1);
217 d->content = d->subjobContents.constFirst();
220 const QGpgME::Protocol *proto =
nullptr;
221 if (d->format & Kleo::AnyOpenPGP) {
222 proto = QGpgME::openpgp();
223 }
else if (d->format & Kleo::AnySMIME) {
224 proto = QGpgME::smime();
226 qCDebug(MESSAGECOMPOSER_LOG) <<
"HELP! Encrypt job but have protocol to encrypt with.";
235 if (d->format & Kleo::InlineOpenPGPFormat) {
241 qCDebug(MESSAGECOMPOSER_LOG) <<
"got backend, starting job";
242 QGpgME::EncryptJob *eJob = proto->encryptJob(!d->binaryHint(d->format), d->format == Kleo::InlineOpenPGPFormat);
244 if (!d->gnupgHome.isEmpty()) {
245 QGpgME::Job::context(eJob)->setEngineHomeDirectory(d->gnupgHome.toUtf8().constData());
250 &QGpgME::EncryptJob::result,
252 [
this, d](
const GpgME::EncryptionResult &
result,
const QByteArray &cipherText,
const QString &auditLogAsHtml,
const GpgME::Error &auditLogError) {
253 Q_UNUSED(auditLogAsHtml)
254 Q_UNUSED(auditLogError)
261 d->resultContent = MessageComposer::Util::composeHeadersAndBody(d->content, cipherText, d->format,
false);
275#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)