Changeset View
Changeset View
Standalone View
Standalone View
messageviewer/src/viewer/messagepart.cpp
Show All 18 Lines | |||||
19 | 19 | | |||
20 | #include "messagepart.h" | 20 | #include "messagepart.h" | ||
21 | #include "messageviewer_debug.h" | 21 | #include "messageviewer_debug.h" | ||
22 | #include <libkleo/importjob.h> | 22 | #include <libkleo/importjob.h> | ||
23 | #include "objecttreeparser.h" | 23 | #include "objecttreeparser.h" | ||
24 | #include "converthtmltoplaintext.h" | 24 | #include "converthtmltoplaintext.h" | ||
25 | #include "htmlquotecolorer.h" | 25 | #include "htmlquotecolorer.h" | ||
26 | #include "csshelper.h" | 26 | #include "csshelper.h" | ||
27 | #include "cryptohelper.h" | ||||
27 | 28 | | |||
28 | #include <MessageCore/StringUtil> | 29 | #include <MessageCore/StringUtil> | ||
29 | 30 | | |||
30 | #include <libkleo/importjob.h> | 31 | #include <libkleo/importjob.h> | ||
32 | #include <libkleo/cryptobackendfactory.h> | ||||
31 | 33 | | |||
32 | #include <interfaces/htmlwriter.h> | 34 | #include <interfaces/htmlwriter.h> | ||
33 | #include <htmlwriter/queuehtmlwriter.h> | 35 | #include <htmlwriter/queuehtmlwriter.h> | ||
34 | #include <job/kleojobexecutor.h> | 36 | #include <job/kleojobexecutor.h> | ||
35 | #include <settings/messageviewersettings.h> | 37 | #include <settings/messageviewersettings.h> | ||
36 | #include <kmime/kmime_content.h> | 38 | #include <kmime/kmime_content.h> | ||
37 | #include <gpgme++/key.h> | 39 | #include <gpgme++/key.h> | ||
38 | #include <gpgme.h> | 40 | #include <gpgme.h> | ||
▲ Show 20 Lines • Show All 298 Lines • ▼ Show 20 Line(s) | 338 | { | |||
337 | if (!mSubOtp) { | 339 | if (!mSubOtp) { | ||
338 | return QString(); | 340 | return QString(); | ||
339 | } | 341 | } | ||
340 | return mSubOtp->plainTextContent(); | 342 | return mSubOtp->plainTextContent(); | ||
341 | } | 343 | } | ||
342 | 344 | | |||
343 | //-----TextMessageBlock---------------------- | 345 | //-----TextMessageBlock---------------------- | ||
344 | 346 | | |||
345 | TextMessagePart::TextMessagePart(ObjectTreeParser* otp, KMime::Content* node, bool drawFrame, bool showLink) | 347 | TextMessagePart::TextMessagePart(ObjectTreeParser* otp, KMime::Content* node, bool drawFrame, bool showLink, bool decryptMessage) | ||
346 | : MessagePart(otp, QString()) | 348 | : MessagePart(otp, QString()) | ||
347 | , mNode(node) | 349 | , mNode(node) | ||
348 | , mDrawFrame(drawFrame) | 350 | , mDrawFrame(drawFrame) | ||
349 | , mShowLink(showLink) | 351 | , mShowLink(showLink) | ||
352 | , mDecryptMessage(decryptMessage) | ||||
350 | { | 353 | { | ||
351 | if (!mNode) { | 354 | if (!mNode) { | ||
352 | qCWarning(MESSAGEVIEWER_LOG) << "not a valid node"; | 355 | qCWarning(MESSAGEVIEWER_LOG) << "not a valid node"; | ||
353 | return; | 356 | return; | ||
354 | } | 357 | } | ||
355 | 358 | parseContent(); | |||
356 | mBlocks = mOtp->writeBodyStr2(mNode->decodedContent(), mOtp->codecFor(mNode), NodeHelper::fromAsString(mNode), mSignatureState, mEncryptionState); | | |||
357 | } | 359 | } | ||
358 | 360 | | |||
359 | TextMessagePart::~TextMessagePart() | 361 | TextMessagePart::~TextMessagePart() | ||
360 | { | 362 | { | ||
361 | 363 | | |||
362 | } | 364 | } | ||
363 | 365 | | |||
366 | bool TextMessagePart::decryptMessage() const | ||||
367 | { | ||||
368 | return mDecryptMessage; | ||||
369 | } | ||||
370 | | ||||
371 | void TextMessagePart::parseContent() | ||||
372 | { | ||||
373 | const auto aCodec = mOtp->codecFor(mNode); | ||||
374 | const QString &fromAddress = NodeHelper::fromAsString(mNode); | ||||
375 | mSignatureState = KMMsgNotSigned; | ||||
376 | mEncryptionState = KMMsgNotEncrypted; | ||||
377 | const auto blocks = prepareMessageForDecryption(mNode->decodedContent()); | ||||
378 | | ||||
379 | const auto cryptProto = Kleo::CryptoBackendFactory::instance()->openpgp(); | ||||
380 | | ||||
381 | if (!blocks.isEmpty()) { | ||||
382 | | ||||
383 | if (blocks.count() > 1 || blocks.at(0).type() != MessageViewer::NoPgpBlock) { | ||||
384 | mOtp->setCryptoProtocol(cryptProto); | ||||
385 | } | ||||
386 | | ||||
387 | | ||||
388 | QString htmlStr; | ||||
389 | QString plainTextStr; | ||||
390 | | ||||
391 | /* The (overall) signature/encrypted status is broken | ||||
392 | * if one unencrypted part is at the beginning or in the middle | ||||
393 | * because mailmain adds an unencrypted part at the end this should not break the overall status | ||||
394 | * | ||||
395 | * That's why we first set the tmp status and if one crypted/signed block comes afterwards, than | ||||
396 | * the status is set to unencryped | ||||
397 | */ | ||||
398 | bool fullySignedOrEncrypted = true; | ||||
399 | bool fullySignedOrEncryptedTmp = true; | ||||
400 | | ||||
401 | Q_FOREACH (const auto &block, blocks) { | ||||
402 | | ||||
403 | if (!fullySignedOrEncryptedTmp) { | ||||
404 | fullySignedOrEncrypted = false; | ||||
405 | } | ||||
406 | | ||||
407 | if (block.type() == NoPgpBlock && !block.text().trimmed().isEmpty()) { | ||||
408 | fullySignedOrEncryptedTmp = false; | ||||
409 | mBlocks.append(MessagePart::Ptr(new MessagePart(mOtp, aCodec->toUnicode(block.text())))); | ||||
410 | } else if (block.type() == PgpMessageBlock) { | ||||
411 | CryptoMessagePart::Ptr mp(new CryptoMessagePart(mOtp, QString(), cryptProto, fromAddress, 0)); | ||||
412 | mBlocks.append(mp); | ||||
413 | if (!decryptMessage()) { | ||||
414 | continue; | ||||
415 | } | ||||
416 | mp->startDecryption(block.text(), aCodec); | ||||
417 | if (mp->partMetaData()->inProgress) { | ||||
418 | continue; | ||||
419 | } | ||||
420 | } else if (block.type() == ClearsignedBlock) { | ||||
421 | CryptoMessagePart::Ptr mp(new CryptoMessagePart(mOtp, QString(), cryptProto, fromAddress, 0)); | ||||
422 | mBlocks.append(mp); | ||||
423 | mp->startVerification(block.text(), aCodec); | ||||
424 | } else { | ||||
425 | continue; | ||||
426 | } | ||||
427 | | ||||
428 | const PartMetaData *messagePart(mBlocks.last()->partMetaData()); | ||||
429 | | ||||
430 | if (!messagePart->isEncrypted && !messagePart->isSigned && !block.text().trimmed().isEmpty()) { | ||||
431 | mBlocks.last()->setText(aCodec->toUnicode(block.text())); | ||||
432 | } | ||||
433 | | ||||
434 | if (messagePart->isEncrypted) { | ||||
435 | mEncryptionState = KMMsgPartiallyEncrypted; | ||||
436 | } | ||||
437 | | ||||
438 | if (messagePart->isSigned) { | ||||
439 | mSignatureState = KMMsgPartiallySigned; | ||||
440 | } | ||||
441 | } | ||||
442 | | ||||
443 | //Do we have an fully Signed/Encrypted Message? | ||||
444 | if (fullySignedOrEncrypted) { | ||||
445 | if (mSignatureState == KMMsgPartiallySigned) { | ||||
446 | mSignatureState = KMMsgFullySigned; | ||||
447 | } | ||||
448 | if (mEncryptionState == KMMsgPartiallyEncrypted) { | ||||
449 | mEncryptionState = KMMsgFullyEncrypted; | ||||
450 | } | ||||
451 | } | ||||
452 | } | ||||
453 | } | ||||
454 | | ||||
364 | void TextMessagePart::html(bool decorate) | 455 | void TextMessagePart::html(bool decorate) | ||
365 | { | 456 | { | ||
366 | HTMLBlock::Ptr block; | 457 | HTMLBlock::Ptr block; | ||
367 | MessageViewer::HtmlWriter *writer = mOtp->htmlWriter(); | 458 | MessageViewer::HtmlWriter *writer = mOtp->htmlWriter(); | ||
368 | if (mDrawFrame) { | 459 | if (mDrawFrame) { | ||
369 | block = HTMLBlock::Ptr(new TextBlock(writer, mOtp->nodeHelper(), mNode, mShowLink)); | 460 | block = HTMLBlock::Ptr(new TextBlock(writer, mOtp->nodeHelper(), mNode, mShowLink)); | ||
370 | } | 461 | } | ||
371 | 462 | | |||
▲ Show 20 Lines • Show All 532 Lines • Show Last 20 Lines |