Changeset View
Changeset View
Standalone View
Standalone View
messagecomposer/src/job/signencryptjob.cpp
Show All 15 Lines | 1 | /* | |||
---|---|---|---|---|---|
16 | along with this library; see the file COPYING.LIB. If not, write to the | 16 | along with this library; see the file COPYING.LIB. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
18 | 02110-1301, USA. | 18 | 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "job/signencryptjob.h" | 21 | #include "job/signencryptjob.h" | ||
22 | 22 | | |||
23 | #include "contentjobbase_p.h" | 23 | #include "contentjobbase_p.h" | ||
24 | #include "utils/util.h" | 24 | #include "job/protectedheaders.h" | ||
25 | #include "utils/util_p.h" | 25 | #include "utils/util_p.h" | ||
26 | 26 | | |||
27 | #include <Libkleo/Enum> | 27 | #include <Libkleo/Enum> | ||
28 | #include <QGpgME/Protocol> | 28 | #include <QGpgME/Protocol> | ||
29 | #include <QGpgME/SignEncryptJob> | 29 | #include <QGpgME/SignEncryptJob> | ||
30 | 30 | | |||
31 | #include "messagecomposer_debug.h" | 31 | #include "messagecomposer_debug.h" | ||
32 | #include <kmime/kmime_message.h> | 32 | #include <kmime/kmime_message.h> | ||
Show All 16 Lines | 45 | public: | |||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | std::vector<GpgME::Key> signers; | 51 | std::vector<GpgME::Key> signers; | ||
52 | 52 | | |||
53 | std::vector<GpgME::Key> encKeys; | 53 | std::vector<GpgME::Key> encKeys; | ||
54 | QStringList recipients; | 54 | QStringList recipients; | ||
55 | Kleo::CryptoMessageFormat format; | 55 | Kleo::CryptoMessageFormat format; | ||
56 | KMime::Content *content = nullptr; | 56 | KMime::Content *content = nullptr; | ||
57 | KMime::Message *skeletonMessage = nullptr; | ||||
58 | | ||||
59 | bool protectedHeaders = true; | ||||
60 | bool protectedHeadersObvoscate = false; | ||||
57 | 61 | | |||
58 | // copied from messagecomposer.cpp | 62 | // copied from messagecomposer.cpp | ||
59 | bool binaryHint(Kleo::CryptoMessageFormat f) | 63 | bool binaryHint(Kleo::CryptoMessageFormat f) | ||
60 | { | 64 | { | ||
61 | switch (f) { | 65 | switch (f) { | ||
62 | case Kleo::SMIMEFormat: | 66 | case Kleo::SMIMEFormat: | ||
63 | case Kleo::SMIMEOpaqueFormat: | 67 | case Kleo::SMIMEOpaqueFormat: | ||
64 | return true; | 68 | return true; | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
125 | 129 | | |||
126 | void SignEncryptJob::setRecipients(const QStringList &recipients) | 130 | void SignEncryptJob::setRecipients(const QStringList &recipients) | ||
127 | { | 131 | { | ||
128 | Q_D(SignEncryptJob); | 132 | Q_D(SignEncryptJob); | ||
129 | 133 | | |||
130 | d->recipients = recipients; | 134 | d->recipients = recipients; | ||
131 | } | 135 | } | ||
132 | 136 | | |||
137 | void SignEncryptJob::setSkeletonMessage(KMime::Message *skeletonMessage) | ||||
138 | { | ||||
139 | Q_D(SignEncryptJob); | ||||
140 | | ||||
141 | d->skeletonMessage = skeletonMessage; | ||||
142 | } | ||||
143 | | ||||
144 | void SignEncryptJob::setProtectedHeaders(bool protectedHeaders) | ||||
145 | { | ||||
146 | Q_D(SignEncryptJob); | ||||
147 | | ||||
148 | d->protectedHeaders = protectedHeaders; | ||||
149 | } | ||||
150 | | ||||
151 | void SignEncryptJob::setProtectedHeadersObvoscate(bool protectedHeadersObvoscate) | ||||
152 | { | ||||
153 | Q_D(SignEncryptJob); | ||||
154 | | ||||
155 | d->protectedHeadersObvoscate = protectedHeadersObvoscate; | ||||
156 | } | ||||
157 | | ||||
133 | QStringList SignEncryptJob::recipients() const | 158 | QStringList SignEncryptJob::recipients() const | ||
134 | { | 159 | { | ||
135 | Q_D(const SignEncryptJob); | 160 | Q_D(const SignEncryptJob); | ||
136 | 161 | | |||
137 | return d->recipients; | 162 | return d->recipients; | ||
138 | } | 163 | } | ||
139 | 164 | | |||
140 | std::vector<GpgME::Key> SignEncryptJob::encryptionKeys() const | 165 | std::vector<GpgME::Key> SignEncryptJob::encryptionKeys() const | ||
141 | { | 166 | { | ||
142 | Q_D(const SignEncryptJob); | 167 | Q_D(const SignEncryptJob); | ||
143 | 168 | | |||
144 | return d->encKeys; | 169 | return d->encKeys; | ||
145 | } | 170 | } | ||
146 | 171 | | |||
172 | void SignEncryptJob::doStart() | ||||
173 | { | ||||
174 | Q_D(SignEncryptJob); | ||||
175 | Q_ASSERT(d->resultContent == nullptr); // Not processed before. | ||||
176 | | ||||
177 | if (d->protectedHeaders && d->skeletonMessage && d->format & Kleo::OpenPGPMIMEFormat) { | ||||
178 | ProtectedHeadersJob *pJob = new ProtectedHeadersJob; | ||||
179 | pJob->setContent(d->content); | ||||
180 | pJob->setSkeletonMessage(d->skeletonMessage); | ||||
181 | pJob->setObvoscate(d->protectedHeadersObvoscate); | ||||
182 | QObject::connect(pJob, &ProtectedHeadersJob::finished, this, [d, pJob](KJob *job) { | ||||
183 | if (job->error()) { | ||||
184 | return; | ||||
185 | } | ||||
186 | d->content = pJob->content(); | ||||
187 | }); | ||||
188 | appendSubjob(pJob); | ||||
189 | } | ||||
190 | | ||||
191 | ContentJobBase::doStart(); | ||||
192 | } | ||||
193 | | ||||
194 | | ||||
195 | void SignEncryptJob::slotResult(KJob *job) | ||||
196 | { | ||||
197 | Q_D(SignEncryptJob); | ||||
198 | if (error()) { | ||||
199 | ContentJobBase::slotResult(job); | ||||
200 | return; | ||||
201 | } | ||||
202 | if (subjobs().size() == 2) { | ||||
203 | auto pjob = static_cast<ProtectedHeadersJob *>(subjobs().last()); | ||||
204 | if (pjob) { | ||||
205 | auto cjob = dynamic_cast<ContentJobBase *>(job); | ||||
206 | Q_ASSERT(cjob); | ||||
207 | pjob->setContent(cjob->content()); | ||||
208 | } | ||||
209 | } | ||||
210 | | ||||
211 | ContentJobBase::slotResult(job); | ||||
212 | } | ||||
213 | | ||||
147 | void SignEncryptJob::process() | 214 | void SignEncryptJob::process() | ||
148 | { | 215 | { | ||
149 | Q_D(SignEncryptJob); | 216 | Q_D(SignEncryptJob); | ||
150 | Q_ASSERT(d->resultContent == nullptr); // Not processed before. | 217 | Q_ASSERT(d->resultContent == nullptr); // Not processed before. | ||
151 | 218 | | |||
152 | // if setContent hasn't been called, we assume that a subjob was added | 219 | // if setContent hasn't been called, we assume that a subjob was added | ||
153 | // and we want to use that | 220 | // and we want to use that | ||
154 | if (!d->content || !d->content->hasContent()) { | 221 | if (!d->content || !d->content->hasContent()) { | ||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |