Changeset View
Changeset View
Standalone View
Standalone View
messageviewer/src/viewer/objecttreeparser.cpp
Show First 20 Lines • Show All 349 Lines • ▼ Show 20 Line(s) | 340 | if (const Interface::BodyPartFormatter * formatter | |||
---|---|---|---|---|---|
350 | QObject *asyncResultObserver = allowAsync() ? mSource->sourceObject() : 0; | 350 | QObject *asyncResultObserver = allowAsync() ? mSource->sourceObject() : 0; | ||
351 | const Interface::BodyPartFormatter::Result result = formatter->format(&part, htmlWriter(), asyncResultObserver); | 351 | const Interface::BodyPartFormatter::Result result = formatter->format(&part, htmlWriter(), asyncResultObserver); | ||
352 | switch (result) { | 352 | switch (result) { | ||
353 | case Interface::BodyPartFormatter::AsIcon: | 353 | case Interface::BodyPartFormatter::AsIcon: | ||
354 | processResult.setNeverDisplayInline(true); | 354 | processResult.setNeverDisplayInline(true); | ||
355 | mNodeHelper->setNodeDisplayedEmbedded(node, false); | 355 | mNodeHelper->setNodeDisplayedEmbedded(node, false); | ||
356 | // fall through: | 356 | // fall through: | ||
357 | case Interface::BodyPartFormatter::Failed: | 357 | case Interface::BodyPartFormatter::Failed: | ||
358 | defaultHandling(node, processResult); | 358 | { | ||
359 | const auto mp = defaultHandling(node, processResult); | ||||
360 | if (mp) { | ||||
361 | mp->html(false); | ||||
362 | } | ||||
359 | break; | 363 | break; | ||
364 | } | ||||
360 | case Interface::BodyPartFormatter::Ok: | 365 | case Interface::BodyPartFormatter::Ok: | ||
361 | case Interface::BodyPartFormatter::NeedContent: | 366 | case Interface::BodyPartFormatter::NeedContent: | ||
362 | // FIXME: incomplete content handling | 367 | // FIXME: incomplete content handling | ||
363 | ; | 368 | ; | ||
364 | } | 369 | } | ||
365 | 370 | | |||
366 | // No external plugin can handle the MIME part, handle it internally | 371 | // No external plugin can handle the MIME part, handle it internally | ||
367 | } else { | 372 | } else { | ||
368 | qCCritical(MESSAGEVIEWER_LOG) << "THIS SHOULD NO LONGER HAPPEN:" << mediaType << '/' << subType; | 373 | qCCritical(MESSAGEVIEWER_LOG) << "THIS SHOULD NO LONGER HAPPEN:" << mediaType << '/' << subType; | ||
369 | AttachmentMarkBlock block(htmlWriter(), node); | 374 | AttachmentMarkBlock block(htmlWriter(), node); | ||
370 | defaultHandling(node, processResult); | 375 | const auto mp = defaultHandling(node, processResult); | ||
376 | if (mp) { | ||||
377 | mp->html(false); | ||||
378 | } | ||||
371 | } | 379 | } | ||
372 | mNodeHelper->setNodeProcessed(node, false); | 380 | mNodeHelper->setNodeProcessed(node, false); | ||
373 | 381 | | |||
374 | // adjust signed/encrypted flags if inline PGP was found | 382 | // adjust signed/encrypted flags if inline PGP was found | ||
375 | processResult.adjustCryptoStatesOfNode(node); | 383 | processResult.adjustCryptoStatesOfNode(node); | ||
376 | 384 | | |||
377 | if (showOnlyOneMimePart()) { | 385 | if (showOnlyOneMimePart()) { | ||
378 | break; | 386 | break; | ||
379 | } | 387 | } | ||
380 | } | 388 | } | ||
381 | 389 | | |||
382 | if (isRoot && htmlWriter()) { | 390 | if (isRoot && htmlWriter()) { | ||
383 | htmlWriter()->queue(QStringLiteral("</div>\n")); | 391 | htmlWriter()->queue(QStringLiteral("</div>\n")); | ||
384 | } | 392 | } | ||
385 | } | 393 | } | ||
386 | 394 | | |||
387 | void ObjectTreeParser::defaultHandling(KMime::Content *node, ProcessResult &result) | 395 | MessagePart::Ptr ObjectTreeParser::defaultHandling(KMime::Content *node, ProcessResult &result) | ||
388 | { | 396 | { | ||
389 | // ### (mmutz) default handling should go into the respective | 397 | // ### (mmutz) default handling should go into the respective | ||
390 | // ### bodypartformatters. | 398 | // ### bodypartformatters. | ||
391 | if (!htmlWriter()) { | 399 | if (!htmlWriter()) { | ||
392 | qCWarning(MESSAGEVIEWER_LOG) << "no htmlWriter()"; | 400 | qCWarning(MESSAGEVIEWER_LOG) << "no htmlWriter()"; | ||
393 | return; | 401 | return MessagePart::Ptr(); | ||
394 | } | 402 | } | ||
395 | 403 | | |||
396 | // always show images in multipart/related when showing in html, not with an additional icon | 404 | // always show images in multipart/related when showing in html, not with an additional icon | ||
397 | if (result.isImage() && node->parent() && | 405 | if (result.isImage() && node->parent() && | ||
398 | node->parent()->contentType()->subType() == "related" && mSource->htmlMail() && !showOnlyOneMimePart()) { | 406 | node->parent()->contentType()->subType() == "related" && mSource->htmlMail() && !showOnlyOneMimePart()) { | ||
399 | QString fileName = mNodeHelper->writeNodeToTempFile(node); | 407 | QString fileName = mNodeHelper->writeNodeToTempFile(node); | ||
400 | QString href = QLatin1String("file:///") + fileName; | 408 | QString href = QLatin1String("file:///") + fileName; | ||
401 | QByteArray cid = node->contentID()->identifier(); | 409 | QByteArray cid = node->contentID()->identifier(); | ||
402 | htmlWriter()->embedPart(cid, href); | 410 | htmlWriter()->embedPart(cid, href); | ||
403 | nodeHelper()->setNodeDisplayedEmbedded(node, true); | 411 | nodeHelper()->setNodeDisplayedEmbedded(node, true); | ||
404 | return; | 412 | return MessagePart::Ptr(); | ||
405 | } | 413 | } | ||
406 | 414 | MessagePart::Ptr mp; | |||
407 | if (node->contentType()->mimeType() == QByteArray("application/octet-stream") && | 415 | if (node->contentType()->mimeType() == QByteArray("application/octet-stream") && | ||
408 | (node->contentType()->name().endsWith(QLatin1String("p7m")) || | 416 | (node->contentType()->name().endsWith(QLatin1String("p7m")) || | ||
409 | node->contentType()->name().endsWith(QLatin1String("p7s")) || | 417 | node->contentType()->name().endsWith(QLatin1String("p7s")) || | ||
410 | node->contentType()->name().endsWith(QLatin1String("p7c")) | 418 | node->contentType()->name().endsWith(QLatin1String("p7c")) | ||
411 | ) && | 419 | ) && | ||
412 | processApplicationPkcs7MimeSubtype(node, result)) { | 420 | (mp = processApplicationPkcs7MimeSubtype(node, result))) { | ||
413 | return; | 421 | return mp; | ||
414 | } | 422 | } | ||
415 | 423 | | |||
416 | const AttachmentStrategy *const as = attachmentStrategy(); | 424 | const AttachmentStrategy *const as = attachmentStrategy(); | ||
417 | if (as && as->defaultDisplay(node) == AttachmentStrategy::None && | 425 | if (as && as->defaultDisplay(node) == AttachmentStrategy::None && | ||
418 | !showOnlyOneMimePart() && | 426 | !showOnlyOneMimePart() && | ||
419 | node->parent() /* message is not an attachment */) { | 427 | node->parent() /* message is not an attachment */) { | ||
420 | mNodeHelper->setNodeDisplayedHidden(node, true); | 428 | mNodeHelper->setNodeDisplayedHidden(node, true); | ||
421 | return; | 429 | return MessagePart::Ptr(); | ||
422 | } | 430 | } | ||
423 | 431 | | |||
424 | bool asIcon = true; | 432 | bool asIcon = true; | ||
425 | if (!result.neverDisplayInline()) | 433 | if (!result.neverDisplayInline()) | ||
426 | if (as) { | 434 | if (as) { | ||
427 | asIcon = as->defaultDisplay(node) == AttachmentStrategy::AsIcon; | 435 | asIcon = as->defaultDisplay(node) == AttachmentStrategy::AsIcon; | ||
428 | } | 436 | } | ||
429 | 437 | | |||
Show All 24 Lines | 461 | } else { | |||
454 | mNodeHelper->setNodeDisplayedHidden(node, true); | 462 | mNodeHelper->setNodeDisplayedHidden(node, true); | ||
455 | } | 463 | } | ||
456 | } else if (result.isImage()) { | 464 | } else if (result.isImage()) { | ||
457 | // Embed the image | 465 | // Embed the image | ||
458 | mNodeHelper->setNodeDisplayedEmbedded(node, true); | 466 | mNodeHelper->setNodeDisplayedEmbedded(node, true); | ||
459 | writePartIcon(node, true); | 467 | writePartIcon(node, true); | ||
460 | } else { | 468 | } else { | ||
461 | mNodeHelper->setNodeDisplayedEmbedded(node, true); | 469 | mNodeHelper->setNodeDisplayedEmbedded(node, true); | ||
462 | writeBodyString(node->decodedContent(), | 470 | const auto mp = TextMessagePart::Ptr(new TextMessagePart(this, node, false, false)); | ||
463 | NodeHelper::fromAsString(node), | 471 | result.setInlineSignatureState(mp->signatureState()); | ||
464 | codecFor(node), result, false); | 472 | result.setInlineEncryptionState(mp->encryptionState()); | ||
473 | return mp; | ||||
465 | } | 474 | } | ||
466 | // end of ### | 475 | return MessagePart::Ptr(); | ||
467 | } | 476 | } | ||
468 | 477 | | |||
469 | KMMsgSignatureState ProcessResult::inlineSignatureState() const | 478 | KMMsgSignatureState ProcessResult::inlineSignatureState() const | ||
470 | { | 479 | { | ||
471 | return mInlineSignatureState; | 480 | return mInlineSignatureState; | ||
472 | } | 481 | } | ||
473 | 482 | | |||
474 | void ProcessResult::setInlineSignatureState(KMMsgSignatureState state) | 483 | void ProcessResult::setInlineSignatureState(KMMsgSignatureState state) | ||
▲ Show 20 Lines • Show All 267 Lines • ▼ Show 20 Line(s) | 735 | if (!cryptProto) { | |||
742 | } | 751 | } | ||
743 | } | 752 | } | ||
744 | 753 | | |||
745 | dumpToFile("dat_05_reader.decrypted", decryptedData.data(), decryptedData.size()); | 754 | dumpToFile("dat_05_reader.decrypted", decryptedData.data(), decryptedData.size()); | ||
746 | 755 | | |||
747 | return bDecryptionOk; | 756 | return bDecryptionOk; | ||
748 | } | 757 | } | ||
749 | 758 | | |||
750 | bool ObjectTreeParser::processTextHtmlSubtype(KMime::Content *curNode, ProcessResult &) | 759 | MessagePart::Ptr ObjectTreeParser::processTextHtmlSubtype(KMime::Content *curNode, ProcessResult &) | ||
751 | { | 760 | { | ||
752 | HtmlMessagePart mp(this, curNode, mSource); | 761 | HtmlMessagePart::Ptr mp(new HtmlMessagePart(this, curNode, mSource)); | ||
753 | 762 | | |||
754 | if (curNode->topLevel()->textContent() == curNode || attachmentStrategy()->defaultDisplay(curNode) == AttachmentStrategy::Inline || | 763 | if (curNode->topLevel()->textContent() == curNode || attachmentStrategy()->defaultDisplay(curNode) == AttachmentStrategy::Inline || | ||
755 | showOnlyOneMimePart()) { | 764 | showOnlyOneMimePart()) { | ||
756 | mp.html(false); | | |||
757 | return true; | | |||
758 | } else { | 765 | } else { | ||
759 | // we need the copy of htmlcontent and charset in anycase for the current design of otp. | 766 | // we need the copy of htmlcontent and charset in anycase for the current design of otp. | ||
760 | //Should be not neeed if otp don't hold any status anymore | 767 | //Should be not neeed if otp don't hold any status anymore | ||
761 | mp.fix(); | 768 | mp->fix(); | ||
762 | return false; | 769 | | ||
763 | } | 770 | } | ||
771 | return mp; | ||||
764 | } | 772 | } | ||
765 | 773 | | |||
766 | bool ObjectTreeParser::isMailmanMessage(KMime::Content *curNode) | 774 | bool ObjectTreeParser::isMailmanMessage(KMime::Content *curNode) | ||
767 | { | 775 | { | ||
768 | if (!curNode || curNode->head().isEmpty()) { | 776 | if (!curNode || curNode->head().isEmpty()) { | ||
769 | return false; | 777 | return false; | ||
770 | } | 778 | } | ||
771 | if (curNode->hasHeader("X-Mailman-Version")) { | 779 | if (curNode->hasHeader("X-Mailman-Version")) { | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | |||||
891 | void ObjectTreeParser::extractNodeInfos(KMime::Content *curNode, bool isFirstTextPart) | 899 | void ObjectTreeParser::extractNodeInfos(KMime::Content *curNode, bool isFirstTextPart) | ||
892 | { | 900 | { | ||
893 | if (isFirstTextPart) { | 901 | if (isFirstTextPart) { | ||
894 | mPlainTextContent += curNode->decodedText(); | 902 | mPlainTextContent += curNode->decodedText(); | ||
895 | mPlainTextContentCharset += NodeHelper::charset(curNode); | 903 | mPlainTextContentCharset += NodeHelper::charset(curNode); | ||
896 | } | 904 | } | ||
897 | } | 905 | } | ||
898 | 906 | | |||
899 | bool ObjectTreeParser::processTextPlainSubtype(KMime::Content *curNode, ProcessResult &result) | 907 | MessagePart::Ptr ObjectTreeParser::processTextPlainSubtype(KMime::Content *curNode, ProcessResult &result) | ||
900 | { | 908 | { | ||
901 | const bool isFirstTextPart = (curNode->topLevel()->textContent() == curNode); | 909 | const bool isFirstTextPart = (curNode->topLevel()->textContent() == curNode); | ||
902 | 910 | | |||
903 | if (!isFirstTextPart && attachmentStrategy()->defaultDisplay(curNode) != AttachmentStrategy::Inline && | 911 | if (!isFirstTextPart && attachmentStrategy()->defaultDisplay(curNode) != AttachmentStrategy::Inline && | ||
904 | !showOnlyOneMimePart()) { | 912 | !showOnlyOneMimePart()) { | ||
905 | return false; | 913 | return MessagePart::Ptr(); | ||
906 | } | 914 | } | ||
907 | 915 | | |||
908 | extractNodeInfos(curNode, isFirstTextPart); | 916 | extractNodeInfos(curNode, isFirstTextPart); | ||
909 | 917 | | |||
910 | QString label = NodeHelper::fileName(curNode); | 918 | QString label = NodeHelper::fileName(curNode); | ||
911 | 919 | | |||
912 | const bool bDrawFrame = !isFirstTextPart | 920 | const bool bDrawFrame = !isFirstTextPart | ||
913 | && !showOnlyOneMimePart() | 921 | && !showOnlyOneMimePart() | ||
914 | && !label.isEmpty(); | 922 | && !label.isEmpty(); | ||
915 | const QString fileName = mNodeHelper->writeNodeToTempFile(curNode); | 923 | const QString fileName = mNodeHelper->writeNodeToTempFile(curNode); | ||
916 | 924 | | |||
917 | // process old style not-multipart Mailman messages to | 925 | // process old style not-multipart Mailman messages to | ||
918 | // enable verification of the embedded messages' signatures | 926 | // enable verification of the embedded messages' signatures | ||
919 | if (!isMailmanMessage(curNode) || | 927 | //if (!isMailmanMessage(curNode) || | ||
920 | !processMailmanMessage(curNode)) { | 928 | // !processMailmanMessage(curNode)) { | ||
vkrause: intentionally commented out code? | |||||
Yepp this is intentenally. knauss: Yepp this is intentenally.
It is a bahaviour change at the moment, but I have already… | |||||
921 | 929 | | |||
922 | TextMessagePart mp(this, curNode, bDrawFrame, !fileName.isEmpty()); | 930 | TextMessagePart::Ptr mp(new TextMessagePart(this, curNode, bDrawFrame, !fileName.isEmpty())); | ||
923 | mp.html(!bDrawFrame); | | |||
924 | 931 | | |||
925 | result.setInlineSignatureState(mp.signatureState()); | 932 | result.setInlineSignatureState(mp->signatureState()); | ||
926 | result.setInlineEncryptionState(mp.encryptionState()); | 933 | result.setInlineEncryptionState(mp->encryptionState()); | ||
927 | 934 | | |||
928 | if (isFirstTextPart) { | 935 | if (isFirstTextPart) { | ||
929 | mPlainTextContent = mp.text(); | 936 | mPlainTextContent = mp->text(); | ||
930 | } | 937 | } | ||
931 | 938 | | |||
932 | mNodeHelper->setNodeDisplayedEmbedded(curNode, true); | 939 | mNodeHelper->setNodeDisplayedEmbedded(curNode, true); | ||
933 | } | 940 | //} | ||
934 | return true; | 941 | | ||
942 | return mp; | ||||
935 | } | 943 | } | ||
936 | 944 | | |||
937 | void ObjectTreeParser::standardChildHandling(KMime::Content *child) | 945 | void ObjectTreeParser::standardChildHandling(KMime::Content *child) | ||
938 | { | 946 | { | ||
939 | if (!child) { | 947 | if (!child) { | ||
940 | return; | 948 | return; | ||
941 | } | 949 | } | ||
942 | 950 | | |||
943 | MimeMessagePart mp(this, child, false); | 951 | MimeMessagePart mp(this, child, false); | ||
944 | mp.html(false); | 952 | mp.html(false); | ||
945 | } | 953 | } | ||
946 | 954 | | |||
947 | bool ObjectTreeParser::processMultiPartMixedSubtype(KMime::Content *node, ProcessResult &) | 955 | MessagePart::Ptr ObjectTreeParser::processMultiPartMixedSubtype(KMime::Content *node, ProcessResult &) | ||
948 | { | 956 | { | ||
949 | KMime::Content *child = MessageCore::NodeHelper::firstChild(node); | 957 | KMime::Content *child = MessageCore::NodeHelper::firstChild(node); | ||
950 | if (!child) { | 958 | if (!child) { | ||
951 | return false; | 959 | return MessagePart::Ptr(); | ||
952 | } | 960 | } | ||
953 | 961 | | |||
954 | // normal treatment of the parts in the mp/mixed container | 962 | // normal treatment of the parts in the mp/mixed container | ||
955 | MimeMessagePart mp(this, child, false); | 963 | MimeMessagePart::Ptr mp(new MimeMessagePart(this, child, false)); | ||
956 | mp.html(false); | 964 | return mp; | ||
957 | return true; | | |||
958 | } | 965 | } | ||
959 | 966 | | |||
960 | bool ObjectTreeParser::processMultiPartAlternativeSubtype(KMime::Content *node, ProcessResult &) | 967 | MessagePart::Ptr ObjectTreeParser::processMultiPartAlternativeSubtype(KMime::Content *node, ProcessResult &) | ||
961 | { | 968 | { | ||
962 | KMime::Content *child = MessageCore::NodeHelper::firstChild(node); | 969 | KMime::Content *child = MessageCore::NodeHelper::firstChild(node); | ||
963 | if (!child) { | 970 | if (!child) { | ||
964 | return false; | 971 | return MessagePart::Ptr(); | ||
965 | } | 972 | } | ||
966 | 973 | | |||
967 | KMime::Content *dataHtml = findType(child, "text/html", false, true); | 974 | KMime::Content *dataHtml = findType(child, "text/html", false, true); | ||
968 | KMime::Content *dataPlain = findType(child, "text/plain", false, true); | 975 | KMime::Content *dataPlain = findType(child, "text/plain", false, true); | ||
969 | 976 | | |||
970 | if (!dataHtml) { | 977 | if (!dataHtml) { | ||
971 | // If we didn't find the HTML part as the first child of the multipart/alternative, it might | 978 | // If we didn't find the HTML part as the first child of the multipart/alternative, it might | ||
972 | // be that this is a HTML message with images, and text/plain and multipart/related are the | 979 | // be that this is a HTML message with images, and text/plain and multipart/related are the | ||
973 | // immediate children of this multipart/alternative node. | 980 | // immediate children of this multipart/alternative node. | ||
974 | // In this case, the HTML node is a child of multipart/related. | 981 | // In this case, the HTML node is a child of multipart/related. | ||
975 | dataHtml = findType(child, "multipart/related", false, true); | 982 | dataHtml = findType(child, "multipart/related", false, true); | ||
976 | 983 | | |||
977 | // Still not found? Stupid apple mail actually puts the attachments inside of the | 984 | // Still not found? Stupid apple mail actually puts the attachments inside of the | ||
978 | // multipart/alternative, which is wrong. Therefore we also have to look for multipart/mixed | 985 | // multipart/alternative, which is wrong. Therefore we also have to look for multipart/mixed | ||
979 | // here. | 986 | // here. | ||
980 | // Do this only when prefering HTML mail, though, since otherwise the attachments are hidden | 987 | // Do this only when prefering HTML mail, though, since otherwise the attachments are hidden | ||
981 | // when displaying plain text. | 988 | // when displaying plain text. | ||
982 | if (!dataHtml && mSource->htmlMail()) { | 989 | if (!dataHtml && mSource->htmlMail()) { | ||
983 | dataHtml = findType(child, "multipart/mixed", false, true); | 990 | dataHtml = findType(child, "multipart/mixed", false, true); | ||
984 | } | 991 | } | ||
985 | } | 992 | } | ||
986 | 993 | | |||
987 | if (dataPlain || dataHtml) { | 994 | if (dataPlain || dataHtml) { | ||
988 | AlternativeMessagePart mp(this, dataPlain, dataHtml); | 995 | AlternativeMessagePart::Ptr mp(new AlternativeMessagePart(this, dataPlain, dataHtml)); | ||
989 | 996 | | |||
990 | if ((mSource->htmlMail() && dataHtml) || | 997 | if ((mSource->htmlMail() && dataHtml) || | ||
991 | (dataHtml && dataPlain && dataPlain->body().isEmpty())) { | 998 | (dataHtml && dataPlain && dataPlain->body().isEmpty())) { | ||
992 | if (dataPlain) { | 999 | if (dataPlain) { | ||
993 | mNodeHelper->setNodeProcessed(dataPlain, false); | 1000 | mNodeHelper->setNodeProcessed(dataPlain, false); | ||
994 | } | 1001 | } | ||
995 | mSource->setHtmlMode(Util::MultipartHtml); | 1002 | mSource->setHtmlMode(Util::MultipartHtml); | ||
996 | mp.setViewHtml(true); | 1003 | mp->setViewHtml(true); | ||
997 | mp.html(false); | | |||
998 | return true; | | |||
999 | } | 1004 | } | ||
1000 | 1005 | | |||
1001 | if (!mSource->htmlMail() && dataPlain) { | 1006 | if (!mSource->htmlMail() && dataPlain) { | ||
1002 | mNodeHelper->setNodeProcessed(dataHtml, false); | 1007 | mNodeHelper->setNodeProcessed(dataHtml, false); | ||
1003 | mSource->setHtmlMode(Util::MultipartPlain); | 1008 | mSource->setHtmlMode(Util::MultipartPlain); | ||
1004 | mp.setViewHtml(false); | 1009 | mp->setViewHtml(false); | ||
1005 | mp.html(false); | | |||
1006 | return true; | | |||
1007 | } | 1010 | } | ||
1011 | return mp; | ||||
1008 | } | 1012 | } | ||
1009 | 1013 | | |||
1010 | MimeMessagePart mp(this, child, false); | 1014 | MimeMessagePart::Ptr mp(new MimeMessagePart(this, child, false)); | ||
1011 | mp.html(false); | 1015 | return mp; | ||
1012 | return true; | | |||
1013 | } | 1016 | } | ||
1014 | 1017 | | |||
1015 | MessagePart::Ptr ObjectTreeParser::processMultiPartSignedSubtype(KMime::Content *node, ProcessResult &) | 1018 | MessagePart::Ptr ObjectTreeParser::processMultiPartSignedSubtype(KMime::Content *node, ProcessResult &) | ||
1016 | { | 1019 | { | ||
1017 | KMime::Content *signedData = MessageCore::NodeHelper::firstChild(node); | 1020 | KMime::Content *signedData = MessageCore::NodeHelper::firstChild(node); | ||
1018 | assert(signedData); | 1021 | assert(signedData); | ||
1019 | if (node->contents().size() != 2) { | 1022 | if (node->contents().size() != 2) { | ||
1020 | qCDebug(MESSAGEVIEWER_LOG) << "mulitpart/signed must have exactly two child parts!" << endl | 1023 | qCDebug(MESSAGEVIEWER_LOG) << "mulitpart/signed must have exactly two child parts!" << endl | ||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Line(s) | 1134 | if (messagePart->isDecryptable && messagePart->isSigned) { | |||
1143 | mNodeHelper->setSignatureState(node, KMMsgFullySigned); | 1146 | mNodeHelper->setSignatureState(node, KMMsgFullySigned); | ||
1144 | qCDebug(MESSAGEVIEWER_LOG) << "setting FULLY SIGNED to:" << node; | 1147 | qCDebug(MESSAGEVIEWER_LOG) << "setting FULLY SIGNED to:" << node; | ||
1145 | } | 1148 | } | ||
1146 | } | 1149 | } | ||
1147 | } | 1150 | } | ||
1148 | return mp; | 1151 | return mp; | ||
1149 | } | 1152 | } | ||
1150 | 1153 | | |||
1151 | bool ObjectTreeParser::processApplicationPkcs7MimeSubtype(KMime::Content *node, ProcessResult &result) | 1154 | MessagePart::Ptr ObjectTreeParser::processApplicationPkcs7MimeSubtype(KMime::Content *node, ProcessResult &result) | ||
1152 | { | 1155 | { | ||
1153 | if (node->head().isEmpty()) { | 1156 | if (node->head().isEmpty()) { | ||
1154 | return false; | 1157 | return MessagePart::Ptr(); | ||
1155 | } | 1158 | } | ||
1156 | 1159 | | |||
1157 | const Kleo::CryptoBackend::Protocol *smimeCrypto = Kleo::CryptoBackendFactory::instance()->smime(); | 1160 | const Kleo::CryptoBackend::Protocol *smimeCrypto = Kleo::CryptoBackendFactory::instance()->smime(); | ||
1158 | if (!smimeCrypto) { | 1161 | if (!smimeCrypto) { | ||
1159 | return false; | 1162 | return MessagePart::Ptr(); | ||
1160 | } | 1163 | } | ||
1161 | 1164 | | |||
1162 | const QString smimeType = node->contentType()->parameter(QStringLiteral("smime-type")).toLower(); | 1165 | const QString smimeType = node->contentType()->parameter(QStringLiteral("smime-type")).toLower(); | ||
1163 | 1166 | | |||
1164 | if (smimeType == QLatin1String("certs-only")) { | 1167 | if (smimeType == QLatin1String("certs-only")) { | ||
1165 | result.setNeverDisplayInline(true); | 1168 | result.setNeverDisplayInline(true); | ||
1166 | 1169 | | |||
1167 | CertMessagePart mp(this, node, smimeCrypto, MessageViewer::MessageViewerSettings::self()->autoImportKeys()); | 1170 | CertMessagePart::Ptr mp(new CertMessagePart(this, node, smimeCrypto, MessageViewer::MessageViewerSettings::self()->autoImportKeys())); | ||
1168 | mp.html(true); | 1171 | return mp; | ||
1169 | return true; | | |||
1170 | } | 1172 | } | ||
1171 | 1173 | | |||
1172 | CryptoProtocolSaver cpws(this, smimeCrypto); | 1174 | CryptoProtocolSaver cpws(this, smimeCrypto); | ||
1173 | 1175 | | |||
1174 | bool isSigned = (smimeType == QLatin1String("signed-data")); | 1176 | bool isSigned = (smimeType == QLatin1String("signed-data")); | ||
1175 | bool isEncrypted = (smimeType == QLatin1String("enveloped-data")); | 1177 | bool isEncrypted = (smimeType == QLatin1String("enveloped-data")); | ||
1176 | 1178 | | |||
1177 | // Analyze "signTestNode" node to find/verify a signature. | 1179 | // Analyze "signTestNode" node to find/verify a signature. | ||
1178 | // If zero this verification was successfully done after | 1180 | // If zero this verification was successfully done after | ||
1179 | // decrypting via recursion by insertAndParseNewChildNode(). | 1181 | // decrypting via recursion by insertAndParseNewChildNode(). | ||
1180 | KMime::Content *signTestNode = isEncrypted ? 0 : node; | 1182 | KMime::Content *signTestNode = isEncrypted ? 0 : node; | ||
1181 | 1183 | | |||
1182 | // We try decrypting the content | 1184 | // We try decrypting the content | ||
1183 | // if we either *know* that it is an encrypted message part | 1185 | // if we either *know* that it is an encrypted message part | ||
1184 | // or there is neither signed nor encrypted parameter. | 1186 | // or there is neither signed nor encrypted parameter. | ||
1187 | CryptoMessagePart::Ptr mp; | ||||
1185 | if (!isSigned) { | 1188 | if (!isSigned) { | ||
1186 | if (isEncrypted) { | 1189 | if (isEncrypted) { | ||
1187 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime == S/MIME TYPE: enveloped (encrypted) data"; | 1190 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime == S/MIME TYPE: enveloped (encrypted) data"; | ||
1188 | } else { | 1191 | } else { | ||
1189 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - type unknown - enveloped (encrypted) data ?"; | 1192 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - type unknown - enveloped (encrypted) data ?"; | ||
1190 | } | 1193 | } | ||
1191 | 1194 | | |||
1192 | CryptoMessagePart mp(this, | 1195 | mp = CryptoMessagePart::Ptr(new CryptoMessagePart(this, | ||
1193 | node->decodedText(), cryptoProtocol(), | 1196 | node->decodedText(), cryptoProtocol(), | ||
1194 | NodeHelper::fromAsString(node), node); | 1197 | NodeHelper::fromAsString(node), node)); | ||
1195 | 1198 | | |||
1196 | PartMetaData *messagePart(mp.partMetaData()); | 1199 | PartMetaData *messagePart(mp->partMetaData()); | ||
1197 | if (!mSource->decryptMessage()) { | 1200 | if (!mSource->decryptMessage()) { | ||
1198 | isEncrypted = true; | 1201 | isEncrypted = true; | ||
1199 | signTestNode = 0; // PENDING(marc) to be abs. sure, we'd need to have to look at the content | 1202 | signTestNode = 0; // PENDING(marc) to be abs. sure, we'd need to have to look at the content | ||
1200 | } else { | 1203 | } else { | ||
1201 | mp.startDecryption(); | 1204 | mp->startDecryption(); | ||
1202 | if (messagePart->isDecryptable) { | 1205 | if (messagePart->isDecryptable) { | ||
1203 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - encryption found - enveloped (encrypted) data !"; | 1206 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - encryption found - enveloped (encrypted) data !"; | ||
1204 | isEncrypted = true; | 1207 | isEncrypted = true; | ||
1205 | mNodeHelper->setEncryptionState(node, KMMsgFullyEncrypted); | 1208 | mNodeHelper->setEncryptionState(node, KMMsgFullyEncrypted); | ||
1206 | if (messagePart->isSigned) { | 1209 | if (messagePart->isSigned) { | ||
1207 | mNodeHelper->setSignatureState(node, KMMsgFullySigned); | 1210 | mNodeHelper->setSignatureState(node, KMMsgFullySigned); | ||
1208 | } | 1211 | } | ||
1209 | signTestNode = 0; | 1212 | signTestNode = 0; | ||
1210 | 1213 | | |||
1211 | } else { | 1214 | } else { | ||
1212 | // decryption failed, which could be because the part was encrypted but | 1215 | // decryption failed, which could be because the part was encrypted but | ||
1213 | // decryption failed, or because we didn't know if it was encrypted, tried, | 1216 | // decryption failed, or because we didn't know if it was encrypted, tried, | ||
1214 | // and failed. If the message was not actually encrypted, we continue | 1217 | // and failed. If the message was not actually encrypted, we continue | ||
1215 | // assuming it's signed | 1218 | // assuming it's signed | ||
1216 | if (mp.mPassphraseError || (smimeType.isEmpty() && messagePart->isEncrypted)) { | 1219 | if (mp->mPassphraseError || (smimeType.isEmpty() && messagePart->isEncrypted)) { | ||
1217 | isEncrypted = true; | 1220 | isEncrypted = true; | ||
1218 | signTestNode = 0; | 1221 | signTestNode = 0; | ||
1219 | } | 1222 | } | ||
1220 | 1223 | | |||
1221 | if (isEncrypted) { | 1224 | if (isEncrypted) { | ||
1222 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - ERROR: COULD NOT DECRYPT enveloped data !"; | 1225 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - ERROR: COULD NOT DECRYPT enveloped data !"; | ||
1223 | } else { | 1226 | } else { | ||
1224 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - NO encryption found"; | 1227 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - NO encryption found"; | ||
1225 | } | 1228 | } | ||
1226 | } | 1229 | } | ||
1227 | } | 1230 | } | ||
1228 | mp.html(false); | | |||
1229 | 1231 | | |||
1230 | if (isEncrypted) { | 1232 | if (isEncrypted) { | ||
1231 | mNodeHelper->setEncryptionState(node, KMMsgFullyEncrypted); | 1233 | mNodeHelper->setEncryptionState(node, KMMsgFullyEncrypted); | ||
1232 | } | 1234 | } | ||
1233 | } | 1235 | } | ||
1234 | 1236 | | |||
1235 | // We now try signature verification if necessarry. | 1237 | // We now try signature verification if necessarry. | ||
1236 | if (signTestNode) { | 1238 | if (signTestNode) { | ||
1237 | if (isSigned) { | 1239 | if (isSigned) { | ||
1238 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime == S/MIME TYPE: opaque signed data"; | 1240 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime == S/MIME TYPE: opaque signed data"; | ||
1239 | } else { | 1241 | } else { | ||
1240 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - type unknown - opaque signed data ?"; | 1242 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - type unknown - opaque signed data ?"; | ||
1241 | } | 1243 | } | ||
1242 | 1244 | | |||
1243 | const QTextCodec *aCodec(codecFor(signTestNode)); | 1245 | const QTextCodec *aCodec(codecFor(signTestNode)); | ||
1244 | const QByteArray signaturetext = signTestNode->decodedContent(); | 1246 | const QByteArray signaturetext = signTestNode->decodedContent(); | ||
1245 | CryptoMessagePart mp(this, | 1247 | mp = CryptoMessagePart::Ptr(new CryptoMessagePart(this, | ||
1246 | aCodec->toUnicode(signaturetext), cryptoProtocol(), | 1248 | aCodec->toUnicode(signaturetext), cryptoProtocol(), | ||
1247 | NodeHelper::fromAsString(node), signTestNode); | 1249 | NodeHelper::fromAsString(node), signTestNode)); | ||
1248 | 1250 | | |||
1249 | PartMetaData *messagePart(mp.partMetaData()); | 1251 | PartMetaData *messagePart(mp->partMetaData()); | ||
1250 | if (cryptoProtocol()) { | 1252 | if (cryptoProtocol()) { | ||
1251 | mp.startVerificationDetached(signaturetext, 0, QByteArray()); | 1253 | mp->startVerificationDetached(signaturetext, 0, QByteArray()); | ||
1252 | } else { | 1254 | } else { | ||
1253 | messagePart->auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED); | 1255 | messagePart->auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED); | ||
1254 | } | 1256 | } | ||
1255 | 1257 | | |||
1256 | mp.html(false /*, hideErrors = isEncrypted*/); | | |||
1257 | if (messagePart->isSigned) { | 1258 | if (messagePart->isSigned) { | ||
1258 | if (!isSigned) { | 1259 | if (!isSigned) { | ||
1259 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - signature found - opaque signed data !"; | 1260 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - signature found - opaque signed data !"; | ||
1260 | isSigned = true; | 1261 | isSigned = true; | ||
1261 | } | 1262 | } | ||
1262 | 1263 | | |||
1263 | mNodeHelper->setSignatureState(signTestNode, KMMsgFullySigned); | 1264 | mNodeHelper->setSignatureState(signTestNode, KMMsgFullySigned); | ||
1264 | if (signTestNode != node) { | 1265 | if (signTestNode != node) { | ||
1265 | mNodeHelper->setSignatureState(node, KMMsgFullySigned); | 1266 | mNodeHelper->setSignatureState(node, KMMsgFullySigned); | ||
1266 | } | 1267 | } | ||
1267 | } else { | 1268 | } else { | ||
1268 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - NO signature found :-("; | 1269 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - NO signature found :-("; | ||
1269 | } | 1270 | } | ||
1270 | } | 1271 | } | ||
1271 | 1272 | | |||
1272 | return isSigned || isEncrypted; | 1273 | return mp; | ||
1273 | } | 1274 | } | ||
1274 | 1275 | | |||
1275 | void ObjectTreeParser::writeBodyString(const QByteArray &bodyString, | 1276 | void ObjectTreeParser::writeBodyString(const QByteArray &bodyString, | ||
1276 | const QString &fromAddress, | 1277 | const QString &fromAddress, | ||
1277 | const QTextCodec *codec, | 1278 | const QTextCodec *codec, | ||
1278 | ProcessResult &result, | 1279 | ProcessResult &result, | ||
1279 | bool decorate) | 1280 | bool decorate) | ||
1280 | { | 1281 | { | ||
▲ Show 20 Lines • Show All 1459 Lines • Show Last 20 Lines |
intentionally commented out code?