diff --git a/messageviewer/src/viewer/bodypartformatter.cpp b/messageviewer/src/viewer/bodypartformatter.cpp --- a/messageviewer/src/viewer/bodypartformatter.cpp +++ b/messageviewer/src/viewer/bodypartformatter.cpp @@ -227,7 +227,7 @@ { \ static const subtype##BodyPartFormatter *self; \ public: \ - bool process(ObjectTreeParser *, KMime::Content *, ProcessResult &) const;\ + MessagePart::Ptr process(const Interface::BodyPart &part) const; \ MessageViewer::Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE; \ using MessageViewer::Interface::BodyPartFormatter::format; \ static const MessageViewer::Interface::BodyPartFormatter *create(); \ @@ -241,14 +241,18 @@ } \ return self; \ } \ - bool subtype##BodyPartFormatter::process(ObjectTreeParser *otp, KMime::Content *node, ProcessResult &result) const { \ - return otp->process##subtype##Subtype(node, result); \ + MessagePart::Ptr subtype##BodyPartFormatter::process(const Interface::BodyPart &part) const { \ + return part.objectTreeParser()->process##subtype##Subtype(part.content(), *part.processResult()); \ } \ \ MessageViewer::Interface::BodyPartFormatter::Result subtype##BodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const { \ Q_UNUSED(writer) \ - const bool result = process(part->objectTreeParser(), part->content(), *part->processResult()); \ - return result ? Ok : Failed; \ + MessagePart::Ptr mp = process(*part);\ + if (!mp.isNull()) {\ + mp->html(false);\ + return Ok;\ + }\ + return Failed;\ } CREATE_BODY_PART_FORMATTER(TextPlain) diff --git a/messageviewer/src/viewer/objecttreeparser.h b/messageviewer/src/viewer/objecttreeparser.h --- a/messageviewer/src/viewer/objecttreeparser.h +++ b/messageviewer/src/viewer/objecttreeparser.h @@ -370,7 +370,7 @@ kroupware hacks) */ void standardChildHandling(KMime::Content *child); - void defaultHandling(KMime::Content *node, ProcessResult &result); + MessagePart::Ptr defaultHandling(KMime::Content *node, ProcessResult &result); /** 1. Create a new partNode using 'content' data and Content-Description found in 'cntDesc'. @@ -400,15 +400,15 @@ public:// (during refactoring) - bool processTextHtmlSubtype(KMime::Content *node, ProcessResult &result); - bool processTextPlainSubtype(KMime::Content *node, ProcessResult &result); + MessagePart::Ptr processTextHtmlSubtype(KMime::Content *node, ProcessResult &result); + MessagePart::Ptr processTextPlainSubtype(KMime::Content *node, ProcessResult &result); - bool processMultiPartMixedSubtype(KMime::Content *node, ProcessResult &result); - bool processMultiPartAlternativeSubtype(KMime::Content *node, ProcessResult &result); + MessagePart::Ptr processMultiPartMixedSubtype(KMime::Content *node, ProcessResult &result); + MessagePart::Ptr processMultiPartAlternativeSubtype(KMime::Content *node, ProcessResult &result); MessagePart::Ptr processMultiPartSignedSubtype(KMime::Content *node, ProcessResult &result); MessagePart::Ptr processMultiPartEncryptedSubtype(KMime::Content *node, ProcessResult &result); - bool processApplicationPkcs7MimeSubtype(KMime::Content *node, ProcessResult &result); + MessagePart::Ptr processApplicationPkcs7MimeSubtype(KMime::Content *node, ProcessResult &result); void writeBodyString(const QByteArray &bodyString, const QString &fromAddress, diff --git a/messageviewer/src/viewer/objecttreeparser.cpp b/messageviewer/src/viewer/objecttreeparser.cpp --- a/messageviewer/src/viewer/objecttreeparser.cpp +++ b/messageviewer/src/viewer/objecttreeparser.cpp @@ -355,8 +355,13 @@ mNodeHelper->setNodeDisplayedEmbedded(node, false); // fall through: case Interface::BodyPartFormatter::Failed: - defaultHandling(node, processResult); + { + const auto mp = defaultHandling(node, processResult); + if (mp) { + mp->html(false); + } break; + } case Interface::BodyPartFormatter::Ok: case Interface::BodyPartFormatter::NeedContent: // FIXME: incomplete content handling @@ -367,7 +372,10 @@ } else { qCCritical(MESSAGEVIEWER_LOG) << "THIS SHOULD NO LONGER HAPPEN:" << mediaType << '/' << subType; AttachmentMarkBlock block(htmlWriter(), node); - defaultHandling(node, processResult); + const auto mp = defaultHandling(node, processResult); + if (mp) { + mp->html(false); + } } mNodeHelper->setNodeProcessed(node, false); @@ -384,13 +392,13 @@ } } -void ObjectTreeParser::defaultHandling(KMime::Content *node, ProcessResult &result) +MessagePart::Ptr ObjectTreeParser::defaultHandling(KMime::Content *node, ProcessResult &result) { // ### (mmutz) default handling should go into the respective // ### bodypartformatters. if (!htmlWriter()) { qCWarning(MESSAGEVIEWER_LOG) << "no htmlWriter()"; - return; + return MessagePart::Ptr(); } // always show images in multipart/related when showing in html, not with an additional icon @@ -401,24 +409,24 @@ QByteArray cid = node->contentID()->identifier(); htmlWriter()->embedPart(cid, href); nodeHelper()->setNodeDisplayedEmbedded(node, true); - return; + return MessagePart::Ptr(); } - + MessagePart::Ptr mp; if (node->contentType()->mimeType() == QByteArray("application/octet-stream") && (node->contentType()->name().endsWith(QLatin1String("p7m")) || node->contentType()->name().endsWith(QLatin1String("p7s")) || node->contentType()->name().endsWith(QLatin1String("p7c")) ) && - processApplicationPkcs7MimeSubtype(node, result)) { - return; + (mp = processApplicationPkcs7MimeSubtype(node, result))) { + return mp; } const AttachmentStrategy *const as = attachmentStrategy(); if (as && as->defaultDisplay(node) == AttachmentStrategy::None && !showOnlyOneMimePart() && node->parent() /* message is not an attachment */) { mNodeHelper->setNodeDisplayedHidden(node, true); - return; + return MessagePart::Ptr(); } bool asIcon = true; @@ -459,11 +467,12 @@ writePartIcon(node, true); } else { mNodeHelper->setNodeDisplayedEmbedded(node, true); - writeBodyString(node->decodedContent(), - NodeHelper::fromAsString(node), - codecFor(node), result, false); + const auto mp = TextMessagePart::Ptr(new TextMessagePart(this, node, false, false)); + result.setInlineSignatureState(mp->signatureState()); + result.setInlineEncryptionState(mp->encryptionState()); + return mp; } - // end of ### + return MessagePart::Ptr(); } KMMsgSignatureState ProcessResult::inlineSignatureState() const @@ -747,20 +756,19 @@ return bDecryptionOk; } -bool ObjectTreeParser::processTextHtmlSubtype(KMime::Content *curNode, ProcessResult &) +MessagePart::Ptr ObjectTreeParser::processTextHtmlSubtype(KMime::Content *curNode, ProcessResult &) { - HtmlMessagePart mp(this, curNode, mSource); + HtmlMessagePart::Ptr mp(new HtmlMessagePart(this, curNode, mSource)); if (curNode->topLevel()->textContent() == curNode || attachmentStrategy()->defaultDisplay(curNode) == AttachmentStrategy::Inline || showOnlyOneMimePart()) { - mp.html(false); - return true; } else { // we need the copy of htmlcontent and charset in anycase for the current design of otp. //Should be not neeed if otp don't hold any status anymore - mp.fix(); - return false; + mp->fix(); + } + return mp; } bool ObjectTreeParser::isMailmanMessage(KMime::Content *curNode) @@ -896,13 +904,13 @@ } } -bool ObjectTreeParser::processTextPlainSubtype(KMime::Content *curNode, ProcessResult &result) +MessagePart::Ptr ObjectTreeParser::processTextPlainSubtype(KMime::Content *curNode, ProcessResult &result) { const bool isFirstTextPart = (curNode->topLevel()->textContent() == curNode); if (!isFirstTextPart && attachmentStrategy()->defaultDisplay(curNode) != AttachmentStrategy::Inline && !showOnlyOneMimePart()) { - return false; + return MessagePart::Ptr(); } extractNodeInfos(curNode, isFirstTextPart); @@ -916,22 +924,22 @@ // process old style not-multipart Mailman messages to // enable verification of the embedded messages' signatures - if (!isMailmanMessage(curNode) || - !processMailmanMessage(curNode)) { + //if (!isMailmanMessage(curNode) || + // !processMailmanMessage(curNode)) { - TextMessagePart mp(this, curNode, bDrawFrame, !fileName.isEmpty()); - mp.html(!bDrawFrame); + TextMessagePart::Ptr mp(new TextMessagePart(this, curNode, bDrawFrame, !fileName.isEmpty())); - result.setInlineSignatureState(mp.signatureState()); - result.setInlineEncryptionState(mp.encryptionState()); + result.setInlineSignatureState(mp->signatureState()); + result.setInlineEncryptionState(mp->encryptionState()); if (isFirstTextPart) { - mPlainTextContent = mp.text(); + mPlainTextContent = mp->text(); } mNodeHelper->setNodeDisplayedEmbedded(curNode, true); - } - return true; + //} + + return mp; } void ObjectTreeParser::standardChildHandling(KMime::Content *child) @@ -944,24 +952,23 @@ mp.html(false); } -bool ObjectTreeParser::processMultiPartMixedSubtype(KMime::Content *node, ProcessResult &) +MessagePart::Ptr ObjectTreeParser::processMultiPartMixedSubtype(KMime::Content *node, ProcessResult &) { KMime::Content *child = MessageCore::NodeHelper::firstChild(node); if (!child) { - return false; + return MessagePart::Ptr(); } // normal treatment of the parts in the mp/mixed container - MimeMessagePart mp(this, child, false); - mp.html(false); - return true; + MimeMessagePart::Ptr mp(new MimeMessagePart(this, child, false)); + return mp; } -bool ObjectTreeParser::processMultiPartAlternativeSubtype(KMime::Content *node, ProcessResult &) +MessagePart::Ptr ObjectTreeParser::processMultiPartAlternativeSubtype(KMime::Content *node, ProcessResult &) { KMime::Content *child = MessageCore::NodeHelper::firstChild(node); if (!child) { - return false; + return MessagePart::Ptr(); } KMime::Content *dataHtml = findType(child, "text/html", false, true); @@ -985,31 +992,27 @@ } if (dataPlain || dataHtml) { - AlternativeMessagePart mp(this, dataPlain, dataHtml); + AlternativeMessagePart::Ptr mp(new AlternativeMessagePart(this, dataPlain, dataHtml)); if ((mSource->htmlMail() && dataHtml) || (dataHtml && dataPlain && dataPlain->body().isEmpty())) { if (dataPlain) { mNodeHelper->setNodeProcessed(dataPlain, false); } mSource->setHtmlMode(Util::MultipartHtml); - mp.setViewHtml(true); - mp.html(false); - return true; + mp->setViewHtml(true); } if (!mSource->htmlMail() && dataPlain) { mNodeHelper->setNodeProcessed(dataHtml, false); mSource->setHtmlMode(Util::MultipartPlain); - mp.setViewHtml(false); - mp.html(false); - return true; + mp->setViewHtml(false); } + return mp; } - MimeMessagePart mp(this, child, false); - mp.html(false); - return true; + MimeMessagePart::Ptr mp(new MimeMessagePart(this, child, false)); + return mp; } MessagePart::Ptr ObjectTreeParser::processMultiPartSignedSubtype(KMime::Content *node, ProcessResult &) @@ -1148,25 +1151,24 @@ return mp; } -bool ObjectTreeParser::processApplicationPkcs7MimeSubtype(KMime::Content *node, ProcessResult &result) +MessagePart::Ptr ObjectTreeParser::processApplicationPkcs7MimeSubtype(KMime::Content *node, ProcessResult &result) { if (node->head().isEmpty()) { - return false; + return MessagePart::Ptr(); } const Kleo::CryptoBackend::Protocol *smimeCrypto = Kleo::CryptoBackendFactory::instance()->smime(); if (!smimeCrypto) { - return false; + return MessagePart::Ptr(); } const QString smimeType = node->contentType()->parameter(QStringLiteral("smime-type")).toLower(); if (smimeType == QLatin1String("certs-only")) { result.setNeverDisplayInline(true); - CertMessagePart mp(this, node, smimeCrypto, MessageViewer::MessageViewerSettings::self()->autoImportKeys()); - mp.html(true); - return true; + CertMessagePart::Ptr mp(new CertMessagePart(this, node, smimeCrypto, MessageViewer::MessageViewerSettings::self()->autoImportKeys())); + return mp; } CryptoProtocolSaver cpws(this, smimeCrypto); @@ -1182,23 +1184,24 @@ // We try decrypting the content // if we either *know* that it is an encrypted message part // or there is neither signed nor encrypted parameter. + CryptoMessagePart::Ptr mp; if (!isSigned) { if (isEncrypted) { qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime == S/MIME TYPE: enveloped (encrypted) data"; } else { qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - type unknown - enveloped (encrypted) data ?"; } - CryptoMessagePart mp(this, + mp = CryptoMessagePart::Ptr(new CryptoMessagePart(this, node->decodedText(), cryptoProtocol(), - NodeHelper::fromAsString(node), node); + NodeHelper::fromAsString(node), node)); - PartMetaData *messagePart(mp.partMetaData()); + PartMetaData *messagePart(mp->partMetaData()); if (!mSource->decryptMessage()) { isEncrypted = true; signTestNode = 0; // PENDING(marc) to be abs. sure, we'd need to have to look at the content } else { - mp.startDecryption(); + mp->startDecryption(); if (messagePart->isDecryptable) { qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - encryption found - enveloped (encrypted) data !"; isEncrypted = true; @@ -1213,7 +1216,7 @@ // decryption failed, or because we didn't know if it was encrypted, tried, // and failed. If the message was not actually encrypted, we continue // assuming it's signed - if (mp.mPassphraseError || (smimeType.isEmpty() && messagePart->isEncrypted)) { + if (mp->mPassphraseError || (smimeType.isEmpty() && messagePart->isEncrypted)) { isEncrypted = true; signTestNode = 0; } @@ -1225,7 +1228,6 @@ } } } - mp.html(false); if (isEncrypted) { mNodeHelper->setEncryptionState(node, KMMsgFullyEncrypted); @@ -1242,18 +1244,17 @@ const QTextCodec *aCodec(codecFor(signTestNode)); const QByteArray signaturetext = signTestNode->decodedContent(); - CryptoMessagePart mp(this, + mp = CryptoMessagePart::Ptr(new CryptoMessagePart(this, aCodec->toUnicode(signaturetext), cryptoProtocol(), - NodeHelper::fromAsString(node), signTestNode); + NodeHelper::fromAsString(node), signTestNode)); - PartMetaData *messagePart(mp.partMetaData()); + PartMetaData *messagePart(mp->partMetaData()); if (cryptoProtocol()) { - mp.startVerificationDetached(signaturetext, 0, QByteArray()); + mp->startVerificationDetached(signaturetext, 0, QByteArray()); } else { messagePart->auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED); } - mp.html(false /*, hideErrors = isEncrypted*/); if (messagePart->isSigned) { if (!isSigned) { qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - signature found - opaque signed data !"; @@ -1269,7 +1270,7 @@ } } - return isSigned || isEncrypted; + return mp; } void ObjectTreeParser::writeBodyString(const QByteArray &bodyString,