diff options
Diffstat (limited to 'framework/src/domain/mime/mailcrypto.cpp')
-rw-r--r-- | framework/src/domain/mime/mailcrypto.cpp | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/framework/src/domain/mime/mailcrypto.cpp b/framework/src/domain/mime/mailcrypto.cpp index 62a71e42..2dc2d245 100644 --- a/framework/src/domain/mime/mailcrypto.cpp +++ b/framework/src/domain/mime/mailcrypto.cpp | |||
@@ -145,21 +145,20 @@ KMime::Content *setBodyAndCTE(QByteArray &encodedBody, KMime::Headers::ContentTy | |||
145 | return ret; | 145 | return ret; |
146 | } | 146 | } |
147 | 147 | ||
148 | void makeToplevelContentType(KMime::Content *content, bool sign, const QByteArray &hashAlgo) | 148 | void makeToplevelContentType(KMime::Content *content, bool encrypt, const QByteArray &hashAlgo) |
149 | { | 149 | { |
150 | //Kleo::CryptoMessageFormat format, | 150 | //Kleo::CryptoMessageFormat format, |
151 | // switch (format) { | 151 | // switch (format) { |
152 | // default: | 152 | // default: |
153 | // case Kleo::InlineOpenPGPFormat: | 153 | // case Kleo::InlineOpenPGPFormat: |
154 | // case Kleo::OpenPGPMIMEFormat: | 154 | // case Kleo::OpenPGPMIMEFormat: |
155 | if (sign) { | 155 | if (encrypt) { |
156 | content->contentType()->setMimeType(QByteArrayLiteral("multipart/encrypted")); | ||
157 | content->contentType()->setParameter(QStringLiteral("protocol"), QStringLiteral("application/pgp-encrypted")); | ||
158 | } else { | ||
156 | content->contentType()->setMimeType(QByteArrayLiteral("multipart/signed")); | 159 | content->contentType()->setMimeType(QByteArrayLiteral("multipart/signed")); |
157 | content->contentType()->setParameter(QStringLiteral("protocol"), QStringLiteral("application/pgp-signature")); | 160 | content->contentType()->setParameter(QStringLiteral("protocol"), QStringLiteral("application/pgp-signature")); |
158 | content->contentType()->setParameter(QStringLiteral("micalg"), QString::fromLatin1(QByteArray(QByteArrayLiteral("pgp-") + hashAlgo)).toLower()); | 161 | content->contentType()->setParameter(QStringLiteral("micalg"), QString::fromLatin1(QByteArray(QByteArrayLiteral("pgp-") + hashAlgo)).toLower()); |
159 | |||
160 | } else { | ||
161 | content->contentType()->setMimeType(QByteArrayLiteral("multipart/encrypted")); | ||
162 | content->contentType()->setParameter(QStringLiteral("protocol"), QStringLiteral("application/pgp-encrypted")); | ||
163 | } | 162 | } |
164 | return; | 163 | return; |
165 | // case Kleo::SMIMEFormat: | 164 | // case Kleo::SMIMEFormat: |
@@ -187,17 +186,17 @@ void makeToplevelContentType(KMime::Content *content, bool sign, const QByteArra | |||
187 | // } | 186 | // } |
188 | } | 187 | } |
189 | 188 | ||
190 | void setNestedContentType(KMime::Content *content, bool sign) | 189 | void setNestedContentType(KMime::Content *content, bool encrypt) |
191 | { | 190 | { |
192 | // , Kleo::CryptoMessageFormat format | 191 | // , Kleo::CryptoMessageFormat format |
193 | // switch (format) { | 192 | // switch (format) { |
194 | // case Kleo::OpenPGPMIMEFormat: | 193 | // case Kleo::OpenPGPMIMEFormat: |
195 | if (sign) { | 194 | if (encrypt) { |
195 | content->contentType()->setMimeType(QByteArrayLiteral("application/octet-stream")); | ||
196 | } else { | ||
196 | content->contentType()->setMimeType(QByteArrayLiteral("application/pgp-signature")); | 197 | content->contentType()->setMimeType(QByteArrayLiteral("application/pgp-signature")); |
197 | content->contentType()->setParameter(QStringLiteral("name"), QString::fromLatin1("signature.asc")); | 198 | content->contentType()->setParameter(QStringLiteral("name"), QString::fromLatin1("signature.asc")); |
198 | content->contentDescription()->from7BitString("This is a digitally signed message part."); | 199 | content->contentDescription()->from7BitString("This is a digitally signed message part."); |
199 | } else { | ||
200 | content->contentType()->setMimeType(QByteArrayLiteral("application/octet-stream")); | ||
201 | } | 200 | } |
202 | return; | 201 | return; |
203 | // case Kleo::SMIMEFormat: | 202 | // case Kleo::SMIMEFormat: |
@@ -214,11 +213,11 @@ void setNestedContentType(KMime::Content *content, bool sign) | |||
214 | // } | 213 | // } |
215 | } | 214 | } |
216 | 215 | ||
217 | void setNestedContentDisposition(KMime::Content *content, bool sign) | 216 | void setNestedContentDisposition(KMime::Content *content, bool encrypt) |
218 | { | 217 | { |
219 | // Kleo::CryptoMessageFormat format, | 218 | // Kleo::CryptoMessageFormat format, |
220 | // if (!sign && format & Kleo::OpenPGPMIMEFormat) { | 219 | // if (!sign && format & Kleo::OpenPGPMIMEFormat) { |
221 | if (!sign) { | 220 | if (encrypt) { |
222 | content->contentDisposition()->setDisposition(KMime::Headers::CDinline); | 221 | content->contentDisposition()->setDisposition(KMime::Headers::CDinline); |
223 | content->contentDisposition()->setFilename(QStringLiteral("msg.asc")); | 222 | content->contentDisposition()->setFilename(QStringLiteral("msg.asc")); |
224 | // } else if (sign && format & Kleo::SMIMEFormat) { | 223 | // } else if (sign && format & Kleo::SMIMEFormat) { |
@@ -238,7 +237,7 @@ void setNestedContentDisposition(KMime::Content *content, bool sign) | |||
238 | // } | 237 | // } |
239 | // } | 238 | // } |
240 | 239 | ||
241 | KMime::Content *composeHeadersAndBody(KMime::Content *orig, QByteArray encodedBody, bool sign, const QByteArray &hashAlgo) | 240 | KMime::Content *composeHeadersAndBody(KMime::Content *orig, QByteArray encodedBody, bool encrypt, const QByteArray &hashAlgo) |
242 | { | 241 | { |
243 | // Kleo::CryptoMessageFormat format, | 242 | // Kleo::CryptoMessageFormat format, |
244 | KMime::Content *result = new KMime::Content; | 243 | KMime::Content *result = new KMime::Content; |
@@ -248,7 +247,7 @@ KMime::Content *composeHeadersAndBody(KMime::Content *orig, QByteArray encodedBo | |||
248 | 247 | ||
249 | // if (!(format & Kleo::InlineOpenPGPFormat)) { // make a MIME message | 248 | // if (!(format & Kleo::InlineOpenPGPFormat)) { // make a MIME message |
250 | // qDebug() << "making MIME message, format:" << format; | 249 | // qDebug() << "making MIME message, format:" << format; |
251 | makeToplevelContentType(result, sign, hashAlgo); | 250 | makeToplevelContentType(result, encrypt, hashAlgo); |
252 | 251 | ||
253 | // if (makeMultiMime(sign)) { // sign/enc PGPMime, sign SMIME | 252 | // if (makeMultiMime(sign)) { // sign/enc PGPMime, sign SMIME |
254 | if (true) { // sign/enc PGPMime, sign SMIME | 253 | if (true) { // sign/enc PGPMime, sign SMIME |
@@ -263,20 +262,10 @@ KMime::Content *composeHeadersAndBody(KMime::Content *orig, QByteArray encodedBo | |||
263 | // Build a MIME part holding the code information | 262 | // Build a MIME part holding the code information |
264 | // taking the body contents returned in ciphertext. | 263 | // taking the body contents returned in ciphertext. |
265 | KMime::Content *code = new KMime::Content; | 264 | KMime::Content *code = new KMime::Content; |
266 | setNestedContentType(code, sign); | 265 | setNestedContentType(code, encrypt); |
267 | setNestedContentDisposition(code, sign); | 266 | setNestedContentDisposition(code, encrypt); |
268 | 267 | ||
269 | if (sign) { // sign PGPMime, sign SMIME | 268 | if (encrypt) { // enc PGPMime (and or sign) |
270 | // if (format & Kleo::AnySMIME) { // sign SMIME | ||
271 | // code->contentTransferEncoding()->setEncoding(KMime::Headers::CEbase64); | ||
272 | // code->contentTransferEncoding()->needToEncode(); | ||
273 | // code->setBody(encodedBody); | ||
274 | // } else { // sign PGPMmime | ||
275 | setBodyAndCTE(encodedBody, orig->contentType(), code); | ||
276 | // } | ||
277 | result->addContent(orig); | ||
278 | result->addContent(code); | ||
279 | } else { // enc PGPMime | ||
280 | setBodyAndCTE(encodedBody, orig->contentType(), code); | 269 | setBodyAndCTE(encodedBody, orig->contentType(), code); |
281 | 270 | ||
282 | // Build a MIME part holding the version information | 271 | // Build a MIME part holding the version information |
@@ -290,6 +279,16 @@ KMime::Content *composeHeadersAndBody(KMime::Content *orig, QByteArray encodedBo | |||
290 | 279 | ||
291 | result->addContent(vers); | 280 | result->addContent(vers); |
292 | result->addContent(code); | 281 | result->addContent(code); |
282 | } else { // sign PGPMime, sign SMIME | ||
283 | // if (format & Kleo::AnySMIME) { // sign SMIME | ||
284 | // code->contentTransferEncoding()->setEncoding(KMime::Headers::CEbase64); | ||
285 | // code->contentTransferEncoding()->needToEncode(); | ||
286 | // code->setBody(encodedBody); | ||
287 | // } else { // sign PGPMmime | ||
288 | setBodyAndCTE(encodedBody, orig->contentType(), code); | ||
289 | // } | ||
290 | result->addContent(orig); | ||
291 | result->addContent(code); | ||
293 | } | 292 | } |
294 | } else { //enc SMIME, sign/enc SMIMEOpaque | 293 | } else { //enc SMIME, sign/enc SMIMEOpaque |
295 | result->contentTransferEncoding()->setEncoding(KMime::Headers::CEbase64); | 294 | result->contentTransferEncoding()->setEncoding(KMime::Headers::CEbase64); |
@@ -453,7 +452,7 @@ KMime::Content *MailCrypto::processCrypto(KMime::Content *content, const std::ve | |||
453 | return nullptr; | 452 | return nullptr; |
454 | } | 453 | } |
455 | 454 | ||
456 | return composeHeadersAndBody(content, resultContent, sign, hashAlgo); | 455 | return composeHeadersAndBody(content, resultContent, encrypt, hashAlgo); |
457 | } | 456 | } |
458 | 457 | ||
459 | KMime::Content *MailCrypto::sign(KMime::Content *content, const std::vector<GpgME::Key> &signers) | 458 | KMime::Content *MailCrypto::sign(KMime::Content *content, const std::vector<GpgME::Key> &signers) |