diff --git a/messageviewer/src/messagepartthemes/default/autotests/rendertest.cpp b/messageviewer/src/messagepartthemes/default/autotests/rendertest.cpp index 1b8c0e4f..b148d019 100644 --- a/messageviewer/src/messagepartthemes/default/autotests/rendertest.cpp +++ b/messageviewer/src/messagepartthemes/default/autotests/rendertest.cpp @@ -1,432 +1,429 @@ /* Copyright (c) 2010 Volker Krause Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "rendertest.h" #include "setupenv.h" #include "testcsshelper.h" #include "util.h" #include #include #include #include #include #include #include using namespace MessageViewer; void RenderTest::initTestCase() { Test::setupEnv(); } void RenderTest::testRenderSmart_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QTest::addColumn("attachmentStrategy"); QTest::addColumn("showSignatureDetails"); QTest::addColumn("asyncFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); foreach (const QString &file, dir.entryList(QStringList(QLatin1String("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks)) { if (!QFile::exists(dir.path() + QLatin1Char('/') + file + QStringLiteral(".html"))) { continue; } QTest::newRow(file.toLatin1().constData()) << file << QString(dir.path() + QLatin1Char( '/') + file + QStringLiteral(".html")) << QString(file + QStringLiteral(".out")) << QStringLiteral("smart") << false << QString(); } } void RenderTest::testRenderSmart() { testRender(); } void RenderTest::testRenderSmartAsync_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QTest::addColumn("attachmentStrategy"); QTest::addColumn("showSignatureDetails"); QTest::addColumn("asyncFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); foreach (const QString &file, dir.entryList(QStringList(QLatin1String("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks)) { if (!QFile::exists(dir.path() + QLatin1Char('/') + file + QStringLiteral(".inProgress.html"))) { continue; } QTest::newRow(file.toLatin1().constData()) << file << QString(dir.path() + QLatin1Char( '/') + file + QStringLiteral(".html")) << QString(file + QStringLiteral(".out")) << QStringLiteral("smart") << false << QString( dir.path() + QLatin1Char( '/') + file + QStringLiteral(".inProgress.html")); } } void RenderTest::testRenderSmartAsync() { testRender(); } void RenderTest::testRenderSmartDetails_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QTest::addColumn("attachmentStrategy"); QTest::addColumn("showSignatureDetails"); QTest::addColumn("asyncFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); foreach (const QString &file, dir.entryList(QStringList(QLatin1String("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks)) { QString fname = dir.path() + QStringLiteral("/details/") + file + QStringLiteral(".html"); if (!QFile::exists(fname)) { continue; } QTest::newRow(file.toLatin1().constData()) << file << fname << QString(file + QStringLiteral( ".out")) << QStringLiteral("smart") << true << QString(); } } void RenderTest::testRenderSmartDetails() { testRender(); } void RenderTest::testRenderInlined_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QTest::addColumn("attachmentStrategy"); QTest::addColumn("showSignatureDetails"); QTest::addColumn("asyncFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); foreach (const QString &file, dir.entryList(QStringList(QLatin1String("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks)) { QString fname = dir.path() + QStringLiteral("/inlined/") + file + QStringLiteral(".html"); if (!QFile::exists(fname)) { fname = dir.path() + QStringLiteral("/") + file + QStringLiteral(".html"); if (!QFile::exists(fname)) { continue; } } QTest::newRow(file.toLatin1().constData()) << file << fname << QString(file + QStringLiteral( ".out")) << QStringLiteral("inlined") << false << QString(); } } void RenderTest::testRenderInlined() { testRender(); } void RenderTest::testRenderIconic_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QTest::addColumn("attachmentStrategy"); QTest::addColumn("showSignatureDetails"); QTest::addColumn("asyncFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); foreach (const QString &file, dir.entryList(QStringList(QLatin1String("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks)) { QString fname = dir.path() + QStringLiteral("/iconic/") + file + QStringLiteral(".html"); if (!QFile::exists(fname)) { fname = dir.path() + QStringLiteral("/") + file + QStringLiteral(".html"); if (!QFile::exists(fname)) { continue; } } QTest::newRow(file.toLatin1().constData()) << file << fname << QString(file + QStringLiteral( ".out")) << QStringLiteral("iconic") << false << QString(); } } void RenderTest::testRenderIconic() { testRender(); } void RenderTest::testRenderHidden_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QTest::addColumn("attachmentStrategy"); QTest::addColumn("showSignatureDetails"); QTest::addColumn("asyncFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); foreach (const QString &file, dir.entryList(QStringList(QLatin1String("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks)) { QString fname = dir.path() + QStringLiteral("/hidden/") + file + QStringLiteral(".html"); if (!QFile::exists(fname)) { fname = dir.path() + QStringLiteral("/") + file + QStringLiteral(".html"); if (!QFile::exists(fname)) { continue; } } QTest::newRow(file.toLatin1().constData()) << file << fname << QString(file + QStringLiteral( ".out")) << QStringLiteral("hidden") << false << QString(); } } void RenderTest::testRenderHidden() { testRender(); } void RenderTest::testRenderHeaderOnly_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QTest::addColumn("attachmentStrategy"); QTest::addColumn("showSignatureDetails"); QTest::addColumn("asyncFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); foreach (const QString &file, dir.entryList(QStringList(QLatin1String("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks)) { QString fname = dir.path() + QStringLiteral("/headeronly/") + file + QStringLiteral(".html"); if (!QFile::exists(fname)) { fname = dir.path() + QStringLiteral("/") + file + QStringLiteral(".html"); if (!QFile::exists(fname)) { continue; } } QTest::newRow(file.toLatin1().constData()) << file << fname << QString(file + QStringLiteral( ".out")) << QStringLiteral("headeronly") << false << QString(); } } void RenderTest::testRenderHeaderOnly() { testRender(); } -QString renderTreeHelper(const MimeTreeParser::Interface::MessagePart::Ptr &messagePart, QString indent) +QString renderTreeHelper(const MimeTreeParser::MessagePart::Ptr &messagePart, QString indent) { const QString line = QStringLiteral("%1 * %3\n").arg(indent, QString::fromUtf8(messagePart->metaObject()->className())); QString ret = line; indent += QStringLiteral(" "); - const auto m = messagePart.dynamicCast(); - if (m) { - foreach (const auto &subPart, m->subParts()) { - ret += renderTreeHelper(subPart, indent); - } + foreach (const auto &subPart, messagePart->subParts()) { + ret += renderTreeHelper(subPart, indent); } return ret; } void RenderTest::testRenderTree(const MimeTreeParser::MessagePart::Ptr &messagePart) { QString renderedTree = renderTreeHelper(messagePart, QString()); QFETCH(QString, mailFileName); QFETCH(QString, outFileName); const QString treeFileName = QLatin1String(MAIL_DATA_DIR) + QLatin1Char('/') + mailFileName + QStringLiteral(".tree"); const QString outTreeFileName = outFileName + QStringLiteral(".tree"); { QFile f(outTreeFileName); f.open(QIODevice::WriteOnly); f.write(renderedTree.toUtf8()); f.close(); } // compare to reference file const QStringList args = QStringList() << QStringLiteral("-u") << treeFileName << outTreeFileName; QProcess proc; proc.setProcessChannelMode(QProcess::ForwardedChannels); proc.start(QStringLiteral("diff"), args); QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitCode(), 0); } void RenderTest::testRender() { QFETCH(QString, mailFileName); QFETCH(QString, referenceFileName); QFETCH(QString, outFileName); QFETCH(QString, attachmentStrategy); QFETCH(bool, showSignatureDetails); QFETCH(QString, asyncFileName); const QString htmlFileName = outFileName + QStringLiteral(".html"); const bool bAsync = !asyncFileName.isEmpty(); // load input mail const KMime::Message::Ptr msg(Test::readAndParseMail(mailFileName)); // render the mail MimeTreeParser::FileHtmlWriter fileWriter(outFileName); QImage paintDevice; Test::TestCSSHelper cssHelper(&paintDevice); MimeTreeParser::NodeHelper nodeHelper; Test::ObjectTreeSource testSource(&fileWriter, &cssHelper); testSource.setAllowDecryption(true); testSource.setAttachmentStrategy(attachmentStrategy); testSource.setShowSignatureDetails(showSignatureDetails); QEventLoop loop; MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper); connect(&nodeHelper, &MimeTreeParser::NodeHelper::update, &loop, &QEventLoop::quit); otp.setAllowAsync(bAsync); fileWriter.begin(QString()); fileWriter.queue(cssHelper.htmlHead(false)); otp.parseObjectTree(msg.data()); fileWriter.queue(QStringLiteral("")); fileWriter.flush(); fileWriter.end(); if (!bAsync) { testRenderTree(otp.parsedPart()); } else { compareFile(outFileName, asyncFileName); loop.exec(); MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper); otp.setAllowAsync(bAsync); fileWriter.begin(QString()); fileWriter.queue(cssHelper.htmlHead(false)); otp.parseObjectTree(msg.data()); fileWriter.queue(QStringLiteral("")); fileWriter.flush(); fileWriter.end(); testRenderTree(otp.parsedPart()); } compareFile(outFileName, referenceFileName); } void RenderTest::compareFile(const QString &outFile, const QString &referenceFile) { QVERIFY(QFile::exists(outFile)); const QString htmlFile = outFile + QStringLiteral(".html"); // remove tailing newlines and spaces and make htmlmore uniform (breaks pre tags) { QFile f(outFile); QVERIFY(f.open(QIODevice::ReadOnly)); QString content = QString::fromUtf8(f.readAll()); f.close(); content.replace(QRegExp(QStringLiteral("[\t ]+")), QStringLiteral(" ")); content.replace(QRegExp(QStringLiteral("[\t ]*\n+[\t ]*")), QStringLiteral("\n")); content.replace(QRegExp(QStringLiteral("([\n\t ])\\1+")), QStringLiteral("\\1")); content.replace(QRegExp(QStringLiteral(">\n+[\t ]*")), QStringLiteral(">")); content.replace(QRegExp(QStringLiteral("[\t ]*\n+[\t ]*<")), QStringLiteral("<")); content.replace(QLatin1String(" "), QLatin1String("NBSP_ENTITY_PLACEHOLDER")); // xmlling chokes on   QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Truncate)); f.write(content.toUtf8()); f.close(); } // validate xml and pretty-print for comparisson // TODO add proper cmake check for xmllint and diff QStringList args = QStringList() << QStringLiteral("--format") << QStringLiteral("--encode") << QStringLiteral("UTF8") << QStringLiteral("--output") << htmlFile << outFile; QCOMPARE(QProcess::execute(QStringLiteral("xmllint"), args), 0); // get rid of system dependent or random paths { QFile f(htmlFile); QVERIFY(f.open(QIODevice::ReadOnly)); QString content = QString::fromUtf8(f.readAll()); f.close(); content.replace(QRegExp(QStringLiteral( "\"file:[^\"]*[/(?:%2F)]([^\"/(?:%2F)]*)\"")), QStringLiteral("\"file:\\1\"")); content.replace(QLatin1String("NBSP_ENTITY_PLACEHOLDER"), QLatin1String(" ")); // undo above transformation for xmllint QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Truncate)); f.write(content.toUtf8()); f.close(); } // compare to reference file args = QStringList() << QStringLiteral("-u") << referenceFile << htmlFile; QProcess proc; proc.setProcessChannelMode(QProcess::ForwardedChannels); proc.start(QStringLiteral("diff"), args); QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitCode(), 0); } QTEST_MAIN(RenderTest) diff --git a/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp b/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp index ad8a66f3..9f243077 100644 --- a/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp +++ b/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp @@ -1,1075 +1,1067 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "defaultrenderer.h" #include "defaultrenderer_p.h" #include "messageviewer_debug.h" #include "converthtmltoplaintext.h" #include "messagepartrendererbase.h" #include "messagepartrendererfactory.h" #include "htmlblock.h" #include "partrendered.h" #include "utils/iconnamecache.h" #include "utils/mimetype.h" #include "viewer/csshelperbase.h" #include "messagepartrenderermanager.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace MimeTreeParser; using namespace MessageViewer; Q_DECLARE_METATYPE(GpgME::DecryptionResult::Recipient) Q_DECLARE_METATYPE(const QGpgME::Protocol *) static const int SIG_FRAME_COL_UNDEF = 99; #define SIG_FRAME_COL_RED -1 #define SIG_FRAME_COL_YELLOW 0 #define SIG_FRAME_COL_GREEN 1 QString sigStatusToString(const QGpgME::Protocol *cryptProto, int status_code, GpgME::Signature::Summary summary, int &frameColor, bool &showKeyInfos) { // note: At the moment frameColor and showKeyInfos are // used for CMS only but not for PGP signatures // pending(khz): Implement usage of these for PGP sigs as well. showKeyInfos = true; QString result; if (cryptProto) { if (cryptProto == QGpgME::openpgp()) { // process enum according to it's definition to be read in // GNU Privacy Guard CVS repository /gpgme/gpgme/gpgme.h switch (status_code) { case 0: // GPGME_SIG_STAT_NONE result = i18n("Error: Signature not verified"); break; case 1: // GPGME_SIG_STAT_GOOD result = i18n("Good signature"); break; case 2: // GPGME_SIG_STAT_BAD result = i18n("Bad signature"); break; case 3: // GPGME_SIG_STAT_NOKEY result = i18n("No public key to verify the signature"); break; case 4: // GPGME_SIG_STAT_NOSIG result = i18n("No signature found"); break; case 5: // GPGME_SIG_STAT_ERROR result = i18n("Error verifying the signature"); break; case 6: // GPGME_SIG_STAT_DIFF result = i18n("Different results for signatures"); break; /* PENDING(khz) Verify exact meaning of the following values: case 7: // GPGME_SIG_STAT_GOOD_EXP return i18n("Signature certificate is expired"); break; case 8: // GPGME_SIG_STAT_GOOD_EXPKEY return i18n("One of the certificate's keys is expired"); break; */ default: result.clear(); // do *not* return a default text here ! break; } } else if (cryptProto == QGpgME::smime()) { // process status bits according to SigStatus_... // definitions in kdenetwork/libkdenetwork/cryptplug.h if (summary == GpgME::Signature::None) { result = i18n("No status information available."); frameColor = SIG_FRAME_COL_YELLOW; showKeyInfos = false; return result; } if (summary & GpgME::Signature::Valid) { result = i18n("Good signature."); // Note: // Here we are work differently than KMail did before! // // The GOOD case ( == sig matching and the complete // certificate chain was verified and is valid today ) // by definition does *not* show any key // information but just states that things are OK. // (khz, according to LinuxTag 2002 meeting) frameColor = SIG_FRAME_COL_GREEN; showKeyInfos = false; return result; } // we are still there? OK, let's test the different cases: // we assume green, test for yellow or red (in this order!) frameColor = SIG_FRAME_COL_GREEN; QString result2; if (summary & GpgME::Signature::KeyExpired) { // still is green! result2 = i18n("One key has expired."); } if (summary & GpgME::Signature::SigExpired) { // and still is green! result2 += i18n("The signature has expired."); } // test for yellow: if (summary & GpgME::Signature::KeyMissing) { result2 += i18n("Unable to verify: key missing."); // if the signature certificate is missing // we cannot show information on it showKeyInfos = false; frameColor = SIG_FRAME_COL_YELLOW; } if (summary & GpgME::Signature::CrlMissing) { result2 += i18n("CRL not available."); frameColor = SIG_FRAME_COL_YELLOW; } if (summary & GpgME::Signature::CrlTooOld) { result2 += i18n("Available CRL is too old."); frameColor = SIG_FRAME_COL_YELLOW; } if (summary & GpgME::Signature::BadPolicy) { result2 += i18n("A policy was not met."); frameColor = SIG_FRAME_COL_YELLOW; } if (summary & GpgME::Signature::SysError) { result2 += i18n("A system error occurred."); // if a system error occurred // we cannot trust any information // that was given back by the plug-in showKeyInfos = false; frameColor = SIG_FRAME_COL_YELLOW; } // test for red: if (summary & GpgME::Signature::KeyRevoked) { // this is red! result2 += i18n("One key has been revoked."); frameColor = SIG_FRAME_COL_RED; } if (summary & GpgME::Signature::Red) { if (result2.isEmpty()) { // Note: // Here we are work differently than KMail did before! // // The BAD case ( == sig *not* matching ) // by definition does *not* show any key // information but just states that things are BAD. // // The reason for this: In this case ALL information // might be falsificated, we can NOT trust the data // in the body NOT the signature - so we don't show // any key/signature information at all! // (khz, according to LinuxTag 2002 meeting) showKeyInfos = false; } frameColor = SIG_FRAME_COL_RED; } else { result.clear(); } if (SIG_FRAME_COL_GREEN == frameColor) { result = i18n("Good signature."); } else if (SIG_FRAME_COL_RED == frameColor) { result = i18n("Bad signature."); } else { result.clear(); } if (!result2.isEmpty()) { if (!result.isEmpty()) { result.append(QLatin1String("
")); } result.append(result2); } } /* // add i18n support for 3rd party plug-ins here: else if ( cryptPlug->libName().contains( "yetanotherpluginname", Qt::CaseInsensitive )) { } */ } return result; } /** Checks whether @p str contains external references. To be precise, we only check whether @p str contains 'xxx="http[s]:' where xxx is not href. Obfuscated external references are ignored on purpose. */ bool containsExternalReferences(const QString &str, const QString &extraHead) { const bool hasBaseInHeader = extraHead.contains(QStringLiteral( "= 0 || httpsPos >= 0) { // pos = index of next occurrence of "http: or "https: whichever comes first int pos = (httpPos < httpsPos) ? ((httpPos >= 0) ? httpPos : httpsPos) : ((httpsPos >= 0) ? httpsPos : httpPos); // look backwards for "href" if (pos > 5) { int hrefPos = str.lastIndexOf(QLatin1String("href"), pos - 5, Qt::CaseInsensitive); // if no 'href' is found or the distance between 'href' and '"http[s]:' // is larger than 7 (7 is the distance in 'href = "http[s]:') then // we assume that we have found an external reference if ((hrefPos == -1) || (pos - hrefPos > 7)) { // HTML messages created by KMail itself for now contain the following: // // Make sure not to show an external references warning for this string int dtdPos = str.indexOf(QLatin1String( "http://www.w3.org/TR/html4/loose.dtd"), pos + 1); if (dtdPos != (pos + 1)) { return true; } } } // find next occurrence of "http: or "https: if (pos == httpPos) { httpPos = str.indexOf(QLatin1String("\"http:"), httpPos + 6, Qt::CaseInsensitive); } else { httpsPos = str.indexOf(QLatin1String("\"https:"), httpsPos + 7, Qt::CaseInsensitive); } } return false; } // FIXME this used to go through the full webkit parser to extract the body and head blocks // until we have that back, at least attempt to fix some of the damage // yes, "parsing" HTML with regexps is very very wrong, but it's still better than not filtering // this at all... QString processHtml(const QString &htmlSource, QString &extraHead) { auto s = htmlSource.trimmed(); s = s.replace(QRegExp(QStringLiteral("^]*>"), Qt::CaseInsensitive), QString()).trimmed(); s = s.replace(QRegExp(QStringLiteral("^]*>"), Qt::CaseInsensitive), QString()).trimmed(); // head s = s.replace(QRegExp(QStringLiteral("^"), Qt::CaseInsensitive), QString()).trimmed(); if (s.startsWith(QLatin1String("", Qt::CaseInsensitive))) { const auto idx = s.indexOf(QLatin1String(""), Qt::CaseInsensitive); if (idx < 0) { return htmlSource; } extraHead = s.mid(6, idx - 6); s = s.mid(idx + 7).trimmed(); } // body s = s.replace(QRegExp(QStringLiteral("]*>"), Qt::CaseInsensitive), QString()).trimmed(); s = s.replace(QRegExp(QStringLiteral("$"), Qt::CaseInsensitive), QString()).trimmed(); s = s.replace(QRegExp(QStringLiteral("$"), Qt::CaseInsensitive), QString()).trimmed(); return s; } class CacheHtmlWriter : public MimeTreeParser::HtmlWriter { public: explicit CacheHtmlWriter(MimeTreeParser::HtmlWriter *baseWriter) : mBaseWriter(baseWriter) { } virtual ~CacheHtmlWriter() { } void begin(const QString &text) override { mBaseWriter->begin(text); } void write(const QString &str) override { html.append(str); } void end() override { mBaseWriter->end(); } void reset() override { mBaseWriter->reset(); } void queue(const QString &str) override { html.append(str); } void flush() override { mBaseWriter->flush(); } void embedPart(const QByteArray &contentId, const QString &url) override { mBaseWriter->embedPart(contentId, url); } void extraHead(const QString &extra) override { mBaseWriter->extraHead(extra); } QString html; MimeTreeParser::HtmlWriter *mBaseWriter = nullptr; }; -DefaultRendererPrivate::DefaultRendererPrivate(const Interface::MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper, HtmlWriter *writer, const MessagePartRendererFactory *rendererFactory) +DefaultRendererPrivate::DefaultRendererPrivate(const MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper, HtmlWriter *writer, const MessagePartRendererFactory *rendererFactory) : mMsgPart(msgPart) , mOldWriter(writer) , mCSSHelper(cssHelper) , mRendererFactory(rendererFactory) { mHtml = renderFactory(mMsgPart, QSharedPointer()); } DefaultRendererPrivate::~DefaultRendererPrivate() { } QString DefaultRendererPrivate::alignText() { return QApplication::isRightToLeft() ? QStringLiteral("rtl") : QStringLiteral("ltr"); } CSSHelperBase *DefaultRendererPrivate::cssHelper() const { - auto mp = mMsgPart.dynamicCast(); - if (mp) { - return mCSSHelper; - } - return nullptr; + return mCSSHelper; } Interface::ObjectTreeSource *DefaultRendererPrivate::source() const { - auto mp = mMsgPart.dynamicCast(); - if (mp) { - return mp->source(); - } - return nullptr; + return mMsgPart->source(); } void DefaultRendererPrivate::renderSubParts(const MessagePart::Ptr &msgPart, const QSharedPointer &htmlWriter) { foreach (const auto &m, msgPart->subParts()) htmlWriter->queue(renderFactory(m, htmlWriter)); } QString DefaultRendererPrivate::render(const MessagePartList::Ptr &mp) { auto htmlWriter = QSharedPointer(new CacheHtmlWriter(mOldWriter)); { HTMLBlock::Ptr rBlock; HTMLBlock::Ptr aBlock; if (mp->isRoot()) { rBlock = HTMLBlock::Ptr(new RootBlock(htmlWriter.data())); } if (mp->isAttachment()) { aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode())); } renderSubParts(mp, htmlWriter); } return htmlWriter->html; } QString DefaultRendererPrivate::render(const MimeMessagePart::Ptr &mp) { auto htmlWriter = QSharedPointer(new CacheHtmlWriter(mOldWriter)); { HTMLBlock::Ptr aBlock; HTMLBlock::Ptr rBlock; if (mp->isAttachment()) { aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode())); } if (mp->isRoot()) { rBlock = HTMLBlock::Ptr(new RootBlock(htmlWriter.data())); } renderSubParts(mp, htmlWriter); } return htmlWriter->html; } QString DefaultRendererPrivate::render(const EncapsulatedRfc822MessagePart::Ptr &mp) { if (!mp->hasSubParts()) { return QString(); } Grantlee::Template t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral( ":/encapsulatedrfc822messagepart.html")); Grantlee::Context c = MessageViewer::MessagePartRendererManager::self()->createContext(); QObject block; c.insert(QStringLiteral("block"), &block); block.setProperty("dir", alignText()); block.setProperty("link", mp->mOtp->nodeHelper()->asHREF(mp->mMessage.data(), QStringLiteral("body"))); c.insert(QStringLiteral("msgHeader"), mp->source()->createMessageHeader(mp->mMessage.data())); { auto _htmlWriter = QSharedPointer(new CacheHtmlWriter(mOldWriter)); renderSubParts(mp, _htmlWriter); c.insert(QStringLiteral("content"), _htmlWriter->html); } auto htmlWriter = QSharedPointer(new CacheHtmlWriter(mOldWriter)); { HTMLBlock::Ptr aBlock; if (mp->isAttachment()) { aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode())); } const auto html = t->render(&c); htmlWriter->queue(html); } return htmlWriter->html; } QString DefaultRendererPrivate::render(const HtmlMessagePart::Ptr &mp) { Grantlee::Template t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral( ":/htmlmessagepart.html")); Grantlee::Context c = MessageViewer::MessagePartRendererManager::self()->createContext(); QObject block; c.insert(QStringLiteral("block"), &block); auto preferredMode = mp->source()->preferredMode(); bool isHtmlPreferred = (preferredMode == Util::Html) || (preferredMode == Util::MultipartHtml); const bool isPrinting = mp->source()->isPrinting(); block.setProperty("htmlMail", isHtmlPreferred); block.setProperty("loadExternal", mp->source()->htmlLoadExternal()); block.setProperty("isPrinting", isPrinting); { QString extraHead; //laurent: FIXME port to async method webengine QString bodyText = processHtml(mp->mBodyHTML, extraHead); if (isHtmlPreferred) { mp->mOtp->nodeHelper()->setNodeDisplayedEmbedded(mp->mNode, true); mOldWriter->extraHead(extraHead); } block.setProperty("containsExternalReferences", containsExternalReferences(bodyText, extraHead)); c.insert(QStringLiteral("content"), bodyText); } { ConvertHtmlToPlainText convert; convert.setHtmlString(mp->mBodyHTML); QString plaintext = convert.generatePlainText(); plaintext.replace(QLatin1Char('\n'), QStringLiteral("
")); c.insert(QStringLiteral("plaintext"), plaintext); } mp->source()->setHtmlMode(Util::Html, QList() << Util::Html); auto htmlWriter = QSharedPointer(new CacheHtmlWriter(mOldWriter)); { HTMLBlock::Ptr aBlock; if (mp->isAttachment()) { aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode())); } const auto html = t->render(&c); htmlWriter->queue(html); } return htmlWriter->html; } QString DefaultRendererPrivate::renderEncrypted(const EncryptedMessagePart::Ptr &mp) { KMime::Content *node = mp->mNode; - const auto metaData = mp->mMetaData; + const auto metaData = *mp->partMetaData(); Grantlee::Template t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral( ":/encryptedmessagepart.html")); Grantlee::Context c = MessageViewer::MessagePartRendererManager::self()->createContext(); QObject block; if (node || mp->hasSubParts()) { auto _htmlWriter = QSharedPointer(new CacheHtmlWriter(mOldWriter)); { HTMLBlock::Ptr rBlock; if (node && mp->isRoot()) { rBlock = HTMLBlock::Ptr(new RootBlock(_htmlWriter.data())); } renderSubParts(mp, _htmlWriter); } c.insert(QStringLiteral("content"), _htmlWriter->html); } else if (!metaData.inProgress) { auto part = renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp); if (part) { c.insert(QStringLiteral("content"), part->html()); } else { c.insert(QStringLiteral("content"), QString()); } } c.insert(QStringLiteral("cryptoProto"), QVariant::fromValue(mp->mCryptoProto)); if (mp->mDecryptRecipients.size() > 0) { c.insert(QStringLiteral("decryptedRecipients"), QVariant::fromValue(mp->mDecryptRecipients)); } c.insert(QStringLiteral("block"), &block); block.setProperty("dir", alignText()); block.setProperty("inProgress", metaData.inProgress); block.setProperty("isDecrypted", mp->decryptMessage()); block.setProperty("isDecryptable", metaData.isDecryptable); block.setProperty("decryptIcon", QUrl::fromLocalFile(IconNameCache::instance()->iconPath(QStringLiteral( "document-decrypt"), KIconLoader::Small)).url()); block.setProperty("errorText", metaData.errorText); block.setProperty("noSecKey", mp->mNoSecKey); block.setProperty("iconSize", MessageViewer::MessagePartRendererManager::self()->iconCurrentSize()); const auto html = t->render(&c); return html; } QString DefaultRendererPrivate::renderSigned(const SignedMessagePart::Ptr &mp) { KMime::Content *node = mp->mNode; - const auto metaData = mp->mMetaData; + const auto metaData = *mp->partMetaData(); auto cryptoProto = mp->mCryptoProto; const bool isSMIME = cryptoProto && (cryptoProto == QGpgME::smime()); Grantlee::Template t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral( ":/signedmessagepart.html")); Grantlee::Context c = MessageViewer::MessagePartRendererManager::self()->createContext(); QObject block; if (node) { auto _htmlWriter = QSharedPointer(new CacheHtmlWriter(mOldWriter)); { HTMLBlock::Ptr rBlock; if (mp->isRoot()) { rBlock = HTMLBlock::Ptr(new RootBlock(_htmlWriter.data())); } renderSubParts(mp, _htmlWriter); } c.insert(QStringLiteral("content"), _htmlWriter->html); } else if (!metaData.inProgress) { auto part = renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp); if (part) { c.insert(QStringLiteral("content"), part->html()); } else { c.insert(QStringLiteral("content"), QString()); } } c.insert(QStringLiteral("cryptoProto"), QVariant::fromValue(cryptoProto)); c.insert(QStringLiteral("block"), &block); block.setProperty("dir", alignText()); block.setProperty("inProgress", metaData.inProgress); block.setProperty("errorText", metaData.errorText); block.setProperty("detailHeader", mp->source()->showSignatureDetails()); block.setProperty("printing", false); block.setProperty("addr", metaData.signerMailAddresses.join(QLatin1Char(','))); block.setProperty("technicalProblem", metaData.technicalProblem); block.setProperty("keyId", metaData.keyId); if (metaData.creationTime.isValid()) { //should be handled inside grantlee but currently not possible see: https://bugs.kde.org/363475 block.setProperty("creationTime", QLocale().toString(metaData.creationTime, QLocale::ShortFormat)); } block.setProperty("isGoodSignature", metaData.isGoodSignature); block.setProperty("isSMIME", isSMIME); if (metaData.keyTrust == GpgME::Signature::Unknown) { block.setProperty("keyTrust", QStringLiteral("unknown")); } else if (metaData.keyTrust == GpgME::Signature::Marginal) { block.setProperty("keyTrust", QStringLiteral("marginal")); } else if (metaData.keyTrust == GpgME::Signature::Full) { block.setProperty("keyTrust", QStringLiteral("full")); } else if (metaData.keyTrust == GpgME::Signature::Ultimate) { block.setProperty("keyTrust", QStringLiteral("ultimate")); } else { block.setProperty("keyTrust", QStringLiteral("untrusted")); } QString startKeyHREF; { QString keyWithWithoutURL; if (cryptoProto) { startKeyHREF = QStringLiteral("") .arg(cryptoProto->displayName(), cryptoProto->name(), QString::fromLatin1(metaData.keyId)); keyWithWithoutURL = QStringLiteral("%1%2").arg(startKeyHREF, QString::fromLatin1(QByteArray(QByteArrayLiteral( "0x") + metaData.keyId))); } else { keyWithWithoutURL = QStringLiteral("0x") + QString::fromUtf8(metaData.keyId); } block.setProperty("keyWithWithoutURL", keyWithWithoutURL); } bool onlyShowKeyURL = false; bool showKeyInfos = false; bool cannotCheckSignature = true; QString signer = metaData.signer; QString statusStr; QString mClass; QString greenCaseWarning; if (metaData.inProgress) { mClass = QStringLiteral("signInProgress"); } else { const QStringList &blockAddrs(metaData.signerMailAddresses); // note: At the moment frameColor and showKeyInfos are // used for CMS only but not for PGP signatures // pending(khz): Implement usage of these for PGP sigs as well. int frameColor = SIG_FRAME_COL_UNDEF; statusStr = sigStatusToString(cryptoProto, metaData.status_code, metaData.sigSummary, frameColor, showKeyInfos); // if needed fallback to english status text // that was reported by the plugin if (statusStr.isEmpty()) { statusStr = metaData.status; } if (metaData.technicalProblem) { frameColor = SIG_FRAME_COL_YELLOW; } switch (frameColor) { case SIG_FRAME_COL_RED: cannotCheckSignature = false; break; case SIG_FRAME_COL_YELLOW: cannotCheckSignature = true; break; case SIG_FRAME_COL_GREEN: cannotCheckSignature = false; break; } // temporary hack: always show key information! showKeyInfos = true; if (isSMIME && (SIG_FRAME_COL_UNDEF != frameColor)) { switch (frameColor) { case SIG_FRAME_COL_RED: mClass = QStringLiteral("signErr"); onlyShowKeyURL = true; break; case SIG_FRAME_COL_YELLOW: if (metaData.technicalProblem) { mClass = QStringLiteral("signWarn"); } else { mClass = QStringLiteral("signOkKeyBad"); } break; case SIG_FRAME_COL_GREEN: mClass = QStringLiteral("signOkKeyOk"); // extra hint for green case // that email addresses in DN do not match fromAddress QString msgFrom(KEmailAddress::extractEmailAddress(mp->mFromAddress)); QString certificate; if (metaData.keyId.isEmpty()) { certificate = i18n("certificate"); } else { certificate = startKeyHREF + i18n("certificate") + QStringLiteral(""); } if (!blockAddrs.empty()) { if (!blockAddrs.contains(msgFrom, Qt::CaseInsensitive)) { greenCaseWarning = QStringLiteral("") +i18nc("Start of warning message.", "Warning:") +QStringLiteral(" ") +i18n( "Sender's mail address is not stored in the %1 used for signing.", certificate) +QStringLiteral("
") +i18n("sender: ") +msgFrom +QStringLiteral("
") +i18n("stored: "); // We cannot use Qt's join() function here but // have to join the addresses manually to // extract the mail addresses (without '<''>') // before including it into our string: bool bStart = true; QStringList::ConstIterator end(blockAddrs.constEnd()); for (QStringList::ConstIterator it = blockAddrs.constBegin(); it != end; ++it) { if (!bStart) { greenCaseWarning.append(QStringLiteral(",
   ")); } bStart = false; greenCaseWarning.append(KEmailAddress::extractEmailAddress(*it)); } } } else { greenCaseWarning = QStringLiteral("") +i18nc("Start of warning message.", "Warning:") +QStringLiteral(" ") +i18n("No mail address is stored in the %1 used for signing, " "so we cannot compare it to the sender's address %2.", certificate, msgFrom); } break; } if (showKeyInfos && !cannotCheckSignature) { if (metaData.signer.isEmpty()) { signer.clear(); } else { if (!blockAddrs.empty()) { const QUrl address = KEmailAddress::encodeMailtoUrl(blockAddrs.first()); signer = QStringLiteral("%2").arg(QLatin1String(QUrl :: toPercentEncoding( address . path())), signer); } } } } else { if (metaData.signer.isEmpty() || metaData.technicalProblem) { mClass = QStringLiteral("signWarn"); } else { // HTMLize the signer's user id and create mailto: link signer = MessageCore::StringUtil::quoteHtmlChars(signer, true); signer = QStringLiteral("%1").arg(signer); if (metaData.isGoodSignature) { if (metaData.keyTrust < GpgME::Signature::Marginal) { mClass = QStringLiteral("signOkKeyBad"); } else { mClass = QStringLiteral("signOkKeyOk"); } } else { mClass = QStringLiteral("signErr"); } } } } block.setProperty("onlyShowKeyURL", onlyShowKeyURL); block.setProperty("showKeyInfos", showKeyInfos); block.setProperty("cannotCheckSignature", cannotCheckSignature); block.setProperty("signer", signer); block.setProperty("statusStr", statusStr); block.setProperty("signClass", mClass); block.setProperty("greenCaseWarning", greenCaseWarning); const auto html = t->render(&c); return html; } QString DefaultRendererPrivate::render(const SignedMessagePart::Ptr &mp) { auto htmlWriter = QSharedPointer(new CacheHtmlWriter(mOldWriter)); - const auto metaData = mp->mMetaData; + const auto metaData = *mp->partMetaData(); if (metaData.isSigned || metaData.inProgress) { { HTMLBlock::Ptr aBlock; if (mp->isAttachment()) { aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode())); } htmlWriter->queue(renderSigned(mp)); } return htmlWriter->html; } { HTMLBlock::Ptr aBlock; if (mp->isAttachment()) { aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode())); } if (mp->hasSubParts()) { renderSubParts(mp, htmlWriter); } else if (!metaData.inProgress) { auto part = renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp); if (part) { htmlWriter->queue(part->html()); } } } return htmlWriter->html; } QString DefaultRendererPrivate::render(const EncryptedMessagePart::Ptr &mp) { auto htmlWriter = QSharedPointer(new CacheHtmlWriter(mOldWriter)); - const auto metaData = mp->mMetaData; + const auto metaData = *mp->partMetaData(); if (metaData.isEncrypted || metaData.inProgress) { { HTMLBlock::Ptr aBlock; if (mp->isAttachment()) { aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode())); } htmlWriter->queue(renderEncrypted(mp)); } return htmlWriter->html; } { HTMLBlock::Ptr aBlock; if (mp->isAttachment()) { aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode())); } if (mp->hasSubParts()) { renderSubParts(mp, htmlWriter); } else if (!metaData.inProgress) { auto part = renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp); if (part) { htmlWriter->queue(part->html()); } } } return htmlWriter->html; } QString DefaultRendererPrivate::render(const AlternativeMessagePart::Ptr &mp) { auto htmlWriter = QSharedPointer(new CacheHtmlWriter(mOldWriter)); { HTMLBlock::Ptr aBlock; if (mp->isAttachment()) { aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode())); } auto mode = mp->preferredMode(); if (mode == MimeTreeParser::Util::MultipartPlain && mp->text().trimmed().isEmpty()) { foreach (const auto m, mp->availableModes()) { if (m != MimeTreeParser::Util::MultipartPlain) { mode = m; break; } } } MimeMessagePart::Ptr part(mp->mChildParts.first()); if (mp->mChildParts.contains(mode)) { part = mp->mChildParts[mode]; } htmlWriter->queue(render(part)); } return htmlWriter->html; } QString DefaultRendererPrivate::render(const CertMessagePart::Ptr &mp) { const GpgME::ImportResult &importResult(mp->mImportResult); Grantlee::Template t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral( ":/certmessagepart.html")); Grantlee::Context c = MessageViewer::MessagePartRendererManager::self()->createContext(); QObject block; c.insert(QStringLiteral("block"), &block); block.setProperty("importError", QString::fromLocal8Bit(importResult.error().asString())); block.setProperty("nImp", importResult.numImported()); block.setProperty("nUnc", importResult.numUnchanged()); block.setProperty("nSKImp", importResult.numSecretKeysImported()); block.setProperty("nSKUnc", importResult.numSecretKeysUnchanged()); QVariantList keylist; const auto imports = importResult.imports(); auto end(imports.end()); for (auto it = imports.begin(); it != end; ++it) { QObject *key(new QObject(mp.data())); key->setProperty("error", QString::fromLocal8Bit((*it).error().asString())); key->setProperty("status", (*it).status()); key->setProperty("fingerprint", QLatin1String((*it).fingerprint())); keylist << QVariant::fromValue(key); } auto htmlWriter = QSharedPointer(new CacheHtmlWriter(mOldWriter)); { HTMLBlock::Ptr aBlock; if (mp->isAttachment()) { aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode())); } const auto html = t->render(&c); htmlWriter->queue(html); } return htmlWriter->html; } -QSharedPointer DefaultRendererPrivate::renderWithFactory(QString className, const Interface::MessagePart::Ptr &msgPart) +QSharedPointer DefaultRendererPrivate::renderWithFactory(QString className, const MessagePart::Ptr &msgPart) { if (mRendererFactory) { const auto registry = mRendererFactory->typeRegistry(className); if (registry.size() > 0) { const auto plugin = registry.at(0); return plugin->render(this, msgPart); } } return QSharedPointer(); } -QString DefaultRendererPrivate::renderFactory(const Interface::MessagePart::Ptr &msgPart, const QSharedPointer &htmlWriter) +QString DefaultRendererPrivate::renderFactory(const MessagePart::Ptr &msgPart, const QSharedPointer &htmlWriter) { const QString className = QString::fromUtf8(msgPart->metaObject()->className()); const auto rendered = renderWithFactory(className, msgPart); if (rendered) { const auto parts = rendered->embededParts(); foreach (auto key, parts.keys()) { htmlWriter->embedPart(key, parts.value(key)); } foreach (auto entry, rendered->extraHeader()) { htmlWriter->extraHead(entry); } return rendered->html(); } if (className == QStringLiteral("MimeTreeParser::MessagePartList")) { auto mp = msgPart.dynamicCast(); if (mp) { return render(mp); } } else if (className == QStringLiteral("MimeTreeParser::MimeMessagePart")) { auto mp = msgPart.dynamicCast(); if (mp) { return render(mp); } } else if (className == QStringLiteral("MimeTreeParser::EncapsulatedRfc822MessagePart")) { auto mp = msgPart.dynamicCast(); if (mp) { return render(mp); } } else if (className == QStringLiteral("MimeTreeParser::HtmlMessagePart")) { auto mp = msgPart.dynamicCast(); if (mp) { return render(mp); } } else if (className == QStringLiteral("MimeTreeParser::SignedMessagePart")) { auto mp = msgPart.dynamicCast(); if (mp) { return render(mp); } } else if (className == QStringLiteral("MimeTreeParser::EncryptedMessagePart")) { auto mp = msgPart.dynamicCast(); if (mp) { return render(mp); } } else if (className == QStringLiteral("MimeTreeParser::AlternativeMessagePart")) { auto mp = msgPart.dynamicCast(); if (mp) { return render(mp); } } else if (className == QStringLiteral("MimeTreeParser::CertMessagePart")) { auto mp = msgPart.dynamicCast(); if (mp) { return render(mp); } } else if (auto mp = msgPart.dynamicCast()) { return mp->formatOutput(); } qCWarning(MESSAGEVIEWER_LOG) << "We got a unkonwn classname, using default behaviour for " << className; return QString(); } -DefaultRenderer::DefaultRenderer(const MimeTreeParser::Interface::MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper, MimeTreeParser::HtmlWriter *writer) +DefaultRenderer::DefaultRenderer(const MimeTreeParser::MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper, MimeTreeParser::HtmlWriter *writer) : d(new MimeTreeParser::DefaultRendererPrivate(msgPart, cssHelper, writer, MessagePartRendererFactory::instance())) { } DefaultRenderer::~DefaultRenderer() { delete d; } QString DefaultRenderer::html() const { return d->mHtml; } diff --git a/messageviewer/src/messagepartthemes/default/defaultrenderer.h b/messageviewer/src/messagepartthemes/default/defaultrenderer.h index 6541d874..78941620 100644 --- a/messageviewer/src/messagepartthemes/default/defaultrenderer.h +++ b/messageviewer/src/messagepartthemes/default/defaultrenderer.h @@ -1,51 +1,49 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MESSAGEVIEWER_DEFAULTRENDERER_H__ #define __MESSAGEVIEWER_DEFAULTRENDERER_H__ #include #include namespace MimeTreeParser { class DefaultRendererPrivate; class HtmlWriter; -namespace Interface { class MessagePart; typedef QSharedPointer MessagePartPtr; } -} namespace MessageViewer { class CSSHelperBase; class DefaultRenderer : public MimeTreeParser::Interface::MessagePartRenderer { public: - DefaultRenderer(const MimeTreeParser::Interface::MessagePartPtr &msgPart, CSSHelperBase *cssHelder, MimeTreeParser::HtmlWriter *writer); + DefaultRenderer(const MimeTreeParser::MessagePartPtr &msgPart, CSSHelperBase *cssHelder, MimeTreeParser::HtmlWriter *writer); ~DefaultRenderer(); QString html() const override; private: MimeTreeParser::DefaultRendererPrivate *d; }; } #endif //__MIMETREEPARSER_MAILRENDERER_H__ diff --git a/messageviewer/src/messagepartthemes/default/defaultrenderer_p.h b/messageviewer/src/messagepartthemes/default/defaultrenderer_p.h index fab78296..844b0305 100644 --- a/messageviewer/src/messagepartthemes/default/defaultrenderer_p.h +++ b/messageviewer/src/messagepartthemes/default/defaultrenderer_p.h @@ -1,73 +1,73 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MESSAGEVIEWER_DEFAULTRENDERER_P_H__ #define __MESSAGEVIEWER_DEFAULTRENDERER_P_H__ #include "defaultrenderer.h" #include using namespace MimeTreeParser; using namespace MessageViewer; class CacheHtmlWriter; class PartRendered; namespace MessageViewer { class MessagePartRendererFactory; class CSSHelperBase; class HtmlWriter; } namespace MimeTreeParser { class DefaultRendererPrivate { public: - DefaultRendererPrivate(const Interface::MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper, HtmlWriter *writer, const MessagePartRendererFactory *rendererFactory); + DefaultRendererPrivate(const MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper, HtmlWriter *writer, const MessagePartRendererFactory *rendererFactory); ~DefaultRendererPrivate(); QString alignText(); CSSHelperBase *cssHelper() const; Interface::ObjectTreeSource *source() const; void renderSubParts(const MessagePart::Ptr &msgPart, const QSharedPointer &htmlWriter); QString render(const MessagePartList::Ptr &mp); QString render(const MimeMessagePart::Ptr &mp); QString render(const EncapsulatedRfc822MessagePart::Ptr &mp); QString render(const HtmlMessagePart::Ptr &mp); QString renderEncrypted(const EncryptedMessagePart::Ptr &mp); QString renderSigned(const SignedMessagePart::Ptr &mp); QString render(const SignedMessagePart::Ptr &mp); QString render(const EncryptedMessagePart::Ptr &mp); QString render(const AlternativeMessagePart::Ptr &mp); QString render(const CertMessagePart::Ptr &mp); - QSharedPointer renderWithFactory(QString className, const Interface::MessagePart::Ptr &msgPart); - QString renderFactory(const Interface::MessagePart::Ptr &msgPart, const QSharedPointer &htmlWriter); + QSharedPointer renderWithFactory(QString className, const MessagePart::Ptr &msgPart); + QString renderFactory(const MessagePart::Ptr &msgPart, const QSharedPointer &htmlWriter); QString mHtml; - Interface::MessagePart::Ptr mMsgPart; + MessagePart::Ptr mMsgPart; HtmlWriter *mOldWriter = nullptr; CSSHelperBase *mCSSHelper = nullptr; const MessageViewer::MessagePartRendererFactory *mRendererFactory = nullptr; }; } #endif diff --git a/messageviewer/src/messagepartthemes/default/messagepartrendererbase.h b/messageviewer/src/messagepartthemes/default/messagepartrendererbase.h index 3ccd5ccd..c7a589b0 100644 --- a/messageviewer/src/messagepartthemes/default/messagepartrendererbase.h +++ b/messageviewer/src/messagepartthemes/default/messagepartrendererbase.h @@ -1,58 +1,56 @@ /* Copyright (c) 2017 Sandro Knauß KMail is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. KMail is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifndef __MESSAGEVIEWER_MESSAGEPARTRENDERERBASE_H__ #define __MESSAGEVIEWER_MESSAGEPARTRENDERERBASE_H__ #include "messageviewer_export.h" #include #include #include namespace MimeTreeParser { class DefaultRendererPrivate; -namespace Interface { class MessagePart; typedef QSharedPointer MessagePartPtr; } -} class PartRendered; class MessagePartRendererBase { public: MessagePartRendererBase(); virtual ~MessagePartRendererBase(); - virtual QSharedPointer render(MimeTreeParser::DefaultRendererPrivate *, const MimeTreeParser::Interface::MessagePartPtr &) + virtual QSharedPointer render(MimeTreeParser::DefaultRendererPrivate *, const MimeTreeParser::MessagePartPtr &) const = 0; }; #endif diff --git a/messageviewer/src/messagepartthemes/default/plugins/attachmentmessagepartrenderer.cpp b/messageviewer/src/messagepartthemes/default/plugins/attachmentmessagepartrenderer.cpp index 04b92e89..fa5e722a 100644 --- a/messageviewer/src/messagepartthemes/default/plugins/attachmentmessagepartrenderer.cpp +++ b/messageviewer/src/messagepartthemes/default/plugins/attachmentmessagepartrenderer.cpp @@ -1,114 +1,114 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "attachmentmessagepartrenderer.h" #include "quotehtml.h" #include "utils/mimetype.h" #include "../partrendered.h" #include "../defaultrenderer_p.h" #include "../messagepartrenderermanager.h" #include #include #include #include AttachmentMessagePartRenderer::AttachmentMessagePartRenderer() { } AttachmentMessagePartRenderer::~AttachmentMessagePartRenderer() { } -QSharedPointer AttachmentMessagePartRenderer::render(DefaultRendererPrivate *drp, const MimeTreeParser::Interface::MessagePartPtr &msgPart) +QSharedPointer AttachmentMessagePartRenderer::render(DefaultRendererPrivate *drp, const MimeTreeParser::MessagePartPtr &msgPart) const { auto mp = msgPart.dynamicCast(); if (!mp) { return QSharedPointer(); } KMime::Content *node = mp->mNode; NodeHelper *nodeHelper = mp->mOtp->nodeHelper(); if (mp->isHidden()) { return QSharedPointer(new EmptyPartRendered()); } const auto tmpAsIcon = mp->asIcon(); if (tmpAsIcon == MimeTreeParser::NoIcon) { return drp->renderWithFactory(QStringLiteral("MimeTreeParser::TextMessagePart"), mp); } Grantlee::Template t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral( ":/asiconpart.html")); Grantlee::Context c = MessageViewer::MessagePartRendererManager::self()->createContext(); QObject block; c.insert(QStringLiteral("block"), &block); block.setProperty("showTextFrame", mp->showTextFrame()); block.setProperty("label", MessageCore::StringUtil::quoteHtmlChars(NodeHelper::fileName(node), true)); block.setProperty("comment", MessageCore::StringUtil::quoteHtmlChars(node->contentDescription()-> asUnicodeString(), true)); block.setProperty("link", nodeHelper->asHREF(node, QStringLiteral("body"))); block.setProperty("showLink", mp->showLink()); block.setProperty("dir", drp->alignText()); block.setProperty("iconSize", MessageViewer::MessagePartRendererManager::self()->iconCurrentSize()); block.setProperty("inline", (tmpAsIcon == MimeTreeParser::IconInline)); QString iconPath; if (tmpAsIcon == MimeTreeParser::IconInline) { iconPath = nodeHelper->writeNodeToTempFile(node); } else { iconPath = MessageViewer::Util::iconPathForContent(node, KIconLoader::Desktop); if (iconPath.right(14) == QLatin1String("mime_empty.png")) { nodeHelper->magicSetType(node); iconPath = MessageViewer::Util::iconPathForContent(node, KIconLoader::Desktop); } } block.setProperty("iconPath", QUrl::fromLocalFile(iconPath).url()); const QString name = node->contentType()->name(); QString label = name.isEmpty() ? NodeHelper::fileName(node) : name; QString comment = node->contentDescription()->asUnicodeString(); if (label.isEmpty()) { label = i18nc("display name for an unnamed attachment", "Unnamed"); } label = MessageCore::StringUtil::quoteHtmlChars(label, true); comment = MessageCore::StringUtil::quoteHtmlChars(comment, true); if (label == comment) { comment.clear(); } block.setProperty("label", label); block.setProperty("comment", comment); const auto html = t->render(&c); return QSharedPointer(new HtmlOnlyPartRendered(mp, html)); } diff --git a/messageviewer/src/messagepartthemes/default/plugins/attachmentmessagepartrenderer.h b/messageviewer/src/messagepartthemes/default/plugins/attachmentmessagepartrenderer.h index 65cc935e..f88a23f2 100644 --- a/messageviewer/src/messagepartthemes/default/plugins/attachmentmessagepartrenderer.h +++ b/messageviewer/src/messagepartthemes/default/plugins/attachmentmessagepartrenderer.h @@ -1,36 +1,36 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MESSAGEVIEWER_DEFAULTRENDERER_ATTACHMENTMESSAGEPARTRENDERER_H__ #define __MESSAGEVIEWER_DEFAULTRENDERER_ATTACHMENTMESSAGEPARTRENDERER_H__ #include "../messagepartrendererbase.h" #include class AttachmentMessagePartRenderer : public MessagePartRendererBase { public: AttachmentMessagePartRenderer(); virtual ~AttachmentMessagePartRenderer(); - QSharedPointer render(MimeTreeParser::DefaultRendererPrivate *drp, const MimeTreeParser::Interface::MessagePartPtr &msgPart) + QSharedPointer render(MimeTreeParser::DefaultRendererPrivate *drp, const MimeTreeParser::MessagePartPtr &msgPart) const override; }; #endif diff --git a/messageviewer/src/messagepartthemes/default/plugins/messagepartrenderer.cpp b/messageviewer/src/messagepartthemes/default/plugins/messagepartrenderer.cpp index 8e250821..df72ea9f 100644 --- a/messageviewer/src/messagepartthemes/default/plugins/messagepartrenderer.cpp +++ b/messageviewer/src/messagepartthemes/default/plugins/messagepartrenderer.cpp @@ -1,46 +1,41 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "messagepartrenderer.h" #include "quotehtml.h" #include "../partrendered.h" #include "../defaultrenderer_p.h" MessagePartRenderer::MessagePartRenderer() { } MessagePartRenderer::~MessagePartRenderer() { } QSharedPointer MessagePartRenderer::render( - MimeTreeParser::DefaultRendererPrivate *drp, const MimeTreeParser::Interface::MessagePartPtr &msgPart) const + MimeTreeParser::DefaultRendererPrivate *drp, const MimeTreeParser::MessagePartPtr &msgPart) const { - auto mp = msgPart.dynamicCast(); - if (mp) { - return QSharedPointer(new HtmlOnlyPartRendered(mp, - quotedHTML(mp->text(), - mp->source(), + return QSharedPointer(new HtmlOnlyPartRendered(msgPart, quotedHTML(msgPart->text(), + msgPart->source(), drp->cssHelper()))); - } - return QSharedPointer(); } diff --git a/messageviewer/src/messagepartthemes/default/plugins/messagepartrenderer.h b/messageviewer/src/messagepartthemes/default/plugins/messagepartrenderer.h index fdec0aec..6c15b1b3 100644 --- a/messageviewer/src/messagepartthemes/default/plugins/messagepartrenderer.h +++ b/messageviewer/src/messagepartthemes/default/plugins/messagepartrenderer.h @@ -1,36 +1,36 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MESSAGEVIEWER_DEFAULTRENDERER_MESSAGEPARTRENDERER_H__ #define __MESSAGEVIEWER_DEFAULTRENDERER_MESSAGEPARTRENDERER_H__ #include "../messagepartrendererbase.h" #include class MessagePartRenderer : public MessagePartRendererBase { public: MessagePartRenderer(); virtual ~MessagePartRenderer(); - QSharedPointer render(MimeTreeParser::DefaultRendererPrivate *drp, const MimeTreeParser::Interface::MessagePartPtr &msgPart) + QSharedPointer render(MimeTreeParser::DefaultRendererPrivate *drp, const MimeTreeParser::MessagePartPtr &msgPart) const override; }; #endif diff --git a/messageviewer/src/messagepartthemes/default/plugins/textmessagepartrenderer.cpp b/messageviewer/src/messagepartthemes/default/plugins/textmessagepartrenderer.cpp index 0a373b8c..23ae2055 100644 --- a/messageviewer/src/messagepartthemes/default/plugins/textmessagepartrenderer.cpp +++ b/messageviewer/src/messagepartthemes/default/plugins/textmessagepartrenderer.cpp @@ -1,43 +1,43 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "textmessagepartrenderer.h" #include "quotehtml.h" #include "../partrendered.h" #include "../defaultrenderer_p.h" TextMessagePartRenderer::TextMessagePartRenderer() { } TextMessagePartRenderer::~TextMessagePartRenderer() { } -QSharedPointer TextMessagePartRenderer::render(DefaultRendererPrivate *drp, const MimeTreeParser::Interface::MessagePartPtr &msgPart) +QSharedPointer TextMessagePartRenderer::render(DefaultRendererPrivate *drp, const MimeTreeParser::MessagePartPtr &msgPart) const { auto mp = msgPart.dynamicCast(); if (mp) { return QSharedPointer(new TextPartRendered(mp)); } return QSharedPointer(); } diff --git a/messageviewer/src/messagepartthemes/default/plugins/textmessagepartrenderer.h b/messageviewer/src/messagepartthemes/default/plugins/textmessagepartrenderer.h index cdd73586..4c65a51f 100644 --- a/messageviewer/src/messagepartthemes/default/plugins/textmessagepartrenderer.h +++ b/messageviewer/src/messagepartthemes/default/plugins/textmessagepartrenderer.h @@ -1,36 +1,36 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MESSAGEVIEWER_DEFAULTRENDERER_TEXTMESSAGEPARTRENDERER_H__ #define __MESSAGEVIEWER_DEFAULTRENDERER_TEXTMESSAGEPARTRENDERER_H__ #include "../messagepartrendererbase.h" #include class TextMessagePartRenderer : public MessagePartRendererBase { public: TextMessagePartRenderer(); virtual ~TextMessagePartRenderer(); - QSharedPointer render(MimeTreeParser::DefaultRendererPrivate *drp, const MimeTreeParser::Interface::MessagePartPtr &msgPart) + QSharedPointer render(MimeTreeParser::DefaultRendererPrivate *drp, const MimeTreeParser::MessagePartPtr &msgPart) const override; }; #endif diff --git a/messageviewer/src/viewer/objecttreeemptysource.cpp b/messageviewer/src/viewer/objecttreeemptysource.cpp index 86bcf803..e7dc3c82 100644 --- a/messageviewer/src/viewer/objecttreeemptysource.cpp +++ b/messageviewer/src/viewer/objecttreeemptysource.cpp @@ -1,149 +1,149 @@ /* Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Copyright (c) 2009 Andras Mantia This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "objecttreeemptysource.h" #include "viewer/viewer_p.h" #include "viewer/csshelperbase.h" #include #include #include "messagepartthemes/default/defaultrenderer.h" #include "bodypartformatterfactorysingleton.h" using namespace MessageViewer; namespace MessageViewer { class EmptySourcePrivate { public: EmptySourcePrivate() : mAllowDecryption(false) { } bool mAllowDecryption; }; } EmptySource::EmptySource() : MimeTreeParser::Interface::ObjectTreeSource() , d(new MessageViewer::EmptySourcePrivate) { } EmptySource::~EmptySource() { delete d; } bool EmptySource::decryptMessage() const { return d->mAllowDecryption; } bool EmptySource::htmlLoadExternal() const { return false; } bool EmptySource::showSignatureDetails() const { return false; } void EmptySource::setHtmlMode(MimeTreeParser::Util::HtmlMode mode, const QList &availableModes) { Q_UNUSED(mode); Q_UNUSED(availableModes); } MimeTreeParser::Util::HtmlMode EmptySource::preferredMode() const { return MimeTreeParser::Util::Html; } void EmptySource::setAllowDecryption(bool allowDecryption) { d->mAllowDecryption = allowDecryption; } int EmptySource::levelQuote() const { return 1; } const QTextCodec *EmptySource::overrideCodec() { return nullptr; } QString EmptySource::createMessageHeader(KMime::Message *message) { Q_UNUSED(message); return QString(); //do nothing } const MimeTreeParser::AttachmentStrategy *EmptySource::attachmentStrategy() { return MimeTreeParser::AttachmentStrategy::smart(); } MimeTreeParser::HtmlWriter *EmptySource::htmlWriter() { return nullptr; } CSSHelperBase *EmptySource::cssHelper() { return nullptr; } bool EmptySource::autoImportKeys() const { return true; } bool EmptySource::showEmoticons() const { return false; } bool EmptySource::showExpandQuotesMark() const { return false; } const MimeTreeParser::BodyPartFormatterBaseFactory *EmptySource::bodyPartFormatterFactory() { return bodyPartFormatterBaseFactoryInstance(); } bool EmptySource::isPrinting() const { return false; } MimeTreeParser::Interface::MessagePartRendererPtr EmptySource::messagePartTheme( - MimeTreeParser::Interface::MessagePart::Ptr msgPart) + MimeTreeParser::MessagePartPtr msgPart) { return MimeTreeParser::Interface::MessagePartRenderer::Ptr( new DefaultRenderer(msgPart, cssHelper(), htmlWriter())); } diff --git a/messageviewer/src/viewer/objecttreeemptysource.h b/messageviewer/src/viewer/objecttreeemptysource.h index 35eb8acb..e81003a9 100644 --- a/messageviewer/src/viewer/objecttreeemptysource.h +++ b/messageviewer/src/viewer/objecttreeemptysource.h @@ -1,62 +1,62 @@ /* Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Copyright (c) 2009 Andras Mantia This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MAILVIEWER_OBJECTTREEEMPTYSOURCE_H #define MAILVIEWER_OBJECTTREEEMPTYSOURCE_H #include #include "messageviewer_export.h" class QString; namespace MessageViewer { class CSSHelperBase; /** An ObjectTreeSource that does not work on anything */ class EmptySourcePrivate; class MESSAGEVIEWER_EXPORT EmptySource : public MimeTreeParser::Interface::ObjectTreeSource { public: EmptySource(); ~EmptySource(); bool decryptMessage() const override; bool htmlLoadExternal() const override; bool showSignatureDetails() const override; void setHtmlMode(MimeTreeParser::Util::HtmlMode mode, const QList &availableModes) override; MimeTreeParser::Util::HtmlMode preferredMode() const override; void setAllowDecryption(bool allowDecryption); int levelQuote() const override; const QTextCodec *overrideCodec() override; QString createMessageHeader(KMime::Message *message) override; const MimeTreeParser::AttachmentStrategy *attachmentStrategy() override; MimeTreeParser::HtmlWriter *htmlWriter() override; virtual CSSHelperBase *cssHelper(); bool autoImportKeys() const override; bool showEmoticons() const override; bool showExpandQuotesMark() const override; const MimeTreeParser::BodyPartFormatterBaseFactory *bodyPartFormatterFactory() override; MimeTreeParser::Interface::MessagePartRendererPtr messagePartTheme( - MimeTreeParser::Interface::MessagePartPtr msgPart) override; + MimeTreeParser::MessagePartPtr msgPart) override; bool isPrinting() const override; private: EmptySourcePrivate *const d; }; } #endif diff --git a/messageviewer/src/viewer/objecttreeviewersource.cpp b/messageviewer/src/viewer/objecttreeviewersource.cpp index a8b3d51f..fb81cff8 100644 --- a/messageviewer/src/viewer/objecttreeviewersource.cpp +++ b/messageviewer/src/viewer/objecttreeviewersource.cpp @@ -1,137 +1,137 @@ /* Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Copyright (c) 2009 Andras Mantia This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "objecttreeviewersource.h" #include "csshelper.h" #include "bodypartformatterfactorysingleton.h" #include #include "messagepartthemes/default/defaultrenderer.h" #include "viewer/viewer_p.h" #include "widgets/htmlstatusbar.h" #include "settings/messageviewersettings.h" using namespace MessageViewer; MailViewerSource::MailViewerSource(ViewerPrivate *viewer) : MimeTreeParser::Interface::ObjectTreeSource() , mViewer(viewer) { } MailViewerSource::~MailViewerSource() { } bool MailViewerSource::decryptMessage() const { return mViewer->decryptMessage(); } bool MailViewerSource::htmlLoadExternal() const { return mViewer->htmlLoadExternal(); } bool MailViewerSource::showSignatureDetails() const { return mViewer->mShowSignatureDetails; } void MailViewerSource::setHtmlMode(MimeTreeParser::Util::HtmlMode mode, const QList &availableModes) { mViewer->mColorBar->setAvailableModes(availableModes); mViewer->mColorBar->setMode(mode); } MimeTreeParser::Util::HtmlMode MailViewerSource::preferredMode() const { switch (mViewer->displayFormatMessageOverwrite()) { case MessageViewer::Viewer::UseGlobalSetting: case MessageViewer::Viewer::Unknown: return mViewer->htmlMailGlobalSetting() ? MimeTreeParser::Util::Html : MimeTreeParser::Util ::Normal; case MessageViewer::Viewer::Html: return MimeTreeParser::Util::MultipartHtml; case MessageViewer::Viewer::Text: return MimeTreeParser::Util::MultipartPlain; case MessageViewer::Viewer::ICal: return MimeTreeParser::Util::MultipartIcal; } Q_ASSERT(true); return MimeTreeParser::Util::Html; } int MailViewerSource::levelQuote() const { return mViewer->mLevelQuote; } const QTextCodec *MailViewerSource::overrideCodec() { return mViewer->overrideCodec(); } QString MailViewerSource::createMessageHeader(KMime::Message *message) { return mViewer->writeMsgHeader(message); } const MimeTreeParser::AttachmentStrategy *MailViewerSource::attachmentStrategy() { return mViewer->attachmentStrategy(); } MimeTreeParser::HtmlWriter *MailViewerSource::htmlWriter() { return mViewer->htmlWriter(); } bool MailViewerSource::autoImportKeys() const { return MessageViewer::MessageViewerSettings::self()->autoImportKeys(); } bool MailViewerSource::showEmoticons() const { return mViewer->showEmoticons(); } bool MailViewerSource::showExpandQuotesMark() const { return MessageViewer::MessageViewerSettings::self()->showExpandQuotesMark(); } const MimeTreeParser::BodyPartFormatterBaseFactory *MailViewerSource::bodyPartFormatterFactory() { return bodyPartFormatterBaseFactoryInstance(); } bool MailViewerSource::isPrinting() const { return mViewer->mPrinting; } MimeTreeParser::Interface::MessagePartRendererPtr MailViewerSource::messagePartTheme( - MimeTreeParser::Interface::MessagePart::Ptr msgPart) + MimeTreeParser::MessagePartPtr msgPart) { return MimeTreeParser::Interface::MessagePartRenderer::Ptr( new DefaultRenderer(msgPart, mViewer->cssHelper(), mViewer->htmlWriter())); } diff --git a/messageviewer/src/viewer/objecttreeviewersource.h b/messageviewer/src/viewer/objecttreeviewersource.h index 0cf0ce3f..1ecbda6d 100644 --- a/messageviewer/src/viewer/objecttreeviewersource.h +++ b/messageviewer/src/viewer/objecttreeviewersource.h @@ -1,59 +1,59 @@ /* Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Copyright (c) 2009 Andras Mantia This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MAILVIEWER_OBJECTTREEVIEWERSOURCE_H #define MAILVIEWER_OBJECTTREEVIEWERSOURCE_H #include class QString; namespace MessageViewer { class ViewerPrivate; /** An ObjectTreeParser source working on a MailViewer object */ class MailViewerSource : public MimeTreeParser::Interface::ObjectTreeSource { public: explicit MailViewerSource(ViewerPrivate *viewer); ~MailViewerSource(); bool decryptMessage() const override; bool htmlLoadExternal() const override; bool showSignatureDetails() const override; void setHtmlMode(MimeTreeParser::Util::HtmlMode mode, const QList &availableModes) override; MimeTreeParser::Util::HtmlMode preferredMode() const override; int levelQuote() const override; const QTextCodec *overrideCodec() override; QString createMessageHeader(KMime::Message *message) override; const MimeTreeParser::AttachmentStrategy *attachmentStrategy() override; MimeTreeParser::HtmlWriter *htmlWriter() override; bool autoImportKeys() const override; bool showEmoticons() const override; bool showExpandQuotesMark() const override; const MimeTreeParser::BodyPartFormatterBaseFactory *bodyPartFormatterFactory() override; MimeTreeParser::Interface::MessagePartRendererPtr messagePartTheme( - MimeTreeParser::Interface::MessagePartPtr msgPart) override; + MimeTreeParser::MessagePartPtr msgPart) override; bool isPrinting() const override; private: ViewerPrivate *mViewer = nullptr; }; } #endif diff --git a/mimetreeparser/autotests/setupenv.h b/mimetreeparser/autotests/setupenv.h index 80e5e218..c5e59e83 100644 --- a/mimetreeparser/autotests/setupenv.h +++ b/mimetreeparser/autotests/setupenv.h @@ -1,174 +1,175 @@ /* Copyright (C) 2010 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Copyright (c) 2010 Leo Franchi This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MESSAGECORE_TESTS_UTIL_H #define MESSAGECORE_TESTS_UTIL_H #include #include #include #include +#include #include #include namespace MimeTreeParser { namespace Test { /** * setup a environment variables for tests: * * set LC_ALL to C * * set KDEHOME */ void setupEnv(); // We can't use EmptySource, since we need to control some emelnets of the source for tests to also test // loadExternal and htmlMail. class TestObjectTreeSource : public MimeTreeParser::Interface::ObjectTreeSource { public: TestObjectTreeSource(MimeTreeParser::HtmlWriter *writer) : mWriter(writer) , mAttachmentStrategy(QStringLiteral("smart")) , mPreferredMode(Util::Html) , mHtmlLoadExternal(false) , mDecryptMessage(false) { } MimeTreeParser::HtmlWriter *htmlWriter() override { return mWriter; } bool htmlLoadExternal() const override { return mHtmlLoadExternal; } void setHtmlLoadExternal(bool loadExternal) { mHtmlLoadExternal = loadExternal; } void setAttachmentStrategy(QString strategy) { mAttachmentStrategy = strategy; } const AttachmentStrategy *attachmentStrategy() override { return AttachmentStrategy::create(mAttachmentStrategy); } bool autoImportKeys() const override { return true; } bool showEmoticons() const override { return false; } bool showExpandQuotesMark() const override { return false; } const BodyPartFormatterBaseFactory *bodyPartFormatterFactory() override { return &mBodyPartFormatterBaseFactory; } bool decryptMessage() const override { return mDecryptMessage; } void setAllowDecryption(bool allowDecryption) { mDecryptMessage = allowDecryption; } void setShowSignatureDetails(bool showSignatureDetails) { mShowSignatureDetails = showSignatureDetails; } bool showSignatureDetails() const override { return mShowSignatureDetails; } void setHtmlMode(MimeTreeParser::Util::HtmlMode mode, const QList &availableModes) override { Q_UNUSED(mode); Q_UNUSED(availableModes); } MimeTreeParser::Util::HtmlMode preferredMode() const override { return mPreferredMode; } void setPreferredMode(MimeTreeParser::Util::HtmlMode mode) { mPreferredMode = mode; } int levelQuote() const override { return 1; } const QTextCodec *overrideCodec() override { return nullptr; } QString createMessageHeader(KMime::Message *message) override { Q_UNUSED(message); return QString(); //do nothing } - Interface::MessagePartRenderer::Ptr messagePartTheme(Interface::MessagePart::Ptr msgPart) override + Interface::MessagePartRenderer::Ptr messagePartTheme(MessagePart::Ptr msgPart) override { Q_UNUSED(msgPart); return Interface::MessagePartRenderer::Ptr(); } bool isPrinting() const override { return false; } private: MimeTreeParser::HtmlWriter *mWriter = nullptr; QString mAttachmentStrategy; BodyPartFormatterBaseFactory mBodyPartFormatterBaseFactory; MimeTreeParser::Util::HtmlMode mPreferredMode; bool mHtmlLoadExternal = false; bool mDecryptMessage = false; bool mShowSignatureDetails = false; }; } } #endif diff --git a/mimetreeparser/src/bodyformatter/applicationpgpencrypted.cpp b/mimetreeparser/src/bodyformatter/applicationpgpencrypted.cpp index 466b1ff2..a00875c8 100644 --- a/mimetreeparser/src/bodyformatter/applicationpgpencrypted.cpp +++ b/mimetreeparser/src/bodyformatter/applicationpgpencrypted.cpp @@ -1,86 +1,86 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "applicationpgpencrypted.h" #include "utils.h" #include "viewer/objecttreeparser.h" #include "viewer/messagepart.h" #include #include #include "mimetreeparser_debug.h" using namespace MimeTreeParser; const ApplicationPGPEncryptedBodyPartFormatter *ApplicationPGPEncryptedBodyPartFormatter::self; const Interface::BodyPartFormatter *ApplicationPGPEncryptedBodyPartFormatter::create() { if (!self) { self = new ApplicationPGPEncryptedBodyPartFormatter(); } return self; } -Interface::MessagePart::Ptr ApplicationPGPEncryptedBodyPartFormatter::process(Interface::BodyPart &part) const +MessagePart::Ptr ApplicationPGPEncryptedBodyPartFormatter::process(Interface::BodyPart &part) const { KMime::Content *node(part.content()); if (node->decodedContent().trimmed() != "Version: 1") { qCWarning(MIMETREEPARSER_LOG) << "Unknown PGP Version String:" << node->decodedContent().trimmed(); } if (!part.content()->parent()) { return MessagePart::Ptr(); } KMime::Content *data = findTypeInDirectChilds(part.content()->parent(), "application/octet-stream"); if (!data) { return MessagePart::Ptr(); //new MimeMessagePart(part.objectTreeParser(), node, false)); } part.nodeHelper()->setEncryptionState(node, KMMsgFullyEncrypted); EncryptedMessagePart::Ptr mp(new EncryptedMessagePart(part.objectTreeParser(), data->decodedText(), QGpgME::openpgp(), part.nodeHelper()->fromAsString(data), node)); mp->setIsEncrypted(true); mp->setDecryptMessage(part.source()->decryptMessage()); PartMetaData *messagePart(mp->partMetaData()); if (!part.source()->decryptMessage()) { part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed } else if (KMime::Content *newNode = part.nodeHelper()->decryptedNodeForContent(data)) { // if we already have a decrypted node for this encrypted node, don't do the decryption again return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), newNode, part.objectTreeParser()->showOnlyOneMimePart())); } else { mp->startDecryption(data); if (!messagePart->inProgress) { part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed if (messagePart->isDecryptable && messagePart->isSigned) { part.nodeHelper()->setSignatureState(node, KMMsgFullySigned); } } } return mp; } diff --git a/mimetreeparser/src/bodyformatter/applicationpgpencrypted.h b/mimetreeparser/src/bodyformatter/applicationpgpencrypted.h index 0a684716..31d91ec1 100644 --- a/mimetreeparser/src/bodyformatter/applicationpgpencrypted.h +++ b/mimetreeparser/src/bodyformatter/applicationpgpencrypted.h @@ -1,36 +1,36 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MIMETREEPARSER_BODYFORAMATTER_APPLICATIONPGPENCYPTED_H__ #define __MIMETREEPARSER_BODYFORAMATTER_APPLICATIONPGPENCYPTED_H__ #include "interfaces/bodypartformatter.h" #include "interfaces/bodypart.h" namespace MimeTreeParser { class ApplicationPGPEncryptedBodyPartFormatter : public Interface::BodyPartFormatter { static const ApplicationPGPEncryptedBodyPartFormatter *self; public: - Interface::MessagePart::Ptr process(Interface::BodyPart &part) const override; + MessagePartPtr process(Interface::BodyPart &part) const override; static const Interface::BodyPartFormatter *create(); }; } #endif diff --git a/mimetreeparser/src/bodyformatter/applicationpkcs7mime.cpp b/mimetreeparser/src/bodyformatter/applicationpkcs7mime.cpp index 9b72353b..2d3a50ab 100644 --- a/mimetreeparser/src/bodyformatter/applicationpkcs7mime.cpp +++ b/mimetreeparser/src/bodyformatter/applicationpkcs7mime.cpp @@ -1,176 +1,176 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "applicationpkcs7mime.h" #include "utils.h" #include "viewer/attachmentstrategy.h" #include "viewer/objecttreeparser.h" #include "viewer/messagepart.h" #include #include #include #include "mimetreeparser_debug.h" using namespace MimeTreeParser; const ApplicationPkcs7MimeBodyPartFormatter *ApplicationPkcs7MimeBodyPartFormatter::self; const Interface::BodyPartFormatter *ApplicationPkcs7MimeBodyPartFormatter::create() { if (!self) { self = new ApplicationPkcs7MimeBodyPartFormatter(); } return self; } -Interface::MessagePart::Ptr ApplicationPkcs7MimeBodyPartFormatter::process(Interface::BodyPart &part) const +MessagePart::Ptr ApplicationPkcs7MimeBodyPartFormatter::process(Interface::BodyPart &part) const { KMime::Content *node = part.content(); if (node->head().isEmpty()) { return MessagePart::Ptr(); } const auto smimeCrypto = QGpgME::smime(); if (!smimeCrypto) { return MessagePart::Ptr(); } // we are also registered for octet-stream, in that case stop here if that's not a part for us const auto mt = node->contentType()->mimeType(); const auto isCorrectMimeType = mt == QByteArrayLiteral("application/pkcs7-mime") || mt == QByteArrayLiteral("application/x-pkcs7-mime"); const auto hasCorrectName = mt == QByteArrayLiteral("application/octet-stream") && (node->contentType()->name().endsWith(QLatin1String("p7m")) || node->contentType()->name().endsWith(QLatin1String("p7s")) || node->contentType()->name().endsWith(QLatin1String("p7c"))); if (!isCorrectMimeType && !hasCorrectName) return {}; const QString smimeType = node->contentType()->parameter(QStringLiteral("smime-type")).toLower(); if (smimeType == QLatin1String("certs-only")) { part.processResult()->setNeverDisplayInline(true); CertMessagePart::Ptr mp(new CertMessagePart(part.objectTreeParser(), node, smimeCrypto, part.source()->autoImportKeys())); return mp; } bool isSigned = (smimeType == QLatin1String("signed-data")); bool isEncrypted = (smimeType == QLatin1String("enveloped-data")); // Analyze "signTestNode" node to find/verify a signature. // If zero part.objectTreeParser() verification was successfully done after // decrypting via recursion by insertAndParseNewChildNode(). KMime::Content *signTestNode = isEncrypted ? nullptr : node; // We try decrypting the content // if we either *know* that it is an encrypted message part // or there is neither signed nor encrypted parameter. MessagePart::Ptr mp; if (!isSigned) { if (isEncrypted) { qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime == S/MIME TYPE: enveloped (encrypted) data"; } else { qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - type unknown - enveloped (encrypted) data ?"; } auto _mp = EncryptedMessagePart::Ptr(new EncryptedMessagePart(part.objectTreeParser(), node->decodedText(), smimeCrypto, part.nodeHelper()->fromAsString(node), node)); mp = _mp; _mp->setIsEncrypted(true); _mp->setDecryptMessage(part.source()->decryptMessage()); PartMetaData *messagePart(_mp->partMetaData()); if (!part.source()->decryptMessage()) { isEncrypted = true; signTestNode = nullptr; // PENDING(marc) to be abs. sure, we'd need to have to look at the content } else { _mp->startDecryption(); if (messagePart->isDecryptable) { qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - encryption found - enveloped (encrypted) data !"; isEncrypted = true; part.nodeHelper()->setEncryptionState(node, KMMsgFullyEncrypted); signTestNode = nullptr; } else { // decryption failed, which could be because the part was encrypted but // 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->passphraseError() || (smimeType.isEmpty() && messagePart->isEncrypted)) { isEncrypted = true; signTestNode = nullptr; } if (isEncrypted) { qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - ERROR: COULD NOT DECRYPT enveloped data !"; } else { qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - NO encryption found"; } } } if (isEncrypted) { part.nodeHelper()->setEncryptionState(node, KMMsgFullyEncrypted); } } // We now try signature verification if necessarry. if (signTestNode) { if (isSigned) { qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime == S/MIME TYPE: opaque signed data"; } else { qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - type unknown - opaque signed data ?"; } const QTextCodec *aCodec(part.objectTreeParser()->codecFor(signTestNode)); const QByteArray signaturetext = signTestNode->decodedContent(); auto _mp = SignedMessagePart::Ptr(new SignedMessagePart(part.objectTreeParser(), aCodec->toUnicode(signaturetext), smimeCrypto, part.nodeHelper()->fromAsString(node), signTestNode)); mp = _mp; //mp->setDecryptMessage(part.source()->decryptMessage()); PartMetaData *messagePart(mp->partMetaData()); if (smimeCrypto) { _mp->startVerificationDetached(signaturetext, nullptr, QByteArray()); } else { messagePart->auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED); } if (_mp->isSigned()) { if (!isSigned) { qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - signature found - opaque signed data !"; isSigned = true; } if (signTestNode != node) { part.nodeHelper()->setSignatureState(node, KMMsgFullySigned); } } else { qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - NO signature found :-("; } } return mp; } diff --git a/mimetreeparser/src/bodyformatter/applicationpkcs7mime.h b/mimetreeparser/src/bodyformatter/applicationpkcs7mime.h index 1e1dc75f..8c8e99f0 100644 --- a/mimetreeparser/src/bodyformatter/applicationpkcs7mime.h +++ b/mimetreeparser/src/bodyformatter/applicationpkcs7mime.h @@ -1,36 +1,36 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MIMETREEPARSER_BODYFORAMATTER_APPLICATIONPKCS7MIME_H__ #define __MIMETREEPARSER_BODYFORAMATTER_APPLICATIONPKCS7MIME_H__ #include "interfaces/bodypartformatter.h" #include "interfaces/bodypart.h" namespace MimeTreeParser { class ApplicationPkcs7MimeBodyPartFormatter : public Interface::BodyPartFormatter { static const ApplicationPkcs7MimeBodyPartFormatter *self; public: - Interface::MessagePart::Ptr process(Interface::BodyPart &part) const override; + MessagePartPtr process(Interface::BodyPart &part) const override; static const Interface::BodyPartFormatter *create(); }; } #endif diff --git a/mimetreeparser/src/bodyformatter/mailman.cpp b/mimetreeparser/src/bodyformatter/mailman.cpp index f2cf31e9..fccc0719 100644 --- a/mimetreeparser/src/bodyformatter/mailman.cpp +++ b/mimetreeparser/src/bodyformatter/mailman.cpp @@ -1,172 +1,172 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "mailman.h" #include "utils.h" #include "viewer/objecttreeparser.h" #include "viewer/messagepart.h" #include #include "mimetreeparser_debug.h" using namespace MimeTreeParser; const MailmanBodyPartFormatter *MailmanBodyPartFormatter::self; const Interface::BodyPartFormatter *MailmanBodyPartFormatter::create() { if (!self) { self = new MailmanBodyPartFormatter(); } return self; } bool MailmanBodyPartFormatter::isMailmanMessage(KMime::Content *curNode) const { if (!curNode || curNode->head().isEmpty()) { return false; } if (curNode->hasHeader("X-Mailman-Version")) { return true; } if (KMime::Headers::Base *header = curNode->headerByType("X-Mailer")) { if (header->asUnicodeString().contains(QStringLiteral("MAILMAN"), Qt::CaseInsensitive)) { return true; } } return false; } -Interface::MessagePart::Ptr MailmanBodyPartFormatter::process(Interface::BodyPart &part) const +MessagePart::Ptr MailmanBodyPartFormatter::process(Interface::BodyPart &part) const { KMime::Content *curNode = part.content(); if (!isMailmanMessage(curNode)) { return MessagePart::Ptr(); } const QString str = QString::fromLatin1(curNode->decodedContent()); //### const QLatin1String delim1("--__--__--\n\nMessage:"); const QLatin1String delim2("--__--__--\r\n\r\nMessage:"); const QLatin1String delimZ2("--__--__--\n\n_____________"); const QLatin1String delimZ1("--__--__--\r\n\r\n_____________"); QString partStr, digestHeaderStr; int thisDelim = str.indexOf(delim1, Qt::CaseInsensitive); if (thisDelim == -1) { thisDelim = str.indexOf(delim2, Qt::CaseInsensitive); } if (thisDelim == -1) { return MessagePart::Ptr(); } int nextDelim = str.indexOf(delim1, thisDelim + 1, Qt::CaseInsensitive); if (-1 == nextDelim) { nextDelim = str.indexOf(delim2, thisDelim + 1, Qt::CaseInsensitive); } if (-1 == nextDelim) { nextDelim = str.indexOf(delimZ1, thisDelim + 1, Qt::CaseInsensitive); } if (-1 == nextDelim) { nextDelim = str.indexOf(delimZ2, thisDelim + 1, Qt::CaseInsensitive); } if (nextDelim < 0) { return MessagePart::Ptr(); } //if ( curNode->mRoot ) // curNode = curNode->mRoot; // at least one message found: build a mime tree digestHeaderStr = QStringLiteral("Content-Type: text/plain\nContent-Description: digest header\n\n"); digestHeaderStr += str.midRef(0, thisDelim); MessagePartList::Ptr mpl(new MessagePartList(part.objectTreeParser())); mpl->appendSubPart(createAndParseTempNode(part, part.topLevelContent(), digestHeaderStr.toLatin1().constData(), "Digest Header")); //mReader->queueHtml("


"); // temporarily change curent node's Content-Type // to get our embedded RfC822 messages properly inserted curNode->contentType()->setMimeType("multipart/digest"); while (-1 < nextDelim) { int thisEoL = str.indexOf(QLatin1String("\nMessage:"), thisDelim, Qt::CaseInsensitive); if (-1 < thisEoL) { thisDelim = thisEoL + 1; } else { thisEoL = str.indexOf(QLatin1String("\n_____________"), thisDelim, Qt::CaseInsensitive); if (-1 < thisEoL) { thisDelim = thisEoL + 1; } } thisEoL = str.indexOf(QLatin1Char('\n'), thisDelim); if (-1 < thisEoL) { thisDelim = thisEoL + 1; } else { thisDelim = thisDelim + 1; } //while( thisDelim < cstr.size() && '\n' == cstr[thisDelim] ) // ++thisDelim; partStr = QStringLiteral("Content-Type: message/rfc822\nContent-Description: embedded message\n\n"); partStr += str.midRef(thisDelim, nextDelim - thisDelim); QString subject = QStringLiteral("embedded message"); QString subSearch = QStringLiteral("\nSubject:"); int subPos = partStr.indexOf(subSearch, 0, Qt::CaseInsensitive); if (-1 < subPos) { subject = partStr.mid(subPos + subSearch.length()); thisEoL = subject.indexOf(QLatin1Char('\n')); if (-1 < thisEoL) { subject.truncate(thisEoL); } } qCDebug(MIMETREEPARSER_LOG) << " embedded message found: \"" << subject; mpl->appendSubPart(createAndParseTempNode(part, part.topLevelContent(), partStr.toLatin1().constData(), subject.toLatin1().constData())); //mReader->queueHtml("


"); thisDelim = nextDelim + 1; nextDelim = str.indexOf(delim1, thisDelim, Qt::CaseInsensitive); if (-1 == nextDelim) { nextDelim = str.indexOf(delim2, thisDelim, Qt::CaseInsensitive); } if (-1 == nextDelim) { nextDelim = str.indexOf(delimZ1, thisDelim, Qt::CaseInsensitive); } if (-1 == nextDelim) { nextDelim = str.indexOf(delimZ2, thisDelim, Qt::CaseInsensitive); } } // reset curent node's Content-Type curNode->contentType()->setMimeType("text/plain"); int thisEoL = str.indexOf(QLatin1String("_____________"), thisDelim); if (-1 < thisEoL) { thisDelim = thisEoL; thisEoL = str.indexOf(QLatin1Char('\n'), thisDelim); if (-1 < thisEoL) { thisDelim = thisEoL + 1; } } else { thisDelim = thisDelim + 1; } partStr = QStringLiteral("Content-Type: text/plain\nContent-Description: digest footer\n\n"); partStr += str.midRef(thisDelim); mpl->appendSubPart(createAndParseTempNode(part, part.topLevelContent(), partStr.toLatin1().constData(), "Digest Footer")); return mpl; } diff --git a/mimetreeparser/src/bodyformatter/mailman.h b/mimetreeparser/src/bodyformatter/mailman.h index c8437639..5fea9777 100644 --- a/mimetreeparser/src/bodyformatter/mailman.h +++ b/mimetreeparser/src/bodyformatter/mailman.h @@ -1,39 +1,39 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MIMETREEPARSER_BODYFORAMATTER_MAILMAN_H__ #define __MIMETREEPARSER_BODYFORAMATTER_MAILMAN_H__ #include "interfaces/bodypartformatter.h" #include "interfaces/bodypart.h" namespace MimeTreeParser { class MailmanBodyPartFormatter : public Interface::BodyPartFormatter { static const MailmanBodyPartFormatter *self; public: - Interface::MessagePart::Ptr process(Interface::BodyPart &part) const override; + MessagePartPtr process(Interface::BodyPart &part) const override; static const Interface::BodyPartFormatter *create(); private: bool isMailmanMessage(KMime::Content *curNode) const; }; } #endif diff --git a/mimetreeparser/src/bodyformatter/multipartalternative.cpp b/mimetreeparser/src/bodyformatter/multipartalternative.cpp index 15df69e3..2f84d8f7 100644 --- a/mimetreeparser/src/bodyformatter/multipartalternative.cpp +++ b/mimetreeparser/src/bodyformatter/multipartalternative.cpp @@ -1,83 +1,83 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "multipartalternative.h" #include "utils.h" #include "viewer/objecttreeparser.h" #include "viewer/messagepart.h" #include #include "mimetreeparser_debug.h" using namespace MimeTreeParser; const MultiPartAlternativeBodyPartFormatter *MultiPartAlternativeBodyPartFormatter::self; const Interface::BodyPartFormatter *MultiPartAlternativeBodyPartFormatter::create() { if (!self) { self = new MultiPartAlternativeBodyPartFormatter(); } return self; } -Interface::MessagePart::Ptr MultiPartAlternativeBodyPartFormatter::process(Interface::BodyPart &part) const +MessagePart::Ptr MultiPartAlternativeBodyPartFormatter::process(Interface::BodyPart &part) const { KMime::Content *node = part.content(); if (node->contents().isEmpty()) { return MessagePart::Ptr(); } auto preferredMode = part.source()->preferredMode(); AlternativeMessagePart::Ptr mp(new AlternativeMessagePart(part.objectTreeParser(), node, preferredMode)); if (mp->mChildNodes.isEmpty()) { MimeMessagePart::Ptr _mp(new MimeMessagePart(part.objectTreeParser(), node->contents().at(0), false)); return _mp; } KMime::Content *dataIcal = mp->mChildNodes.contains(Util::MultipartIcal) ? mp->mChildNodes[Util::MultipartIcal] : nullptr; KMime::Content *dataHtml = mp->mChildNodes.contains(Util::MultipartHtml) ? mp->mChildNodes[Util::MultipartHtml] : nullptr; KMime::Content *dataPlain = mp->mChildNodes.contains(Util::MultipartPlain) ? mp->mChildNodes[Util::MultipartPlain] : nullptr; // Make sure that in default ical is prefered over html and plain text if (dataIcal && ((preferredMode != Util::MultipartHtml && preferredMode != Util::MultipartPlain))) { if (dataHtml) { part.nodeHelper()->setNodeProcessed(dataHtml, false); } if (dataPlain) { part.nodeHelper()->setNodeProcessed(dataPlain, false); } preferredMode = Util::MultipartIcal; } else if ((dataHtml && (preferredMode == Util::MultipartHtml || preferredMode == Util::Html)) || (dataHtml && dataPlain && dataPlain->body().isEmpty())) { if (dataPlain) { part.nodeHelper()->setNodeProcessed(dataPlain, false); } preferredMode = Util::MultipartHtml; } else if (!(preferredMode == Util::MultipartHtml) && dataPlain) { part.nodeHelper()->setNodeProcessed(dataHtml, false); preferredMode = Util::MultipartPlain; } part.source()->setHtmlMode(preferredMode, mp->availableModes()); mp->mPreferredMode = preferredMode; return mp; } diff --git a/mimetreeparser/src/bodyformatter/multipartalternative.h b/mimetreeparser/src/bodyformatter/multipartalternative.h index b6dca61f..a97bf42a 100644 --- a/mimetreeparser/src/bodyformatter/multipartalternative.h +++ b/mimetreeparser/src/bodyformatter/multipartalternative.h @@ -1,36 +1,36 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTALTERNATIVE_H__ #define __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTALTERNATIVE_H__ #include "interfaces/bodypartformatter.h" #include "interfaces/bodypart.h" namespace MimeTreeParser { class MultiPartAlternativeBodyPartFormatter : public Interface::BodyPartFormatter { static const MultiPartAlternativeBodyPartFormatter *self; public: - Interface::MessagePart::Ptr process(Interface::BodyPart &part) const override; + MessagePartPtr process(Interface::BodyPart &part) const override; static const Interface::BodyPartFormatter *create(); }; } #endif diff --git a/mimetreeparser/src/bodyformatter/multipartencrypted.cpp b/mimetreeparser/src/bodyformatter/multipartencrypted.cpp index 593cb806..0d21b37f 100644 --- a/mimetreeparser/src/bodyformatter/multipartencrypted.cpp +++ b/mimetreeparser/src/bodyformatter/multipartencrypted.cpp @@ -1,100 +1,100 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "multipartencrypted.h" #include "utils.h" #include "viewer/objecttreeparser.h" #include "viewer/messagepart.h" #include #include #include "mimetreeparser_debug.h" using namespace MimeTreeParser; const MultiPartEncryptedBodyPartFormatter *MultiPartEncryptedBodyPartFormatter::self; const Interface::BodyPartFormatter *MultiPartEncryptedBodyPartFormatter::create() { if (!self) { self = new MultiPartEncryptedBodyPartFormatter(); } return self; } -Interface::MessagePart::Ptr MultiPartEncryptedBodyPartFormatter::process(Interface::BodyPart &part) const +MessagePart::Ptr MultiPartEncryptedBodyPartFormatter::process(Interface::BodyPart &part) const { KMime::Content *node = part.content(); if (node->contents().isEmpty()) { Q_ASSERT(false); return MessagePart::Ptr(); } const QGpgME::Protocol *useThisCryptProto = nullptr; /* ATTENTION: This code is to be replaced by the new 'auto-detect' feature. -------------------------------------- */ KMime::Content *data = findTypeInDirectChilds(node, "application/octet-stream"); if (data) { useThisCryptProto = QGpgME::openpgp(); } if (!data) { data = findTypeInDirectChilds(node, "application/pkcs7-mime"); if (data) { useThisCryptProto = QGpgME::smime(); } } /* --------------------------------------------------------------------------------------------------------------- */ if (!data) { return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), node->contents().at(0), false)); } part.nodeHelper()->setEncryptionState(node, KMMsgFullyEncrypted); EncryptedMessagePart::Ptr mp(new EncryptedMessagePart(part.objectTreeParser(), data->decodedText(), useThisCryptProto, part.nodeHelper()->fromAsString(data), node)); mp->setIsEncrypted(true); mp->setDecryptMessage(part.source()->decryptMessage()); PartMetaData *messagePart(mp->partMetaData()); if (!part.source()->decryptMessage()) { part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed } else if (KMime::Content *newNode = part.nodeHelper()->decryptedNodeForContent(data)) { // if we already have a decrypted node for part.objectTreeParser() encrypted node, don't do the decryption again return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), newNode, true)); } else { mp->startDecryption(data); qCDebug(MIMETREEPARSER_LOG) << "decrypted, signed?:" << messagePart->isSigned; if (!messagePart->inProgress) { part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed } } return mp; } diff --git a/mimetreeparser/src/bodyformatter/multipartencrypted.h b/mimetreeparser/src/bodyformatter/multipartencrypted.h index c731c0d9..456cf434 100644 --- a/mimetreeparser/src/bodyformatter/multipartencrypted.h +++ b/mimetreeparser/src/bodyformatter/multipartencrypted.h @@ -1,36 +1,36 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTENCRYPTED_H__ #define __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTENCRYPTED_H__ #include "interfaces/bodypartformatter.h" #include "interfaces/bodypart.h" namespace MimeTreeParser { class MultiPartEncryptedBodyPartFormatter : public Interface::BodyPartFormatter { static const MultiPartEncryptedBodyPartFormatter *self; public: - Interface::MessagePart::Ptr process(Interface::BodyPart &part) const override; + MessagePartPtr process(Interface::BodyPart &part) const override; static const Interface::BodyPartFormatter *create(); }; } #endif diff --git a/mimetreeparser/src/bodyformatter/multipartmixed.cpp b/mimetreeparser/src/bodyformatter/multipartmixed.cpp index b60432ab..9b2ca6f6 100644 --- a/mimetreeparser/src/bodyformatter/multipartmixed.cpp +++ b/mimetreeparser/src/bodyformatter/multipartmixed.cpp @@ -1,50 +1,50 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "multipartmixed.h" #include "viewer/objecttreeparser.h" #include "viewer/messagepart.h" #include #include "mimetreeparser_debug.h" using namespace MimeTreeParser; const MultiPartMixedBodyPartFormatter *MultiPartMixedBodyPartFormatter::self; const Interface::BodyPartFormatter *MultiPartMixedBodyPartFormatter::create() { if (!self) { self = new MultiPartMixedBodyPartFormatter(); } return self; } -Interface::MessagePart::Ptr MultiPartMixedBodyPartFormatter::process(Interface::BodyPart &part) const +MessagePart::Ptr MultiPartMixedBodyPartFormatter::process(Interface::BodyPart &part) const { if (part.content()->contents().isEmpty()) { return MessagePart::Ptr(); } // normal treatment of the parts in the mp/mixed container MimeMessagePart::Ptr mp(new MimeMessagePart(part.objectTreeParser(), part.content()->contents().at(0), false)); return mp; } diff --git a/mimetreeparser/src/bodyformatter/multipartmixed.h b/mimetreeparser/src/bodyformatter/multipartmixed.h index dd1d4fdc..9000e39b 100644 --- a/mimetreeparser/src/bodyformatter/multipartmixed.h +++ b/mimetreeparser/src/bodyformatter/multipartmixed.h @@ -1,36 +1,36 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTMIXED_H__ #define __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTMIXED_H__ #include "interfaces/bodypartformatter.h" #include "interfaces/bodypart.h" namespace MimeTreeParser { class MultiPartMixedBodyPartFormatter : public Interface::BodyPartFormatter { static const MultiPartMixedBodyPartFormatter *self; public: - Interface::MessagePart::Ptr process(Interface::BodyPart &part) const override; + MessagePartPtr process(Interface::BodyPart &part) const override; static const Interface::BodyPartFormatter *create(); }; } #endif diff --git a/mimetreeparser/src/bodyformatter/multipartsigned.cpp b/mimetreeparser/src/bodyformatter/multipartsigned.cpp index 4a9695c4..ef5a1fcb 100644 --- a/mimetreeparser/src/bodyformatter/multipartsigned.cpp +++ b/mimetreeparser/src/bodyformatter/multipartsigned.cpp @@ -1,103 +1,103 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "multipartsigned.h" #include "viewer/objecttreeparser.h" #include "viewer/messagepart.h" #include #include #include "mimetreeparser_debug.h" #include using namespace MimeTreeParser; const MultiPartSignedBodyPartFormatter *MultiPartSignedBodyPartFormatter::self; const Interface::BodyPartFormatter *MultiPartSignedBodyPartFormatter::create() { if (!self) { self = new MultiPartSignedBodyPartFormatter(); } return self; } -Interface::MessagePart::Ptr MultiPartSignedBodyPartFormatter::process(Interface::BodyPart &part) const +MessagePart::Ptr MultiPartSignedBodyPartFormatter::process(Interface::BodyPart &part) const { KMime::Content *node = part.content(); if (node->contents().size() != 2) { qCDebug(MIMETREEPARSER_LOG) << "mulitpart/signed must have exactly two child parts!" << endl << "processing as multipart/mixed"; if (!node->contents().isEmpty()) { return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), node->contents().at(0), false)); } else { return MessagePart::Ptr(); } } KMime::Content *signedData = node->contents().at(0); KMime::Content *signature = node->contents().at(1); Q_ASSERT(signedData); Q_ASSERT(signature); QString protocolContentType = node->contentType()->parameter(QStringLiteral("protocol")).toLower(); const QString signatureContentType = QLatin1String(signature->contentType()->mimeType().toLower()); if (protocolContentType.isEmpty()) { qCWarning(MIMETREEPARSER_LOG) << "Message doesn't set the protocol for the multipart/signed content-type, " "using content-type of the signature:" << signatureContentType; protocolContentType = signatureContentType; } const QGpgME::Protocol *protocol = nullptr; if (protocolContentType == QLatin1String("application/pkcs7-signature") || protocolContentType == QLatin1String("application/x-pkcs7-signature")) { protocol = QGpgME::smime(); } else if (protocolContentType == QLatin1String("application/pgp-signature") || protocolContentType == QLatin1String("application/x-pgp-signature")) { protocol = QGpgME::openpgp(); } if (!protocol) { return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), signedData, false)); } part.nodeHelper()->setNodeProcessed(signature, true); part.nodeHelper()->setSignatureState(node, KMMsgFullySigned); const QByteArray cleartext = KMime::LFtoCRLF(signedData->encodedContent()); const QTextCodec *aCodec(part.objectTreeParser()->codecFor(signedData)); SignedMessagePart::Ptr mp(new SignedMessagePart(part.objectTreeParser(), aCodec->toUnicode(cleartext), protocol, part.nodeHelper()->fromAsString(node), signature)); PartMetaData *messagePart(mp->partMetaData()); if (protocol) { mp->startVerificationDetached(cleartext, signedData, signature->decodedContent()); } else { messagePart->auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED); } return mp; } diff --git a/mimetreeparser/src/bodyformatter/multipartsigned.h b/mimetreeparser/src/bodyformatter/multipartsigned.h index d0cbdcf4..ed387d46 100644 --- a/mimetreeparser/src/bodyformatter/multipartsigned.h +++ b/mimetreeparser/src/bodyformatter/multipartsigned.h @@ -1,36 +1,36 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTSIGNED_H__ #define __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTSIGNED_H__ #include "interfaces/bodypartformatter.h" #include "interfaces/bodypart.h" namespace MimeTreeParser { class MultiPartSignedBodyPartFormatter : public Interface::BodyPartFormatter { static const MultiPartSignedBodyPartFormatter *self; public: - Interface::MessagePart::Ptr process(Interface::BodyPart &part) const override; + MessagePartPtr process(Interface::BodyPart &part) const override; static const Interface::BodyPartFormatter *create(); }; } #endif diff --git a/mimetreeparser/src/bodyformatter/texthtml.cpp b/mimetreeparser/src/bodyformatter/texthtml.cpp index 02a3d9d7..ec16a936 100644 --- a/mimetreeparser/src/bodyformatter/texthtml.cpp +++ b/mimetreeparser/src/bodyformatter/texthtml.cpp @@ -1,47 +1,47 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "texthtml.h" #include "viewer/attachmentstrategy.h" #include "viewer/objecttreeparser.h" #include "viewer/messagepart.h" #include #include "mimetreeparser_debug.h" using namespace MimeTreeParser; const TextHtmlBodyPartFormatter *TextHtmlBodyPartFormatter::self; const Interface::BodyPartFormatter *TextHtmlBodyPartFormatter::create() { if (!self) { self = new TextHtmlBodyPartFormatter(); } return self; } -Interface::MessagePart::Ptr TextHtmlBodyPartFormatter::process(Interface::BodyPart &part) const +MessagePart::Ptr TextHtmlBodyPartFormatter::process(Interface::BodyPart &part) const { KMime::Content *node = part.content(); HtmlMessagePart::Ptr mp(new HtmlMessagePart(part.objectTreeParser(), node, part.source())); return mp; } diff --git a/mimetreeparser/src/bodyformatter/texthtml.h b/mimetreeparser/src/bodyformatter/texthtml.h index 08f95d9b..73c7f631 100644 --- a/mimetreeparser/src/bodyformatter/texthtml.h +++ b/mimetreeparser/src/bodyformatter/texthtml.h @@ -1,36 +1,36 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MIMETREEPARSER_BODYFORAMATTER_TEXTHTML_H__ #define __MIMETREEPARSER_BODYFORAMATTER_TEXTHTML_H__ #include "interfaces/bodypartformatter.h" #include "interfaces/bodypart.h" namespace MimeTreeParser { class TextHtmlBodyPartFormatter : public Interface::BodyPartFormatter { static const TextHtmlBodyPartFormatter *self; public: - Interface::MessagePart::Ptr process(Interface::BodyPart &part) const override; + MessagePartPtr process(Interface::BodyPart &part) const override; static const Interface::BodyPartFormatter *create(); }; } #endif diff --git a/mimetreeparser/src/bodyformatter/textplain.cpp b/mimetreeparser/src/bodyformatter/textplain.cpp index 1a0941bb..18012878 100644 --- a/mimetreeparser/src/bodyformatter/textplain.cpp +++ b/mimetreeparser/src/bodyformatter/textplain.cpp @@ -1,67 +1,67 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "textplain.h" #include "viewer/attachmentstrategy.h" #include "viewer/objecttreeparser.h" #include "viewer/messagepart.h" #include #include "mimetreeparser_debug.h" using namespace MimeTreeParser; const TextPlainBodyPartFormatter *TextPlainBodyPartFormatter::self; const Interface::BodyPartFormatter *TextPlainBodyPartFormatter::create() { if (!self) { self = new TextPlainBodyPartFormatter(); } return self; } -Interface::MessagePart::Ptr TextPlainBodyPartFormatter::process(Interface::BodyPart &part) const +MessagePart::Ptr TextPlainBodyPartFormatter::process(Interface::BodyPart &part) const { KMime::Content *node = part.content(); const bool isFirstTextPart = (node->topLevel()->textContent() == node); QString label = NodeHelper::fileName(node); const bool bDrawFrame = !isFirstTextPart && !part.objectTreeParser()->showOnlyOneMimePart() && !label.isEmpty(); const QString fileName = part.nodeHelper()->writeNodeToTempFile(node); TextMessagePart::Ptr mp; if (isFirstTextPart) { mp = TextMessagePart::Ptr(new TextMessagePart(part.objectTreeParser(), node, bDrawFrame, fileName.isEmpty(), part.source()->decryptMessage())); } else { mp = TextMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, bDrawFrame, fileName.isEmpty(), part.source()->decryptMessage())); } part.processResult()->setInlineSignatureState(mp->signatureState()); part.processResult()->setInlineEncryptionState(mp->encryptionState()); part.nodeHelper()->setNodeDisplayedEmbedded(node, true); return mp; } diff --git a/mimetreeparser/src/bodyformatter/textplain.h b/mimetreeparser/src/bodyformatter/textplain.h index d50d837d..7b218cef 100644 --- a/mimetreeparser/src/bodyformatter/textplain.h +++ b/mimetreeparser/src/bodyformatter/textplain.h @@ -1,36 +1,36 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MIMETREEPARSER_BODYFORAMATTER_TEXTPLAIN_H__ #define __MIMETREEPARSER_BODYFORAMATTER_TEXTPLAIN_H__ #include "interfaces/bodypartformatter.h" #include "interfaces/bodypart.h" namespace MimeTreeParser { class TextPlainBodyPartFormatter : public Interface::BodyPartFormatter { static const TextPlainBodyPartFormatter *self; public: - Interface::MessagePart::Ptr process(Interface::BodyPart &part) const override; + MessagePartPtr process(Interface::BodyPart &part) const override; static const Interface::BodyPartFormatter *create(); }; } #endif diff --git a/mimetreeparser/src/bodyformatter/utils.cpp b/mimetreeparser/src/bodyformatter/utils.cpp index c85ff60d..bd351eb3 100644 --- a/mimetreeparser/src/bodyformatter/utils.cpp +++ b/mimetreeparser/src/bodyformatter/utils.cpp @@ -1,70 +1,70 @@ /* Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "utils.h" using namespace MimeTreeParser; MimeMessagePart::Ptr MimeTreeParser::createAndParseTempNode(Interface::BodyPart &part, KMime::Content *parentNode, const char *content, const char *cntDesc) { KMime::Content *newNode = new KMime::Content(); newNode->setContent(KMime::CRLFtoLF(content)); newNode->parse(); if (!newNode->head().isEmpty()) { newNode->contentDescription()->from7BitString(cntDesc); } part.nodeHelper()->attachExtraContent(parentNode, newNode); return MimeMessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), newNode, false)); } KMime::Content *MimeTreeParser::findTypeInDirectChilds(KMime::Content *content, const QByteArray &mimeType) { if (mimeType.isEmpty()) { return content; } foreach (auto child, content->contents()) { if ((!child->contentType()->isEmpty()) && (mimeType == child->contentType()->mimeType())) { return child; } } return nullptr; } MessagePart::Ptr MimeTreeParser::toplevelTextNode(MessagePart::Ptr messageTree) { foreach (const auto &mp, messageTree->subParts()) { auto text = mp.dynamicCast(); auto attach = mp.dynamicCast(); if (text && !attach) { return text; } else if (const auto alternative = mp.dynamicCast()) { return alternative; - } else if (const auto m = mp.dynamicCast()) { - auto ret = toplevelTextNode(m); + } else { + auto ret = toplevelTextNode(mp); if (ret) { return ret; } } } return MessagePart::Ptr(); } diff --git a/mimetreeparser/src/interfaces/bodypartformatter.cpp b/mimetreeparser/src/interfaces/bodypartformatter.cpp index eafb46cd..3d7383b7 100644 --- a/mimetreeparser/src/interfaces/bodypartformatter.cpp +++ b/mimetreeparser/src/interfaces/bodypartformatter.cpp @@ -1,108 +1,62 @@ /* -*- mode: C++; c-file-style: "gnu" -*- bodypartformatter.cpp This file is part of KMail's plugin interface. Copyright (c) 2016 Sandro Knauß KMail is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. KMail is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #include "bodypartformatter.h" #include "bodypart.h" #include "viewer/messagepart.h" #include "viewer/objecttreeparser.h" using namespace MimeTreeParser::Interface; -namespace MimeTreeParser { -namespace Interface { -class MessagePartPrivate -{ -public: - MessagePart *mParentPart = nullptr; -}; -} -} - -MessagePart::MessagePart() - : QObject() - , d(new MessagePartPrivate) -{ -} - -MessagePart::~MessagePart() -{ - delete d; -} - -QString MessagePart::text() const -{ - return QString(); -} - -MessagePart *MessagePart::parentPart() const -{ - return d->mParentPart; -} - -void MessagePart::setParentPart(MessagePart *parentPart) -{ - d->mParentPart = parentPart; -} - -QString MessagePart::htmlContent() const -{ - return text(); -} - -QString MessagePart::plaintextContent() const -{ - return text(); -} - BodyPartFormatter::Result BodyPartFormatter::format(BodyPart *part, MimeTreeParser::HtmlWriter *writer) const { Q_UNUSED(part); Q_UNUSED(writer); return Failed; } -MessagePart::Ptr BodyPartFormatter::process(BodyPart&) const +MimeTreeParser::MessagePart::Ptr BodyPartFormatter::process(BodyPart &part) const { - auto mp = MessagePart::Ptr(new LegacyPluginMessagePart); + auto mp = MimeTreeParser::MessagePart::Ptr(new LegacyPluginMessagePart(part.objectTreeParser())); return mp; } BodyPartFormatterPlugin::~BodyPartFormatterPlugin() { } const BodyPartURLHandler *BodyPartFormatterPlugin::urlHandler(int idx) const { Q_UNUSED(idx); return nullptr; } diff --git a/mimetreeparser/src/interfaces/bodypartformatter.h b/mimetreeparser/src/interfaces/bodypartformatter.h index 98d8dbff..d55dec6d 100644 --- a/mimetreeparser/src/interfaces/bodypartformatter.h +++ b/mimetreeparser/src/interfaces/bodypartformatter.h @@ -1,131 +1,110 @@ /* -*- mode: C++; c-file-style: "gnu" -*- bodypartformatter.h This file is part of KMail's plugin interface. Copyright (c) 2004 Marc Mutz , Ingo Kloecker KMail is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. KMail is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifndef __MIMETREEPARSER_INTERFACE_BODYPARTFORMATTER_H__ #define __MIMETREEPARSER_INTERFACE_BODYPARTFORMATTER_H__ #include "mimetreeparser_export.h" #include #include #include "mimetreeparser/objecttreeparser.h" namespace MimeTreeParser { class HtmlWriter; +class MessagePart; +typedef QSharedPointer MessagePartPtr; namespace Interface { class BodyPartURLHandler; class BodyPart; -class MessagePartPrivate; - -class MIMETREEPARSER_EXPORT MessagePart : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString plaintextContent READ plaintextContent) - Q_PROPERTY(QString htmlContent READ htmlContent) -public: - typedef QSharedPointer Ptr; - MessagePart(); - virtual ~MessagePart(); - - virtual QString text() const; - - void setParentPart(MessagePart *parentPart); - MessagePart *parentPart() const; - - virtual QString plaintextContent() const; - virtual QString htmlContent() const; - -private: - MessagePartPrivate *d; -}; class MIMETREEPARSER_EXPORT BodyPartFormatter { public: virtual ~BodyPartFormatter() { } /** @li Ok returned when format() generated some HTML @li NeedContent returned when format() needs the body of the part @li AsIcon returned when the part should be shown iconified @li Failed returned when formatting failed. Currently equivalent to Ok */ enum Result { Ok, NeedContent, AsIcon, Failed }; /** Format body part \a part by generating some HTML and writing that to \a writer. If you a async process and need to send an update information you can use MimeTreeParser::NodeHelper::Update signal with the corresponding instance of BodyPart::nodeHelper() @return the result code (see above) */ virtual Result format(BodyPart *part, MimeTreeParser::HtmlWriter *writer) const; - virtual MessagePart::Ptr process(BodyPart &part) const; + virtual MimeTreeParser::MessagePartPtr process(BodyPart &part) const; }; /** @short interface for BodyPartFormatter plugins The interface is queried by for types, subtypes, and the corresponding bodypart formatter, and the result inserted into the bodypart formatter factory. Subtype alone or both type and subtype may be "*", which is taken as a wildcard, so that e.g. type=text subtype=* matches any text subtype, but with lesser specificity than a concrete mimetype such as text/plain. type=* is only allowed when subtype=*, too. */ class MIMETREEPARSER_EXPORT BodyPartFormatterPlugin { public: virtual ~BodyPartFormatterPlugin(); virtual const BodyPartFormatter *bodyPartFormatter(int idx) const = 0; virtual const BodyPartURLHandler *urlHandler(int idx) const; }; } // namespace Interface } Q_DECLARE_INTERFACE(MimeTreeParser::Interface::BodyPartFormatterPlugin, "org.kde.messageviewer.bodypartformatter/1.0") #endif // __MIMETREEPARSER_INTERFACE_BODYPARTFORMATTER_H__ diff --git a/mimetreeparser/src/interfaces/objecttreesource.h b/mimetreeparser/src/interfaces/objecttreesource.h index 60c4acaf..a870c0f8 100644 --- a/mimetreeparser/src/interfaces/objecttreesource.h +++ b/mimetreeparser/src/interfaces/objecttreesource.h @@ -1,105 +1,105 @@ /* Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Copyright (c) 2009 Andras Mantia This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MIMETREEPARSER_OBJECTTREESOURCE_IF_H__ #define __MIMETREEPARSER_OBJECTTREESOURCE_IF_H__ #include "mimetreeparser_export.h" #include #include #include class QTextCodec; namespace MimeTreeParser { class HtmlWriter; class AttachmentStrategy; class BodyPartFormatterBaseFactory; -namespace Interface { class MessagePart; typedef QSharedPointer MessagePartPtr; +namespace Interface { class MessagePartRenderer; typedef QSharedPointer MessagePartRendererPtr; } } namespace MimeTreeParser { namespace Interface { /** * Interface for object tree sources. * @author Andras Mantia */ class MIMETREEPARSER_EXPORT ObjectTreeSource { public: ObjectTreeSource(); virtual ~ObjectTreeSource(); /** * Sets the type of mail that is currently displayed. Applications can display this * information to the user, for example KMail displays a HTML status bar. * Note: This is not called when the mode is "Normal". */ virtual void setHtmlMode(MimeTreeParser::Util::HtmlMode mode, const QList &availableModes) = 0; /** Return the mode that is the preferred to display */ virtual MimeTreeParser::Util::HtmlMode preferredMode() const = 0; /** Return true if an encrypted mail should be decrypted */ virtual bool decryptMessage() const = 0; /** Return true if external sources should be loaded in a html mail */ virtual bool htmlLoadExternal() const = 0; /** Return true to include the signature details in the generated html */ virtual bool showSignatureDetails() const = 0; virtual int levelQuote() const = 0; /** The override codec that should be used for the mail */ virtual const QTextCodec *overrideCodec() = 0; virtual QString createMessageHeader(KMime::Message *message) = 0; /** Return the wanted attachment startegy */ virtual const AttachmentStrategy *attachmentStrategy() = 0; /** Return the html write object */ virtual HtmlWriter *htmlWriter() = 0; /** should keys be imported automatically **/ virtual bool autoImportKeys() const = 0; virtual bool showEmoticons() const = 0; virtual bool showExpandQuotesMark() const = 0; virtual const BodyPartFormatterBaseFactory *bodyPartFormatterFactory() = 0; virtual MessagePartRendererPtr messagePartTheme(MessagePartPtr msgPart) = 0; virtual bool isPrinting() const = 0; private: Q_DISABLE_COPY(ObjectTreeSource) }; } } #endif diff --git a/mimetreeparser/src/viewer/bodypartformatter.cpp b/mimetreeparser/src/viewer/bodypartformatter.cpp index 068f15c7..ad0ed465 100644 --- a/mimetreeparser/src/viewer/bodypartformatter.cpp +++ b/mimetreeparser/src/viewer/bodypartformatter.cpp @@ -1,188 +1,188 @@ /* -*- c++ -*- bodypartformatter.cpp This file is part of KMail, the KDE mail client. Copyright (c) 2003 Marc Mutz KMail is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. KMail is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #include "mimetreeparser_debug.h" #include "bodyformatter/applicationpgpencrypted.h" #include "bodyformatter/applicationpkcs7mime.h" #include "bodyformatter/mailman.h" #include "bodyformatter/multipartalternative.h" #include "bodyformatter/multipartmixed.h" #include "bodyformatter/multipartencrypted.h" #include "bodyformatter/multipartsigned.h" #include "bodyformatter/texthtml.h" #include "bodyformatter/textplain.h" #include "interfaces/bodypartformatter.h" #include "interfaces/bodypart.h" #include "interfaces/htmlwriter.h" #include "viewer/bodypartformatterbasefactory.h" #include "viewer/bodypartformatterbasefactory_p.h" #include "viewer/attachmentstrategy.h" #include "viewer/objecttreeparser.h" #include "viewer/messagepart.h" #include #include using namespace MimeTreeParser; namespace { class AnyTypeBodyPartFormatter : public MimeTreeParser::Interface::BodyPartFormatter { static const AnyTypeBodyPartFormatter *self; public: - Interface::MessagePart::Ptr process(Interface::BodyPart &part) const override + MessagePart::Ptr process(Interface::BodyPart &part) const override { KMime::Content *node = part.content(); const auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, false, true, part.source()->decryptMessage())); part.processResult()->setInlineSignatureState(mp->signatureState()); part.processResult()->setInlineEncryptionState(mp->encryptionState()); part.processResult()->setNeverDisplayInline(true); mp->setNeverDisplayInline(true); mp->setIsImage(false); return mp; } static const MimeTreeParser::Interface::BodyPartFormatter *create() { if (!self) { self = new AnyTypeBodyPartFormatter(); } return self; } }; const AnyTypeBodyPartFormatter *AnyTypeBodyPartFormatter::self = nullptr; class ImageTypeBodyPartFormatter : public MimeTreeParser::Interface::BodyPartFormatter { static const ImageTypeBodyPartFormatter *self; public: static const MimeTreeParser::Interface::BodyPartFormatter *create() { if (!self) { self = new ImageTypeBodyPartFormatter(); } return self; } - Interface::MessagePart::Ptr process(Interface::BodyPart &part) const override + MessagePart::Ptr process(Interface::BodyPart &part) const override { KMime::Content *node = part.content(); auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, false, true, part.source()->decryptMessage())); mp->setIsImage(true); part.processResult()->setInlineSignatureState(mp->signatureState()); part.processResult()->setInlineEncryptionState(mp->encryptionState()); auto preferredMode = part.source()->preferredMode(); bool isHtmlPreferred = (preferredMode == Util::Html) || (preferredMode == Util::MultipartHtml); if (node->parent() && node->parent()->contentType()->subType() == "related" && isHtmlPreferred && !part.objectTreeParser()->showOnlyOneMimePart()) { QString fileName = part.nodeHelper()->writeNodeToTempFile(node); QString href = QUrl::fromLocalFile(fileName).url(); QByteArray cid = node->contentID()->identifier(); if (part.objectTreeParser()->htmlWriter()) { part.objectTreeParser()->htmlWriter()->embedPart(cid, href); } part.nodeHelper()->setNodeDisplayedEmbedded(node, true); part.nodeHelper()->setNodeDisplayedHidden(node, true); return mp; } // Show it inline if showOnlyOneMimePart(), which means the user clicked the image // in the message structure viewer manually, and therefore wants to see the full image if (part.objectTreeParser()->showOnlyOneMimePart() && !part.processResult()->neverDisplayInline()) { part.nodeHelper()->setNodeDisplayedEmbedded(node, true); } return mp; } }; const ImageTypeBodyPartFormatter *ImageTypeBodyPartFormatter::self = nullptr; class MessageRfc822BodyPartFormatter : public MimeTreeParser::Interface::BodyPartFormatter { static const MessageRfc822BodyPartFormatter *self; public: - Interface::MessagePart::Ptr process(Interface::BodyPart &) const override; + MessagePart::Ptr process(Interface::BodyPart &) const override; static const MimeTreeParser::Interface::BodyPartFormatter *create(); }; const MessageRfc822BodyPartFormatter *MessageRfc822BodyPartFormatter::self; const MimeTreeParser::Interface::BodyPartFormatter *MessageRfc822BodyPartFormatter::create() { if (!self) { self = new MessageRfc822BodyPartFormatter(); } return self; } -Interface::MessagePart::Ptr MessageRfc822BodyPartFormatter::process(Interface::BodyPart &part) const +MessagePart::Ptr MessageRfc822BodyPartFormatter::process(Interface::BodyPart &part) const { const KMime::Message::Ptr message = part.content()->bodyAsMessage(); return MessagePart::Ptr(new EncapsulatedRfc822MessagePart(part.objectTreeParser(), part.content(), message)); } } // anon namespace void BodyPartFormatterBaseFactoryPrivate::messageviewer_create_builtin_bodypart_formatters() { insert(QStringLiteral("application/pkcs7-mime"), ApplicationPkcs7MimeBodyPartFormatter::create()); insert(QStringLiteral("application/x-pkcs7-mime"), ApplicationPkcs7MimeBodyPartFormatter::create()); insert(QStringLiteral("application/pgp-encrypted"), ApplicationPGPEncryptedBodyPartFormatter::create()); insert(QStringLiteral("application/octet-stream"), ApplicationPkcs7MimeBodyPartFormatter::create()); insert(QStringLiteral("application/octet-stream"), AnyTypeBodyPartFormatter::create()); insert(QStringLiteral("text/html"), TextHtmlBodyPartFormatter::create()); insert(QStringLiteral("text/rtf"), AnyTypeBodyPartFormatter::create()); insert(QStringLiteral("text/plain"), MailmanBodyPartFormatter::create()); insert(QStringLiteral("text/plain"), TextPlainBodyPartFormatter::create()); insert(QStringLiteral("image/png"), ImageTypeBodyPartFormatter::create()); insert(QStringLiteral("image/jpeg"), ImageTypeBodyPartFormatter::create()); insert(QStringLiteral("image/gif"), ImageTypeBodyPartFormatter::create()); insert(QStringLiteral("image/svg+xml"), ImageTypeBodyPartFormatter::create()); insert(QStringLiteral("image/bmp"), ImageTypeBodyPartFormatter::create()); insert(QStringLiteral("image/vnd.microsoft.icon"), ImageTypeBodyPartFormatter::create()); insert(QStringLiteral("message/rfc822"), MessageRfc822BodyPartFormatter::create()); insert(QStringLiteral("multipart/alternative"), MultiPartAlternativeBodyPartFormatter::create()); insert(QStringLiteral("multipart/encrypted"), MultiPartEncryptedBodyPartFormatter::create()); insert(QStringLiteral("multipart/signed"), MultiPartSignedBodyPartFormatter::create()); insert(QStringLiteral("multipart/mixed"), MultiPartMixedBodyPartFormatter::create()); } diff --git a/mimetreeparser/src/viewer/messagepart.cpp b/mimetreeparser/src/viewer/messagepart.cpp index a7a175bb..06f3f0e2 100644 --- a/mimetreeparser/src/viewer/messagepart.cpp +++ b/mimetreeparser/src/viewer/messagepart.cpp @@ -1,1316 +1,1347 @@ /* Copyright (c) 2015 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "messagepart.h" #include "mimetreeparser_debug.h" #include "attachmentstrategy.h" #include "cryptohelper.h" #include "objecttreeparser.h" #include "interfaces/htmlwriter.h" #include "job/qgpgmejobexecutor.h" #include "memento/cryptobodypartmemento.h" #include "memento/decryptverifybodypartmemento.h" #include "memento/verifydetachedbodypartmemento.h" #include "memento/verifyopaquebodypartmemento.h" #include "bodyformatter/utils.h" #include #include #include #include #include #include #include #include #include #include #include #include using namespace MimeTreeParser; //------MessagePart----------------------- +namespace MimeTreeParser { +class MessagePartPrivate +{ +public: + MessagePart *mParentPart = nullptr; + QVector mBlocks; + KMime::Content *mAttachmentNode = nullptr; + QString mText; + PartMetaData mMetaData; + bool mRoot = false; +}; +} + MessagePart::MessagePart(ObjectTreeParser *otp, const QString &text) - : mText(text) - , mOtp(otp) - , mAttachmentNode(nullptr) - , mRoot(false) + : mOtp(otp) + , d(new MessagePartPrivate) +{ + d->mText = text; +} + +MessagePart::~MessagePart() = default; + +MessagePart *MessagePart::parentPart() const { + return d->mParentPart; } -MessagePart::~MessagePart() +void MessagePart::setParentPart(MessagePart *parentPart) { + d->mParentPart = parentPart; } -PartMetaData *MessagePart::partMetaData() +QString MessagePart::htmlContent() const { - return &mMetaData; + return text(); +} + +QString MessagePart::plaintextContent() const +{ + return text(); +} + +PartMetaData *MessagePart::partMetaData() const +{ + return &d->mMetaData; } void MessagePart::setAttachmentFlag(KMime::Content *node) { - mAttachmentNode = node; + d->mAttachmentNode = node; } bool MessagePart::isAttachment() const { - return mAttachmentNode; + return d->mAttachmentNode; } KMime::Content *MessagePart::attachmentNode() const { - return mAttachmentNode; + return d->mAttachmentNode; } void MessagePart::setIsRoot(bool root) { - mRoot = root; + d->mRoot = root; } bool MessagePart::isRoot() const { - return mRoot; + return d->mRoot; } QString MessagePart::text() const { - return mText; + return d->mText; } void MessagePart::setText(const QString &text) { - mText = text; + d->mText = text; } bool MessagePart::isHtml() const { return false; } bool MessagePart::isHidden() const { return false; } Interface::ObjectTreeSource *MessagePart::source() const { Q_ASSERT(mOtp); return mOtp->mSource; } void MessagePart::parseInternal(KMime::Content *node, bool onlyOneMimePart) { auto subMessagePart = mOtp->parseObjectTreeInternal(node, onlyOneMimePart); - mRoot = subMessagePart->isRoot(); + d->mRoot = subMessagePart->isRoot(); foreach (const auto &part, subMessagePart->subParts()) { appendSubPart(part); } } QString MessagePart::renderInternalText() const { QString text; foreach (const auto &mp, subParts()) { text += mp->text(); } return text; } void MessagePart::fix() const { foreach (const auto &mp, subParts()) { const auto m = mp.dynamicCast(); if (m) { m->fix(); } } } -void MessagePart::appendSubPart(const Interface::MessagePart::Ptr &messagePart) +void MessagePart::appendSubPart(const MessagePart::Ptr &messagePart) { messagePart->setParentPart(this); - mBlocks.append(messagePart); + d->mBlocks.append(messagePart); } -const QVector &MessagePart::subParts() const +const QVector &MessagePart::subParts() const { - return mBlocks; + return d->mBlocks; } bool MessagePart::hasSubParts() const { - return !mBlocks.isEmpty(); + return !d->mBlocks.isEmpty(); } //-----LegacyMessagePart-------------------- class LegacyHtmlWriter : public HtmlWriter { public: void begin(const QString&) override {} void end() override {} void extraHead(const QString&) override {} void embedPart(const QByteArray&, const QString&) override {} void flush() override {} void queue(const QString &str) override { text += str; } void write(const QString &html) override { text += html; } void reset() override {} QString text; }; -LegacyPluginMessagePart::LegacyPluginMessagePart() - : m_htmlWriter(new LegacyHtmlWriter) +LegacyPluginMessagePart::LegacyPluginMessagePart(ObjectTreeParser *otp) + : MessagePart(otp, QString()) + , m_htmlWriter(new LegacyHtmlWriter) { } LegacyPluginMessagePart::~LegacyPluginMessagePart() { } HtmlWriter* LegacyPluginMessagePart::htmlWriter() const { return m_htmlWriter.get(); } QString LegacyPluginMessagePart::formatOutput() const { return static_cast(m_htmlWriter.get())->text; } //-----MessagePartList---------------------- MessagePartList::MessagePartList(ObjectTreeParser *otp) : MessagePart(otp, QString()) { } MessagePartList::~MessagePartList() { } QString MessagePartList::text() const { return renderInternalText(); } QString MessagePartList::plaintextContent() const { return QString(); } QString MessagePartList::htmlContent() const { return QString(); } //-----TextMessageBlock---------------------- TextMessagePart::TextMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool showLink, bool decryptMessage) : MessagePartList(otp) , mNode(node) , mDrawFrame(drawFrame) , mShowLink(showLink) , mDecryptMessage(decryptMessage) , mIsHidden(false) { if (!mNode) { qCWarning(MIMETREEPARSER_LOG) << "not a valid node"; return; } mIsHidden = mOtp->nodeHelper()->isNodeDisplayedHidden(mNode); parseContent(); } TextMessagePart::~TextMessagePart() { } bool TextMessagePart::decryptMessage() const { return mDecryptMessage; } void TextMessagePart::parseContent() { const auto aCodec = mOtp->codecFor(mNode); const QString &fromAddress = mOtp->nodeHelper()->fromAsString(mNode); mSignatureState = KMMsgNotSigned; mEncryptionState = KMMsgNotEncrypted; const auto blocks = prepareMessageForDecryption(mNode->decodedContent()); const auto cryptProto = QGpgME::openpgp(); if (!blocks.isEmpty()) { /* The (overall) signature/encrypted status is broken * if one unencrypted part is at the beginning or in the middle * because mailmain adds an unencrypted part at the end this should not break the overall status * * That's why we first set the tmp status and if one crypted/signed block comes afterwards, than * the status is set to unencryped */ bool fullySignedOrEncrypted = true; bool fullySignedOrEncryptedTmp = true; for (const auto &block : blocks) { if (!fullySignedOrEncryptedTmp) { fullySignedOrEncrypted = false; } if (block.type() == NoPgpBlock && !block.text().trimmed().isEmpty()) { fullySignedOrEncryptedTmp = false; appendSubPart(MessagePart::Ptr(new MessagePart(mOtp, aCodec->toUnicode(block.text())))); } else if (block.type() == PgpMessageBlock) { EncryptedMessagePart::Ptr mp(new EncryptedMessagePart(mOtp, QString(), cryptProto, fromAddress, nullptr)); mp->setDecryptMessage(decryptMessage()); mp->setIsEncrypted(true); appendSubPart(mp); if (!decryptMessage()) { continue; } mp->startDecryption(block.text(), aCodec); if (mp->partMetaData()->inProgress) { continue; } } else if (block.type() == ClearsignedBlock) { SignedMessagePart::Ptr mp(new SignedMessagePart(mOtp, QString(), cryptProto, fromAddress, nullptr)); appendSubPart(mp); mp->startVerification(block.text(), aCodec); } else { continue; } const auto mp = subParts().last().staticCast(); const PartMetaData *messagePart(mp->partMetaData()); if (!messagePart->isEncrypted && !messagePart->isSigned && !block.text().trimmed().isEmpty()) { mp->setText(aCodec->toUnicode(block.text())); } if (messagePart->isEncrypted) { mEncryptionState = KMMsgPartiallyEncrypted; } if (messagePart->isSigned) { mSignatureState = KMMsgPartiallySigned; } } //Do we have an fully Signed/Encrypted Message? if (fullySignedOrEncrypted) { if (mSignatureState == KMMsgPartiallySigned) { mSignatureState = KMMsgFullySigned; } if (mEncryptionState == KMMsgPartiallyEncrypted) { mEncryptionState = KMMsgFullyEncrypted; } } } } KMMsgEncryptionState TextMessagePart::encryptionState() const { return mEncryptionState; } KMMsgSignatureState TextMessagePart::signatureState() const { return mSignatureState; } bool TextMessagePart::isHidden() const { return mIsHidden; } bool TextMessagePart::showLink() const { return mShowLink; } bool TextMessagePart::showTextFrame() const { return mDrawFrame; } //-----AttachmentMessageBlock---------------------- AttachmentMessagePart::AttachmentMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool showLink, bool decryptMessage) : TextMessagePart(otp, node, drawFrame, showLink, decryptMessage) , mIsImage(false) , mNeverDisplayInline(false) { } AttachmentMessagePart::~AttachmentMessagePart() { } bool AttachmentMessagePart::neverDisplayInline() const { return mNeverDisplayInline; } void AttachmentMessagePart::setNeverDisplayInline(bool displayInline) { mNeverDisplayInline = displayInline; } bool AttachmentMessagePart::isImage() const { return mIsImage; } void AttachmentMessagePart::setIsImage(bool image) { mIsImage = image; } IconType AttachmentMessagePart::asIcon() const { const AttachmentStrategy *const as = mOtp->attachmentStrategy(); const bool defaultHidden(as && as->defaultDisplay(mNode) == AttachmentStrategy::None); const bool showOnlyOneMimePart(mOtp->showOnlyOneMimePart()); auto preferredMode = source()->preferredMode(); bool isHtmlPreferred = (preferredMode == Util::Html) || (preferredMode == Util::MultipartHtml); QByteArray mediaType("text"); if (mNode->contentType(false) && !mNode->contentType()->mediaType().isEmpty() && !mNode->contentType()->subType().isEmpty()) { mediaType = mNode->contentType()->mediaType(); } const bool isTextPart = (mediaType == QByteArrayLiteral("text")); bool defaultAsIcon = true; if (!neverDisplayInline()) { if (as) { defaultAsIcon = as->defaultDisplay(mNode) == AttachmentStrategy::AsIcon; } } if (isImage() && showOnlyOneMimePart && !neverDisplayInline()) { defaultAsIcon = false; } // neither image nor text -> show as icon if (!isImage() && !isTextPart) { defaultAsIcon = true; } if (isTextPart) { if (as && as->defaultDisplay(mNode) != AttachmentStrategy::Inline) { return MimeTreeParser::IconExternal; } return MimeTreeParser::NoIcon; } else { if (isImage() && isHtmlPreferred && mNode->parent() && mNode->parent()->contentType()->subType() == "related") { return MimeTreeParser::IconInline; } if (defaultHidden && !showOnlyOneMimePart && mNode->parent()) { return MimeTreeParser::IconInline; } if (defaultAsIcon) { return MimeTreeParser::IconExternal; } else if (isImage()) { return MimeTreeParser::IconInline; } else { return MimeTreeParser::NoIcon; } } } bool AttachmentMessagePart::isHidden() const { if (mOtp->showOnlyOneMimePart()) return false; // never hide when only showing one part, otherwise you'll see nothing const AttachmentStrategy *const as = mOtp->attachmentStrategy(); const bool defaultHidden(as && as->defaultDisplay(mNode) == AttachmentStrategy::None); auto preferredMode = source()->preferredMode(); bool isHtmlPreferred = (preferredMode == Util::Html) || (preferredMode == Util::MultipartHtml); QByteArray mediaType("text"); if (mNode->contentType(false) && !mNode->contentType()->mediaType().isEmpty() && !mNode->contentType()->subType().isEmpty()) { mediaType = mNode->contentType()->mediaType(); } const bool isTextPart = (mediaType == QByteArrayLiteral("text")); bool defaultAsIcon = true; if (!neverDisplayInline()) { if (as) { defaultAsIcon = as->defaultDisplay(mNode) == AttachmentStrategy::AsIcon; } } // neither image nor text -> show as icon if (!isImage() && !isTextPart) { defaultAsIcon = true; } bool hidden(false); if (isTextPart) { hidden = defaultHidden; } else { if (isImage() && isHtmlPreferred && mNode->parent() && mNode->parent()->contentType()->subType() == "related") { hidden = true; } else { hidden = defaultHidden && mNode->parent(); hidden |= defaultAsIcon && defaultHidden; } } mOtp->nodeHelper()->setNodeDisplayedHidden(mNode, hidden); return hidden; } //-----HtmlMessageBlock---------------------- HtmlMessagePart::HtmlMessagePart(ObjectTreeParser *otp, KMime::Content *node, Interface::ObjectTreeSource *source) : MessagePart(otp, QString()) , mNode(node) , mSource(source) { if (!mNode) { qCWarning(MIMETREEPARSER_LOG) << "not a valid node"; return; } const QByteArray partBody(mNode->decodedContent()); mBodyHTML = mOtp->codecFor(mNode)->toUnicode(partBody); mCharset = NodeHelper::charset(mNode); } HtmlMessagePart::~HtmlMessagePart() { } void HtmlMessagePart::fix() const { mOtp->mHtmlContent += mBodyHTML; mOtp->mHtmlContentCharset = mCharset; } QString HtmlMessagePart::text() const { return mBodyHTML; } bool HtmlMessagePart::isHtml() const { return true; } //-----MimeMessageBlock---------------------- MimeMessagePart::MimeMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool onlyOneMimePart) : MessagePart(otp, QString()) , mNode(node) , mOnlyOneMimePart(onlyOneMimePart) { if (!mNode) { qCWarning(MIMETREEPARSER_LOG) << "not a valid node"; return; } parseInternal(mNode, mOnlyOneMimePart); } MimeMessagePart::~MimeMessagePart() { } QString MimeMessagePart::text() const { return renderInternalText(); } QString MimeMessagePart::plaintextContent() const { return QString(); } QString MimeMessagePart::htmlContent() const { return QString(); } //-----AlternativeMessagePart---------------------- AlternativeMessagePart::AlternativeMessagePart(ObjectTreeParser *otp, KMime::Content *node, Util::HtmlMode preferredMode) : MessagePart(otp, QString()) , mNode(node) , mPreferredMode(preferredMode) { KMime::Content *dataIcal = findTypeInDirectChilds(mNode, "text/calendar"); KMime::Content *dataHtml = findTypeInDirectChilds(mNode, "text/html"); KMime::Content *dataText = findTypeInDirectChilds(mNode, "text/plain"); if (!dataHtml) { // If we didn't find the HTML part as the first child of the multipart/alternative, it might // be that this is a HTML message with images, and text/plain and multipart/related are the // immediate children of this multipart/alternative node. // In this case, the HTML node is a child of multipart/related. dataHtml = findTypeInDirectChilds(mNode, "multipart/related"); // Still not found? Stupid apple mail actually puts the attachments inside of the // multipart/alternative, which is wrong. Therefore we also have to look for multipart/mixed // here. // Do this only when prefering HTML mail, though, since otherwise the attachments are hidden // when displaying plain text. if (!dataHtml) { dataHtml = findTypeInDirectChilds(mNode, "multipart/mixed"); } } if (dataIcal) { mChildNodes[Util::MultipartIcal] = dataIcal; } if (dataText) { mChildNodes[Util::MultipartPlain] = dataText; } if (dataHtml) { mChildNodes[Util::MultipartHtml] = dataHtml; } if (mChildNodes.isEmpty()) { qCWarning(MIMETREEPARSER_LOG) << "no valid nodes"; return; } QMapIterator i(mChildNodes); while (i.hasNext()) { i.next(); mChildParts[i.key()] = MimeMessagePart::Ptr(new MimeMessagePart(mOtp, i.value(), true)); } } AlternativeMessagePart::~AlternativeMessagePart() { } Util::HtmlMode AlternativeMessagePart::preferredMode() const { return mPreferredMode; } QList AlternativeMessagePart::availableModes() { return mChildParts.keys(); } QString AlternativeMessagePart::text() const { if (mChildParts.contains(Util::MultipartPlain)) { return mChildParts[Util::MultipartPlain]->text(); } return QString(); } void AlternativeMessagePart::fix() const { if (mChildParts.contains(Util::MultipartPlain)) { mChildParts[Util::MultipartPlain]->fix(); } const auto mode = preferredMode(); if (mode != Util::MultipartPlain && mChildParts.contains(mode)) { mChildParts[mode]->fix(); } } bool AlternativeMessagePart::isHtml() const { return mChildParts.contains(Util::MultipartHtml); } QString AlternativeMessagePart::plaintextContent() const { return text(); } QString AlternativeMessagePart::htmlContent() const { if (mChildParts.contains(Util::MultipartHtml)) { return mChildParts[Util::MultipartHtml]->text(); } else { return plaintextContent(); } } //-----CertMessageBlock---------------------- CertMessagePart::CertMessagePart(ObjectTreeParser *otp, KMime::Content *node, const QGpgME::Protocol *cryptoProto, bool autoImport) : MessagePart(otp, QString()) , mNode(node) , mAutoImport(autoImport) , mCryptoProto(cryptoProto) { if (!mNode) { qCWarning(MIMETREEPARSER_LOG) << "not a valid node"; return; } if (!mAutoImport) { return; } const QByteArray certData = node->decodedContent(); QGpgME::ImportJob *import = mCryptoProto->importJob(); QGpgMEJobExecutor executor; mImportResult = executor.exec(import, certData); } CertMessagePart::~CertMessagePart() { } QString CertMessagePart::text() const { return QString(); } //-----SignedMessageBlock--------------------- SignedMessagePart::SignedMessagePart(ObjectTreeParser *otp, const QString &text, const QGpgME::Protocol *cryptoProto, const QString &fromAddress, KMime::Content *node) : MessagePart(otp, text) , mCryptoProto(cryptoProto) , mFromAddress(fromAddress) , mNode(node) { - mMetaData.technicalProblem = (mCryptoProto == nullptr); - mMetaData.isSigned = true; - mMetaData.isGoodSignature = false; - mMetaData.keyTrust = GpgME::Signature::Unknown; - mMetaData.status = i18n("Wrong Crypto Plug-In."); - mMetaData.status_code = GPGME_SIG_STAT_NONE; + partMetaData()->technicalProblem = (mCryptoProto == nullptr); + partMetaData()->isSigned = true; + partMetaData()->isGoodSignature = false; + partMetaData()->keyTrust = GpgME::Signature::Unknown; + partMetaData()->status = i18n("Wrong Crypto Plug-In."); + partMetaData()->status_code = GPGME_SIG_STAT_NONE; } SignedMessagePart::~SignedMessagePart() { } void SignedMessagePart::setIsSigned(bool isSigned) { - mMetaData.isSigned = isSigned; + partMetaData()->isSigned = isSigned; } bool SignedMessagePart::isSigned() const { - return mMetaData.isSigned; + return partMetaData()->isSigned; } bool SignedMessagePart::okVerify(const QByteArray &data, const QByteArray &signature, KMime::Content *textNode) { NodeHelper *nodeHelper = mOtp->nodeHelper(); - mMetaData.isSigned = false; - mMetaData.technicalProblem = (mCryptoProto == nullptr); - mMetaData.keyTrust = GpgME::Signature::Unknown; - mMetaData.status = i18n("Wrong Crypto Plug-In."); - mMetaData.status_code = GPGME_SIG_STAT_NONE; + partMetaData()->isSigned = false; + partMetaData()->technicalProblem = (mCryptoProto == nullptr); + partMetaData()->keyTrust = GpgME::Signature::Unknown; + partMetaData()->status = i18n("Wrong Crypto Plug-In."); + partMetaData()->status_code = GPGME_SIG_STAT_NONE; const QByteArray mementoName = "verification"; CryptoBodyPartMemento *m = dynamic_cast(nodeHelper->bodyPartMemento(mNode, mementoName)); Q_ASSERT(!m || mCryptoProto); //No CryptoPlugin and having a bodyPartMemento -> there is something completely wrong if (!m && mCryptoProto) { if (!signature.isEmpty()) { QGpgME::VerifyDetachedJob *job = mCryptoProto->verifyDetachedJob(); if (job) { m = new VerifyDetachedBodyPartMemento(job, mCryptoProto->keyListJob(), signature, data); } } else { QGpgME::VerifyOpaqueJob *job = mCryptoProto->verifyOpaqueJob(); if (job) { m = new VerifyOpaqueBodyPartMemento(job, mCryptoProto->keyListJob(), data); } } if (m) { if (mOtp->allowAsync()) { QObject::connect(m, &CryptoBodyPartMemento::update, nodeHelper, &NodeHelper::update); if (m->start()) { - mMetaData.inProgress = true; + partMetaData()->inProgress = true; mOtp->mHasPendingAsyncJobs = true; } } else { m->exec(); } nodeHelper->setBodyPartMemento(mNode, mementoName, m); } } else if (m->isRunning()) { - mMetaData.inProgress = true; + partMetaData()->inProgress = true; mOtp->mHasPendingAsyncJobs = true; } else { - mMetaData.inProgress = false; + partMetaData()->inProgress = false; mOtp->mHasPendingAsyncJobs = false; } - if (m && !mMetaData.inProgress) { + if (m && !partMetaData()->inProgress) { if (!signature.isEmpty()) { mVerifiedText = data; } setVerificationResult(m, textNode); } - if (!m && !mMetaData.inProgress) { + if (!m && !partMetaData()->inProgress) { QString errorMsg; QString cryptPlugLibName; QString cryptPlugDisplayName; if (mCryptoProto) { cryptPlugLibName = mCryptoProto->name(); cryptPlugDisplayName = mCryptoProto->displayName(); } if (!mCryptoProto) { if (cryptPlugDisplayName.isEmpty()) { errorMsg = i18n("No appropriate crypto plug-in was found."); } else { errorMsg = i18nc("%1 is either 'OpenPGP' or 'S/MIME'", "No %1 plug-in was found.", cryptPlugDisplayName); } } else { errorMsg = i18n("Crypto plug-in \"%1\" cannot verify signatures.", cryptPlugLibName); } - mMetaData.errorText = i18n("The message is signed, but the " + partMetaData()->errorText = i18n("The message is signed, but the " "validity of the signature cannot be " "verified.
" "Reason: %1", errorMsg); } - return mMetaData.isSigned; + return partMetaData()->isSigned; } static int signatureToStatus(const GpgME::Signature &sig) { switch (sig.status().code()) { case GPG_ERR_NO_ERROR: return GPGME_SIG_STAT_GOOD; case GPG_ERR_BAD_SIGNATURE: return GPGME_SIG_STAT_BAD; case GPG_ERR_NO_PUBKEY: return GPGME_SIG_STAT_NOKEY; case GPG_ERR_NO_DATA: return GPGME_SIG_STAT_NOSIG; case GPG_ERR_SIG_EXPIRED: return GPGME_SIG_STAT_GOOD_EXP; case GPG_ERR_KEY_EXPIRED: return GPGME_SIG_STAT_GOOD_EXPKEY; default: return GPGME_SIG_STAT_ERROR; } } QString prettifyDN(const char *uid) { return QGpgME::DN(uid).prettyDN(); } void SignedMessagePart::sigStatusToMetaData() { GpgME::Key key; - if (mMetaData.isSigned) { + if (partMetaData()->isSigned) { GpgME::Signature signature = mSignatures.front(); - mMetaData.status_code = signatureToStatus(signature); - mMetaData.isGoodSignature = mMetaData.status_code & GPGME_SIG_STAT_GOOD; + partMetaData()->status_code = signatureToStatus(signature); + partMetaData()->isGoodSignature = partMetaData()->status_code & GPGME_SIG_STAT_GOOD; // save extended signature status flags - mMetaData.sigSummary = signature.summary(); + partMetaData()->sigSummary = signature.summary(); - if (mMetaData.isGoodSignature && !key.keyID()) { + if (partMetaData()->isGoodSignature && !key.keyID()) { // Search for the key by its fingerprint so that we can check for // trust etc. QGpgME::KeyListJob *job = mCryptoProto->keyListJob(false); // local, no sigs if (!job) { qCDebug(MIMETREEPARSER_LOG) << "The Crypto backend does not support listing keys. "; } else { std::vector found_keys; // As we are local it is ok to make this synchronous GpgME::KeyListResult res = job->exec(QStringList(QLatin1String(signature.fingerprint())), false, found_keys); if (res.error()) { qCDebug(MIMETREEPARSER_LOG) << "Error while searching key for Fingerprint: " << signature.fingerprint(); } if (found_keys.size() > 1) { // Should not Happen qCDebug(MIMETREEPARSER_LOG) << "Oops: Found more then one Key for Fingerprint: " << signature.fingerprint(); } if (found_keys.size() != 1) { // Should not Happen at this point qCDebug(MIMETREEPARSER_LOG) << "Oops: Found no Key for Fingerprint: " << signature.fingerprint(); } else { key = found_keys[0]; } delete job; } } if (key.keyID()) { - mMetaData.keyId = key.keyID(); + partMetaData()->keyId = key.keyID(); } - if (mMetaData.keyId.isEmpty()) { - mMetaData.keyId = signature.fingerprint(); + if (partMetaData()->keyId.isEmpty()) { + partMetaData()->keyId = signature.fingerprint(); } - mMetaData.keyTrust = signature.validity(); + partMetaData()->keyTrust = signature.validity(); if (key.numUserIDs() > 0 && key.userID(0).id()) { - mMetaData.signer = prettifyDN(key.userID(0).id()); + partMetaData()->signer = prettifyDN(key.userID(0).id()); } for (uint iMail = 0; iMail < key.numUserIDs(); ++iMail) { // The following if /should/ always result in TRUE but we // won't trust implicitely the plugin that gave us these data. if (key.userID(iMail).email()) { QString email = QString::fromUtf8(key.userID(iMail).email()); // ### work around gpgme 0.3.QString text() const override;x / cryptplug bug where the // ### email addresses are specified as angle-addr, not addr-spec: if (email.startsWith(QLatin1Char('<')) && email.endsWith(QLatin1Char('>'))) { email = email.mid(1, email.length() - 2); } if (!email.isEmpty()) { - mMetaData.signerMailAddresses.append(email); + partMetaData()->signerMailAddresses.append(email); } } } if (signature.creationTime()) { - mMetaData.creationTime.setTime_t(signature.creationTime()); + partMetaData()->creationTime.setTime_t(signature.creationTime()); } else { - mMetaData.creationTime = QDateTime(); + partMetaData()->creationTime = QDateTime(); } - if (mMetaData.signer.isEmpty()) { + if (partMetaData()->signer.isEmpty()) { if (key.numUserIDs() > 0 && key.userID(0).name()) { - mMetaData.signer = prettifyDN(key.userID(0).name()); + partMetaData()->signer = prettifyDN(key.userID(0).name()); } - if (!mMetaData.signerMailAddresses.empty()) { - if (mMetaData.signer.isEmpty()) { - mMetaData.signer = mMetaData.signerMailAddresses.front(); + if (!partMetaData()->signerMailAddresses.empty()) { + if (partMetaData()->signer.isEmpty()) { + partMetaData()->signer = partMetaData()->signerMailAddresses.front(); } else { - mMetaData.signer += QLatin1String(" <") + mMetaData.signerMailAddresses.front() + QLatin1Char('>'); + partMetaData()->signer += QLatin1String(" <") + partMetaData()->signerMailAddresses.front() + QLatin1Char('>'); } } } } } void SignedMessagePart::startVerification(const QByteArray &text, const QTextCodec *aCodec) { startVerificationDetached(text, nullptr, QByteArray()); - if (!mNode && mMetaData.isSigned) { + if (!mNode && partMetaData()->isSigned) { setText(aCodec->toUnicode(mVerifiedText)); } } void SignedMessagePart::startVerificationDetached(const QByteArray &text, KMime::Content *textNode, const QByteArray &signature) { - mMetaData.isEncrypted = false; - mMetaData.isDecryptable = false; + partMetaData()->isEncrypted = false; + partMetaData()->isDecryptable = false; if (textNode) { parseInternal(textNode, false); } okVerify(text, signature, textNode); - if (!mMetaData.isSigned) { - mMetaData.creationTime = QDateTime(); + if (!partMetaData()->isSigned) { + partMetaData()->creationTime = QDateTime(); } } void SignedMessagePart::setVerificationResult(const CryptoBodyPartMemento *m, KMime::Content *textNode) { { const auto vm = dynamic_cast(m); if (vm) { mSignatures = vm->verifyResult().signatures(); } } { const auto vm = dynamic_cast(m); if (vm) { mVerifiedText = vm->plainText(); mSignatures = vm->verifyResult().signatures(); } } { const auto vm = dynamic_cast(m); if (vm) { mVerifiedText = vm->plainText(); mSignatures = vm->verifyResult().signatures(); } } - mMetaData.auditLogError = m->auditLogError(); - mMetaData.auditLog = m->auditLogAsHtml(); - mMetaData.isSigned = !mSignatures.empty(); + partMetaData()->auditLogError = m->auditLogError(); + partMetaData()->auditLog = m->auditLogAsHtml(); + partMetaData()->isSigned = !mSignatures.empty(); - if (mMetaData.isSigned) { + if (partMetaData()->isSigned) { sigStatusToMetaData(); if (mNode) { mOtp->nodeHelper()->setSignatureState(mNode, KMMsgFullySigned); if (!textNode) { - mOtp->nodeHelper()->setPartMetaData(mNode, mMetaData); + mOtp->nodeHelper()->setPartMetaData(mNode, *partMetaData()); if (!mVerifiedText.isEmpty()) { auto tempNode = new KMime::Content(); tempNode->setContent(KMime::CRLFtoLF(mVerifiedText.constData())); tempNode->parse(); if (!tempNode->head().isEmpty()) { tempNode->contentDescription()->from7BitString("signed data"); } mOtp->nodeHelper()->attachExtraContent(mNode, tempNode); parseInternal(tempNode, false); } } } } } QString SignedMessagePart::plaintextContent() const { if (!mNode) { return MessagePart::text(); } else { return QString(); } } QString SignedMessagePart::htmlContent() const { if (!mNode) { return MessagePart::text(); } else { return QString(); } } //-----CryptMessageBlock--------------------- EncryptedMessagePart::EncryptedMessagePart(ObjectTreeParser *otp, const QString &text, const QGpgME::Protocol *cryptoProto, const QString &fromAddress, KMime::Content *node) : MessagePart(otp, text) , mPassphraseError(false) , mNoSecKey(false) , mCryptoProto(cryptoProto) , mFromAddress(fromAddress) , mNode(node) , mDecryptMessage(false) { - mMetaData.technicalProblem = (mCryptoProto == nullptr); - mMetaData.isSigned = false; - mMetaData.isGoodSignature = false; - mMetaData.isEncrypted = false; - mMetaData.isDecryptable = false; - mMetaData.keyTrust = GpgME::Signature::Unknown; - mMetaData.status = i18n("Wrong Crypto Plug-In."); - mMetaData.status_code = GPGME_SIG_STAT_NONE; + partMetaData()->technicalProblem = (mCryptoProto == nullptr); + partMetaData()->isSigned = false; + partMetaData()->isGoodSignature = false; + partMetaData()->isEncrypted = false; + partMetaData()->isDecryptable = false; + partMetaData()->keyTrust = GpgME::Signature::Unknown; + partMetaData()->status = i18n("Wrong Crypto Plug-In."); + partMetaData()->status_code = GPGME_SIG_STAT_NONE; } EncryptedMessagePart::~EncryptedMessagePart() { } void EncryptedMessagePart::setDecryptMessage(bool decrypt) { mDecryptMessage = decrypt; } bool EncryptedMessagePart::decryptMessage() const { return mDecryptMessage; } void EncryptedMessagePart::setIsEncrypted(bool encrypted) { - mMetaData.isEncrypted = encrypted; + partMetaData()->isEncrypted = encrypted; } bool EncryptedMessagePart::isEncrypted() const { - return mMetaData.isEncrypted; + return partMetaData()->isEncrypted; } bool EncryptedMessagePart::isDecryptable() const { - return mMetaData.isDecryptable; + return partMetaData()->isDecryptable; } bool EncryptedMessagePart::passphraseError() const { return mPassphraseError; } void EncryptedMessagePart::startDecryption(const QByteArray &text, const QTextCodec *aCodec) { KMime::Content *content = new KMime::Content; content->setBody(text); content->parse(); startDecryption(content); - if (!mMetaData.inProgress && mMetaData.isDecryptable) { + if (!partMetaData()->inProgress && partMetaData()->isDecryptable) { if (hasSubParts()) { auto _mp = (subParts()[0]).dynamicCast(); if (_mp) { _mp->setText(aCodec->toUnicode(mDecryptedData)); } else { setText(aCodec->toUnicode(mDecryptedData)); } } else { setText(aCodec->toUnicode(mDecryptedData)); } } } bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data) { mPassphraseError = false; - mMetaData.inProgress = false; - mMetaData.errorText.clear(); - mMetaData.auditLogError = GpgME::Error(); - mMetaData.auditLog.clear(); + partMetaData()->inProgress = false; + partMetaData()->errorText.clear(); + partMetaData()->auditLogError = GpgME::Error(); + partMetaData()->auditLog.clear(); bool bDecryptionOk = false; bool cannotDecrypt = false; NodeHelper *nodeHelper = mOtp->nodeHelper(); Q_ASSERT(decryptMessage()); // Check whether the memento contains a result from last time: const DecryptVerifyBodyPartMemento *m = dynamic_cast(nodeHelper->bodyPartMemento(&data, "decryptverify")); Q_ASSERT(!m || mCryptoProto); //No CryptoPlugin and having a bodyPartMemento -> there is something completely wrong if (!m && mCryptoProto) { QGpgME::DecryptVerifyJob *job = mCryptoProto->decryptVerifyJob(); if (!job) { cannotDecrypt = true; } else { const QByteArray ciphertext = data.decodedContent(); DecryptVerifyBodyPartMemento *newM = new DecryptVerifyBodyPartMemento(job, ciphertext); if (mOtp->allowAsync()) { QObject::connect(newM, &CryptoBodyPartMemento::update, nodeHelper, &NodeHelper::update); if (newM->start()) { - mMetaData.inProgress = true; + partMetaData()->inProgress = true; mOtp->mHasPendingAsyncJobs = true; } else { m = newM; } } else { newM->exec(); m = newM; } nodeHelper->setBodyPartMemento(&data, "decryptverify", newM); } } else if (m->isRunning()) { - mMetaData.inProgress = true; + partMetaData()->inProgress = true; mOtp->mHasPendingAsyncJobs = true; m = nullptr; } if (m) { const QByteArray &plainText = m->plainText(); const GpgME::DecryptionResult &decryptResult = m->decryptResult(); const GpgME::VerificationResult &verifyResult = m->verifyResult(); - mMetaData.isSigned = verifyResult.signatures().size() > 0; + partMetaData()->isSigned = verifyResult.signatures().size() > 0; if (verifyResult.signatures().size() > 0) { auto subPart = SignedMessagePart::Ptr(new SignedMessagePart(mOtp, MessagePart::text(), mCryptoProto, mFromAddress, mNode)); subPart->setVerificationResult(m, nullptr); appendSubPart(subPart); } mDecryptRecipients = decryptResult.recipients(); bDecryptionOk = !decryptResult.error(); // std::stringstream ss; // ss << decryptResult << '\n' << verifyResult; // qCDebug(MIMETREEPARSER_LOG) << ss.str().c_str(); - if (!bDecryptionOk && mMetaData.isSigned) { + if (!bDecryptionOk && partMetaData()->isSigned) { //Only a signed part - mMetaData.isEncrypted = false; + partMetaData()->isEncrypted = false; bDecryptionOk = true; mDecryptedData = plainText; } else { mPassphraseError = decryptResult.error().isCanceled() || decryptResult.error().code() == GPG_ERR_NO_SECKEY; - mMetaData.isEncrypted = decryptResult.error().code() != GPG_ERR_NO_DATA; - mMetaData.errorText = QString::fromLocal8Bit(decryptResult.error().asString()); - if (mMetaData.isEncrypted && decryptResult.numRecipients() > 0) { - mMetaData.keyId = decryptResult.recipient(0).keyID(); + partMetaData()->isEncrypted = decryptResult.error().code() != GPG_ERR_NO_DATA; + partMetaData()->errorText = QString::fromLocal8Bit(decryptResult.error().asString()); + if (partMetaData()->isEncrypted && decryptResult.numRecipients() > 0) { + partMetaData()->keyId = decryptResult.recipient(0).keyID(); } if (bDecryptionOk) { mDecryptedData = plainText; } else { mNoSecKey = true; foreach (const GpgME::DecryptionResult::Recipient &recipient, decryptResult.recipients()) { mNoSecKey &= (recipient.status().code() == GPG_ERR_NO_SECKEY); } if (!mPassphraseError && !mNoSecKey) { // GpgME do not detect passphrase error correctly mPassphraseError = true; } } } } if (!bDecryptionOk) { QString cryptPlugLibName; if (mCryptoProto) { cryptPlugLibName = mCryptoProto->name(); } if (!mCryptoProto) { - mMetaData.errorText = i18n("No appropriate crypto plug-in was found."); + partMetaData()->errorText = i18n("No appropriate crypto plug-in was found."); } else if (cannotDecrypt) { - mMetaData.errorText = i18n("Crypto plug-in \"%1\" cannot decrypt messages.", + partMetaData()->errorText = i18n("Crypto plug-in \"%1\" cannot decrypt messages.", cryptPlugLibName); } else if (!passphraseError()) { - mMetaData.errorText = i18n("Crypto plug-in \"%1\" could not decrypt the data.", cryptPlugLibName) + partMetaData()->errorText = i18n("Crypto plug-in \"%1\" could not decrypt the data.", cryptPlugLibName) + QLatin1String("
") - + i18n("Error: %1", mMetaData.errorText); + + i18n("Error: %1", partMetaData()->errorText); } } return bDecryptionOk; } void EncryptedMessagePart::startDecryption(KMime::Content *data) { if (!mNode && !data) { return; } if (!data) { data = mNode; } - mMetaData.isEncrypted = true; + partMetaData()->isEncrypted = true; bool bOkDecrypt = okDecryptMIME(*data); - if (mMetaData.inProgress) { + if (partMetaData()->inProgress) { return; } - mMetaData.isDecryptable = bOkDecrypt; + partMetaData()->isDecryptable = bOkDecrypt; - if (!mMetaData.isDecryptable) { + if (!partMetaData()->isDecryptable) { setText(QString::fromUtf8(mDecryptedData.constData())); } - if (mMetaData.isEncrypted && !decryptMessage()) { - mMetaData.isDecryptable = true; + if (partMetaData()->isEncrypted && !decryptMessage()) { + partMetaData()->isDecryptable = true; } - if (mNode && !mMetaData.isSigned) { - mOtp->nodeHelper()->setPartMetaData(mNode, mMetaData); + if (mNode && !partMetaData()->isSigned) { + mOtp->nodeHelper()->setPartMetaData(mNode, *partMetaData()); if (decryptMessage()) { auto tempNode = new KMime::Content(); tempNode->setContent(KMime::CRLFtoLF(mDecryptedData.constData())); tempNode->parse(); if (!tempNode->head().isEmpty()) { tempNode->contentDescription()->from7BitString("encrypted data"); } mOtp->nodeHelper()->attachExtraContent(mNode, tempNode); parseInternal(tempNode, false); } } } QString EncryptedMessagePart::plaintextContent() const { if (!mNode) { return MessagePart::text(); } else { return QString(); } } QString EncryptedMessagePart::htmlContent() const { if (!mNode) { return MessagePart::text(); } else { return QString(); } } QString EncryptedMessagePart::text() const { if (hasSubParts()) { auto _mp = (subParts()[0]).dynamicCast(); if (_mp) { return _mp->text(); } else { return MessagePart::text(); } } else { return MessagePart::text(); } } EncapsulatedRfc822MessagePart::EncapsulatedRfc822MessagePart(ObjectTreeParser *otp, KMime::Content *node, const KMime::Message::Ptr &message) : MessagePart(otp, QString()) , mMessage(message) , mNode(node) { - mMetaData.isEncrypted = false; - mMetaData.isSigned = false; - mMetaData.isEncapsulatedRfc822Message = true; + partMetaData()->isEncrypted = false; + partMetaData()->isSigned = false; + partMetaData()->isEncapsulatedRfc822Message = true; mOtp->nodeHelper()->setNodeDisplayedEmbedded(mNode, true); - mOtp->nodeHelper()->setPartMetaData(mNode, mMetaData); + mOtp->nodeHelper()->setPartMetaData(mNode, *partMetaData()); if (!mMessage) { qCWarning(MIMETREEPARSER_LOG) << "Node is of type message/rfc822 but doesn't have a message!"; return; } // The link to "Encapsulated message" is clickable, therefore the temp file needs to exists, // since the user can click the link and expect to have normal attachment operations there. mOtp->nodeHelper()->writeNodeToTempFile(message.data()); parseInternal(message.data(), false); } EncapsulatedRfc822MessagePart::~EncapsulatedRfc822MessagePart() { } QString EncapsulatedRfc822MessagePart::text() const { return renderInternalText(); } void EncapsulatedRfc822MessagePart::fix() const { } diff --git a/mimetreeparser/src/viewer/messagepart.h b/mimetreeparser/src/viewer/messagepart.h index e5015d62..a714ab94 100644 --- a/mimetreeparser/src/viewer/messagepart.h +++ b/mimetreeparser/src/viewer/messagepart.h @@ -1,424 +1,417 @@ /* Copyright (c) 2015 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __MIMETREEPARSER_MESSAGEPART_H__ #define __MIMETREEPARSER_MESSAGEPART_H__ #include "mimetreeparser_export.h" #include "mimetreeparser/bodypartformatter.h" #include "mimetreeparser/util.h" #include #include #include #include #include #include #include class QTextCodec; -class PartPrivate; class TextPartRendered; class AttachmentMessagePartRenderer; namespace GpgME { class ImportResult; } namespace QGpgME { class Protocol; } namespace KMime { class Content; } namespace MimeTreeParser { class ObjectTreeParser; class HtmlWriter; -class HTMLBlock; -typedef QSharedPointer HTMLBlockPtr; class CryptoBodyPartMemento; +class MessagePartPrivate; class MultiPartAlternativeBodyPartFormatter; namespace Interface { class ObjectTreeSource; } -class MIMETREEPARSER_EXPORT MessagePart : public Interface::MessagePart +class MIMETREEPARSER_EXPORT MessagePart : public QObject { Q_OBJECT + Q_PROPERTY(QString plaintextContent READ plaintextContent) + Q_PROPERTY(QString htmlContent READ htmlContent) Q_PROPERTY(bool attachment READ isAttachment) Q_PROPERTY(bool root READ isRoot) Q_PROPERTY(bool isHtml READ isHtml) Q_PROPERTY(bool isHidden READ isHidden) public: typedef QSharedPointer Ptr; MessagePart(ObjectTreeParser *otp, const QString &text); + ~MessagePart(); - virtual ~MessagePart(); + void setParentPart(MessagePart *parentPart); + MessagePart *parentPart() const; - QString text() const override; + virtual QString text() const; void setText(const QString &text); + + virtual QString plaintextContent() const; + virtual QString htmlContent() const; + void setAttachmentFlag(KMime::Content *node); bool isAttachment() const; void setIsRoot(bool root); bool isRoot() const; virtual bool isHtml() const; virtual bool isHidden() const; - PartMetaData *partMetaData(); + PartMetaData *partMetaData() const; /* only a function that should be removed if the refactoring is over */ virtual void fix() const; - void appendSubPart(const Interface::MessagePart::Ptr &messagePart); - const QVector &subParts() const; + void appendSubPart(const MessagePart::Ptr &messagePart); + const QVector &subParts() const; bool hasSubParts() const; Interface::ObjectTreeSource *source() const; KMime::Content *attachmentNode() const; protected: void parseInternal(KMime::Content *node, bool onlyOneMimePart); QString renderInternalText() const; - QString mText; ObjectTreeParser *mOtp = nullptr; - PartMetaData mMetaData; private: - QVector mBlocks; - - KMime::Content *mAttachmentNode = nullptr; - bool mRoot; + std::unique_ptr d; }; // TODO remove once all plugins are ported away from BPF::format() class MIMETREEPARSER_DEPRECATED_EXPORT LegacyPluginMessagePart : public Interface::MessagePart { Q_OBJECT public: - LegacyPluginMessagePart(); + LegacyPluginMessagePart(MimeTreeParser::ObjectTreeParser *otp); ~LegacyPluginMessagePart(); HtmlWriter *htmlWriter() const; QString formatOutput() const; private: std::unique_ptr m_htmlWriter; }; class MIMETREEPARSER_EXPORT MimeMessagePart : public MessagePart { Q_OBJECT public: typedef QSharedPointer Ptr; MimeMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool onlyOneMimePart); virtual ~MimeMessagePart(); QString text() const override; QString plaintextContent() const override; QString htmlContent() const override; private: KMime::Content *mNode; bool mOnlyOneMimePart; friend class AlternativeMessagePart; - friend class ::PartPrivate; }; class MIMETREEPARSER_EXPORT MessagePartList : public MessagePart { Q_OBJECT public: typedef QSharedPointer Ptr; MessagePartList(MimeTreeParser::ObjectTreeParser *otp); virtual ~MessagePartList(); QString text() const override; QString plaintextContent() const override; QString htmlContent() const override; -private: }; enum IconType { NoIcon = 0, IconExternal, IconInline }; class MIMETREEPARSER_EXPORT TextMessagePart : public MessagePartList { Q_OBJECT public: typedef QSharedPointer Ptr; TextMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool showLink, bool decryptMessage); virtual ~TextMessagePart(); KMMsgSignatureState signatureState() const; KMMsgEncryptionState encryptionState() const; bool decryptMessage() const; bool isHidden() const override; bool showLink() const; bool showTextFrame() const; protected: KMime::Content *mNode = nullptr; private: void parseContent(); KMMsgSignatureState mSignatureState; KMMsgEncryptionState mEncryptionState; bool mDrawFrame; bool mShowLink; bool mDecryptMessage; bool mIsHidden; friend class ::TextPartRendered; friend class ::AttachmentMessagePartRenderer; - friend class DefaultRendererPrivate; friend class ObjectTreeParser; - friend class ::PartPrivate; }; class MIMETREEPARSER_EXPORT AttachmentMessagePart : public TextMessagePart { Q_OBJECT public: typedef QSharedPointer Ptr; AttachmentMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool showLink, bool decryptMessage); virtual ~AttachmentMessagePart(); IconType asIcon() const; bool neverDisplayInline() const; void setNeverDisplayInline(bool displayInline); bool isImage() const; void setIsImage(bool image); bool isHidden() const override; private: bool mIsImage; bool mNeverDisplayInline; }; class MIMETREEPARSER_EXPORT HtmlMessagePart : public MessagePart { Q_OBJECT public: typedef QSharedPointer Ptr; HtmlMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, MimeTreeParser::Interface::ObjectTreeSource *source); virtual ~HtmlMessagePart(); QString text() const override; void fix() const override; bool isHtml() const override; private: KMime::Content *mNode; Interface::ObjectTreeSource *mSource; QString mBodyHTML; QByteArray mCharset; friend class DefaultRendererPrivate; - friend class ::PartPrivate; }; class MIMETREEPARSER_EXPORT AlternativeMessagePart : public MessagePart { Q_OBJECT public: typedef QSharedPointer Ptr; AlternativeMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, Util::HtmlMode preferredMode); virtual ~AlternativeMessagePart(); QString text() const override; Util::HtmlMode preferredMode() const; bool isHtml() const override; QString plaintextContent() const override; QString htmlContent() const override; QList availableModes(); void fix() const override; private: KMime::Content *mNode; Util::HtmlMode mPreferredMode; QMap mChildNodes; QMap mChildParts; friend class DefaultRendererPrivate; friend class ObjectTreeParser; friend class MultiPartAlternativeBodyPartFormatter; - friend class ::PartPrivate; }; class MIMETREEPARSER_EXPORT CertMessagePart : public MessagePart { Q_OBJECT public: typedef QSharedPointer Ptr; CertMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, const QGpgME::Protocol *cryptoProto, bool autoImport); virtual ~CertMessagePart(); QString text() const override; private: KMime::Content *mNode; bool mAutoImport; GpgME::ImportResult mImportResult; const QGpgME::Protocol *mCryptoProto; friend class DefaultRendererPrivate; }; class MIMETREEPARSER_EXPORT EncapsulatedRfc822MessagePart : public MessagePart { Q_OBJECT public: typedef QSharedPointer Ptr; EncapsulatedRfc822MessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, const KMime::Message::Ptr &message); virtual ~EncapsulatedRfc822MessagePart(); QString text() const override; void fix() const override; private: const KMime::Message::Ptr mMessage; KMime::Content *mNode; friend class DefaultRendererPrivate; }; class MIMETREEPARSER_EXPORT EncryptedMessagePart : public MessagePart { Q_OBJECT Q_PROPERTY(bool decryptMessage READ decryptMessage WRITE setDecryptMessage) Q_PROPERTY(bool isEncrypted READ isEncrypted) Q_PROPERTY(bool passphraseError READ passphraseError) public: typedef QSharedPointer Ptr; EncryptedMessagePart(ObjectTreeParser *otp, const QString &text, const QGpgME::Protocol *cryptoProto, const QString &fromAddress, KMime::Content *node); virtual ~EncryptedMessagePart(); QString text() const override; void setDecryptMessage(bool decrypt); bool decryptMessage() const; void setIsEncrypted(bool encrypted); bool isEncrypted() const; bool isDecryptable() const; bool passphraseError() const; void startDecryption(const QByteArray &text, const QTextCodec *aCodec); void startDecryption(KMime::Content *data = nullptr); QByteArray mDecryptedData; QString plaintextContent() const override; QString htmlContent() const override; private: /** Handles the dectyptioon of a given content * returns true if the decryption was successfull * if used in async mode, check if mMetaData.inProgress is true, it inicates a running decryption process. */ bool okDecryptMIME(KMime::Content &data); protected: bool mPassphraseError; bool mNoSecKey; const QGpgME::Protocol *mCryptoProto; QString mFromAddress; KMime::Content *mNode = nullptr; bool mDecryptMessage; QByteArray mVerifiedText; std::vector mDecryptRecipients; friend class DefaultRendererPrivate; - friend class ::PartPrivate; }; class MIMETREEPARSER_EXPORT SignedMessagePart : public MessagePart { Q_OBJECT Q_PROPERTY(bool isSigned READ isSigned) public: typedef QSharedPointer Ptr; SignedMessagePart(ObjectTreeParser *otp, const QString &text, const QGpgME::Protocol *cryptoProto, const QString &fromAddress, KMime::Content *node); virtual ~SignedMessagePart(); void setIsSigned(bool isSigned); bool isSigned() const; void startVerification(const QByteArray &text, const QTextCodec *aCodec); void startVerificationDetached(const QByteArray &text, KMime::Content *textNode, const QByteArray &signature); QByteArray mDecryptedData; std::vector mSignatures; QString plaintextContent() const override; QString htmlContent() const override; private: /** Handles the verification of data * If signature is empty it is handled as inline signature otherwise as detached signature mode. * Returns true if the verfication was successfull and the block is signed. * If used in async mode, check if mMetaData.inProgress is true, it inicates a running verification process. */ bool okVerify(const QByteArray &data, const QByteArray &signature, KMime::Content *textNode); void sigStatusToMetaData(); void setVerificationResult(const CryptoBodyPartMemento *m, KMime::Content *textNode); protected: const QGpgME::Protocol *mCryptoProto; QString mFromAddress; KMime::Content *mNode = nullptr; QByteArray mVerifiedText; friend EncryptedMessagePart; friend class DefaultRendererPrivate; - friend class ::PartPrivate; }; } #endif //__MIMETREEPARSER_MESSAGEPART_H__ diff --git a/mimetreeparser/src/viewer/objecttreeparser.cpp b/mimetreeparser/src/viewer/objecttreeparser.cpp index 713954e9..2a0de318 100644 --- a/mimetreeparser/src/viewer/objecttreeparser.cpp +++ b/mimetreeparser/src/viewer/objecttreeparser.cpp @@ -1,411 +1,408 @@ /* objecttreeparser.cpp This file is part of KMail, the KDE mail client. Copyright (c) 2003 Marc Mutz Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Copyright (c) 2009 Andras Mantia Copyright (c) 2015 Sandro Knauß KMail is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. KMail is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ // MessageViewer includes #include "objecttreeparser.h" #include "attachmentstrategy.h" #include "bodypartformatterbasefactory.h" #include "nodehelper.h" #include "messagepart.h" #include "partnodebodypart.h" #include "mimetreeparser_debug.h" #include "bodyformatter/utils.h" #include "interfaces/bodypartformatter.h" #include "interfaces/htmlwriter.h" #include "interfaces/messagepartrenderer.h" #include "utils/util.h" #include #include // KDE includes // Qt includes #include #include #include using namespace MimeTreeParser; ObjectTreeParser::ObjectTreeParser(const ObjectTreeParser *topLevelParser, bool showOnlyOneMimePart, const AttachmentStrategy *strategy) : mSource(topLevelParser->mSource) , mNodeHelper(topLevelParser->mNodeHelper) , mHtmlWriter(topLevelParser->mHtmlWriter) , mTopLevelContent(topLevelParser->mTopLevelContent) , mShowOnlyOneMimePart(showOnlyOneMimePart) , mHasPendingAsyncJobs(false) , mAllowAsync(topLevelParser->mAllowAsync) , mAttachmentStrategy(strategy) { init(); } ObjectTreeParser::ObjectTreeParser(Interface::ObjectTreeSource *source, MimeTreeParser::NodeHelper *nodeHelper, bool showOnlyOneMimePart, const AttachmentStrategy *strategy) : mSource(source) , mNodeHelper(nodeHelper) , mHtmlWriter(nullptr) , mTopLevelContent(nullptr) , mShowOnlyOneMimePart(showOnlyOneMimePart) , mHasPendingAsyncJobs(false) , mAllowAsync(false) , mAttachmentStrategy(strategy) { init(); } void ObjectTreeParser::init() { Q_ASSERT(mSource); if (!attachmentStrategy()) { mAttachmentStrategy = mSource->attachmentStrategy(); } if (!mNodeHelper) { mNodeHelper = new NodeHelper(); mDeleteNodeHelper = true; } else { mDeleteNodeHelper = false; } } ObjectTreeParser::ObjectTreeParser(const ObjectTreeParser &other) : mSource(other.mSource) , mNodeHelper(other.nodeHelper()) , //TODO(Andras) hm, review what happens if mDeleteNodeHelper was true in the source mHtmlWriter(other.mHtmlWriter) , mTopLevelContent(other.mTopLevelContent) , mShowOnlyOneMimePart(other.showOnlyOneMimePart()) , mHasPendingAsyncJobs(other.hasPendingAsyncJobs()) , mAllowAsync(other.allowAsync()) , mAttachmentStrategy(other.attachmentStrategy()) , mDeleteNodeHelper(false) { } ObjectTreeParser::~ObjectTreeParser() { if (mDeleteNodeHelper) { delete mNodeHelper; mNodeHelper = nullptr; } } void ObjectTreeParser::setAllowAsync(bool allow) { Q_ASSERT(!mHasPendingAsyncJobs); mAllowAsync = allow; } bool ObjectTreeParser::allowAsync() const { return mAllowAsync; } bool ObjectTreeParser::hasPendingAsyncJobs() const { return mHasPendingAsyncJobs; } QString ObjectTreeParser::plainTextContent() const { return mPlainTextContent; } QString ObjectTreeParser::htmlContent() const { return mHtmlContent; } void ObjectTreeParser::copyContentFrom(const ObjectTreeParser *other) { mPlainTextContent += other->plainTextContent(); mHtmlContent += other->htmlContent(); if (!other->plainTextContentCharset().isEmpty()) { mPlainTextContentCharset = other->plainTextContentCharset(); } if (!other->htmlContentCharset().isEmpty()) { mHtmlContentCharset = other->htmlContentCharset(); } } //----------------------------------------------------------------------------- void ObjectTreeParser::parseObjectTree(KMime::Content *node) { mTopLevelContent = node; mParsedPart = parseObjectTreeInternal(node, showOnlyOneMimePart()); if (mParsedPart) { mParsedPart->fix(); if (auto mp = toplevelTextNode(mParsedPart)) { if (auto _mp = mp.dynamicCast()) { extractNodeInfos(_mp->mNode, true); } else if (auto _mp = mp.dynamicCast()) { if (_mp->mChildNodes.contains(Util::MultipartPlain)) { extractNodeInfos(_mp->mChildNodes[Util::MultipartPlain], true); } } setPlainTextContent(mp->text()); } if (htmlWriter()) { const auto renderer = mSource->messagePartTheme(mParsedPart); if (renderer) { htmlWriter()->queue(renderer->html()); } } } } MessagePartPtr ObjectTreeParser::parsedPart() const { return mParsedPart; } -Interface::MessagePartPtr ObjectTreeParser::processType(KMime::Content *node, ProcessResult &processResult, const QByteArray &mimeType, bool onlyOneMimePart) +MessagePartPtr ObjectTreeParser::processType(KMime::Content *node, ProcessResult &processResult, const QByteArray &mimeType, bool onlyOneMimePart) { const auto formatters = mSource->bodyPartFormatterFactory()->formattersForType(QString::fromUtf8(mimeType)); Q_ASSERT(!formatters.empty()); for (auto formatter : formatters) { PartNodeBodyPart part(this, &processResult, mTopLevelContent, node, mNodeHelper); // Set the default display strategy for this body part relying on the // identity of Interface::BodyPart::Display and AttachmentStrategy::Display part.setDefaultDisplay((Interface::BodyPart::Display)attachmentStrategy()->defaultDisplay(node)); mNodeHelper->setNodeDisplayedEmbedded(node, true); - const Interface::MessagePart::Ptr result = formatter->process(part); + const MessagePart::Ptr result = formatter->process(part); if (!result) { continue; } // ### legacy BFP::format() handling, can be removed once all plugins are ported away from that if (const auto legacyPart = result.dynamicCast()) { const auto r = formatter->format(&part, legacyPart->htmlWriter()); if (r == Interface::BodyPartFormatter::AsIcon) { processResult.setNeverDisplayInline(true); mNodeHelper->setNodeDisplayedEmbedded(node, false); auto mp = processType(node, processResult, QByteArrayLiteral("application/octet-stream"), onlyOneMimePart); if (mp) { - if (auto _mp = mp.dynamicCast()) { - _mp->setAttachmentFlag(node); - } + mp->setAttachmentFlag(node); } return mp; } else if (r == Interface::BodyPartFormatter::Ok) { processResult.setNeverDisplayInline(true); return result; } } else { - if (auto mp = result.dynamicCast()) - mp->setAttachmentFlag(node); + result->setAttachmentFlag(node); return result; } } Q_UNREACHABLE(); return {}; } MessagePart::Ptr ObjectTreeParser::parseObjectTreeInternal(KMime::Content *node, bool onlyOneMimePart) { if (!node) { return MessagePart::Ptr(); } // reset pending async jobs state (we'll rediscover pending jobs as we go) mHasPendingAsyncJobs = false; // reset "processed" flags for... if (onlyOneMimePart) { // ... this node and all descendants mNodeHelper->setNodeUnprocessed(node, false); if (!node->contents().isEmpty()) { mNodeHelper->setNodeUnprocessed(node, true); } } else if (!node->parent()) { // ...this node and all it's siblings and descendants mNodeHelper->setNodeUnprocessed(node, true); } const bool isRoot = node->isTopLevel(); auto parsedPart = MessagePart::Ptr(new MessagePartList(this)); parsedPart->setIsRoot(isRoot); KMime::Content *parent = node->parent(); auto contents = parent ? parent->contents() : KMime::Content::List(); if (contents.isEmpty()) { contents.append(node); } int i = contents.indexOf(const_cast(node)); for (; i < contents.size(); ++i) { node = contents.at(i); if (mNodeHelper->nodeProcessed(node)) { continue; } ProcessResult processResult(mNodeHelper); QByteArray mimeType("text/plain"); if (node->contentType(false) && !node->contentType()->mimeType().isEmpty()) { mimeType = node->contentType()->mimeType(); } const auto mp = processType(node, processResult, mimeType, onlyOneMimePart); Q_ASSERT(mp); parsedPart->appendSubPart(mp); mNodeHelper->setNodeProcessed(node, false); // adjust signed/encrypted flags if inline PGP was found processResult.adjustCryptoStatesOfNode(node); if (onlyOneMimePart) { break; } } return parsedPart; } KMMsgSignatureState ProcessResult::inlineSignatureState() const { return mInlineSignatureState; } void ProcessResult::setInlineSignatureState(KMMsgSignatureState state) { mInlineSignatureState = state; } KMMsgEncryptionState ProcessResult::inlineEncryptionState() const { return mInlineEncryptionState; } void ProcessResult::setInlineEncryptionState(KMMsgEncryptionState state) { mInlineEncryptionState = state; } bool ProcessResult::neverDisplayInline() const { return mNeverDisplayInline; } void ProcessResult::setNeverDisplayInline(bool display) { mNeverDisplayInline = display; } bool ProcessResult::isImage() const { return mIsImage; } void ProcessResult::setIsImage(bool image) { mIsImage = image; } void ProcessResult::adjustCryptoStatesOfNode(const KMime::Content *node) const { if ((inlineSignatureState() != KMMsgNotSigned) || (inlineEncryptionState() != KMMsgNotEncrypted)) { mNodeHelper->setSignatureState(node, inlineSignatureState()); mNodeHelper->setEncryptionState(node, inlineEncryptionState()); } } void ObjectTreeParser::extractNodeInfos(KMime::Content *curNode, bool isFirstTextPart) { if (isFirstTextPart) { mPlainTextContent += curNode->decodedText(); mPlainTextContentCharset += NodeHelper::charset(curNode); } } void ObjectTreeParser::setPlainTextContent(const QString &plainTextContent) { mPlainTextContent = plainTextContent; } const QTextCodec *ObjectTreeParser::codecFor(KMime::Content *node) const { Q_ASSERT(node); if (mSource->overrideCodec()) { return mSource->overrideCodec(); } return mNodeHelper->codec(node); } QByteArray ObjectTreeParser::plainTextContentCharset() const { return mPlainTextContentCharset; } QByteArray ObjectTreeParser::htmlContentCharset() const { return mHtmlContentCharset; } bool ObjectTreeParser::showOnlyOneMimePart() const { return mShowOnlyOneMimePart; } void ObjectTreeParser::setShowOnlyOneMimePart(bool show) { mShowOnlyOneMimePart = show; } const AttachmentStrategy *ObjectTreeParser::attachmentStrategy() const { return mAttachmentStrategy; } HtmlWriter *ObjectTreeParser::htmlWriter() const { if (mHtmlWriter) { return mHtmlWriter; } return mSource->htmlWriter(); } MimeTreeParser::NodeHelper *ObjectTreeParser::nodeHelper() const { return mNodeHelper; } diff --git a/mimetreeparser/src/viewer/objecttreeparser.h b/mimetreeparser/src/viewer/objecttreeparser.h index 10bf6ad7..82373b32 100644 --- a/mimetreeparser/src/viewer/objecttreeparser.h +++ b/mimetreeparser/src/viewer/objecttreeparser.h @@ -1,393 +1,389 @@ /* objecttreeparser.h This file is part of KMail, the KDE mail client. Copyright (c) 2003 Marc Mutz Copyright (C) 2002-2003, 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Copyright (c) 2009 Andras Mantia KMail is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. KMail is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifndef __MIMETREEPARSER_OBJECTTREEPARSER_H__ #define __MIMETREEPARSER_OBJECTTREEPARSER_H__ #include "mimetreeparser_export.h" #include "mimetreeparser/nodehelper.h" #include "mimetreeparser/objecttreesource.h" #include class QString; namespace KMime { class Content; } namespace MimeTreeParser { -namespace Interface { -class MessagePart; -typedef QSharedPointer MessagePartPtr; -} class PartMetaData; class ViewerPrivate; class HtmlWriter; class AttachmentStrategy; class NodeHelper; class MessagePart; class MimeMessagePart; typedef QSharedPointer MessagePartPtr; typedef QSharedPointer MimeMessagePartPtr; class MIMETREEPARSER_EXPORT ProcessResult { public: explicit ProcessResult(NodeHelper *nodeHelper, KMMsgSignatureState inlineSignatureState = KMMsgNotSigned, KMMsgEncryptionState inlineEncryptionState = KMMsgNotEncrypted, bool neverDisplayInline = false, bool isImage = false) : mInlineSignatureState(inlineSignatureState) , mInlineEncryptionState(inlineEncryptionState) , mNeverDisplayInline(neverDisplayInline) , mIsImage(isImage) , mNodeHelper(nodeHelper) { } KMMsgSignatureState inlineSignatureState() const; void setInlineSignatureState(KMMsgSignatureState state); KMMsgEncryptionState inlineEncryptionState() const; void setInlineEncryptionState(KMMsgEncryptionState state); bool neverDisplayInline() const; void setNeverDisplayInline(bool display); bool isImage() const; void setIsImage(bool image); void adjustCryptoStatesOfNode(const KMime::Content *node) const; private: KMMsgSignatureState mInlineSignatureState; KMMsgEncryptionState mInlineEncryptionState; bool mNeverDisplayInline : 1; bool mIsImage : 1; NodeHelper *mNodeHelper; }; /** \brief Parses messages and generates HTML display code out of them \par Introduction First, have a look at the documentation in Mainpage.dox and at the documentation of ViewerPrivate to understand the broader picture. Just a note on the terminology: 'Node' refers to a MIME part here, which in KMime is a KMime::Content. \par Basics The ObjectTreeParser basically has two modes: Generating the HTML code for the Viewer, or only extracting the plainTextContent() for situations where only the message text is needed, for example when inline forwarding a message. The mode depends on the Interface::ObjectTreeSource passed to the constructor: If Interface::ObjectTreeSource::htmlWriter() is not 0, then the HTML code generation mode is used. Basically, all the ObjectTreeParser does is going through the tree of MIME parts and operating on those nodes. Operating here means creating the HTML code for the node or extracting the textual content from it. This process is started with parseObjectTree(), where we loop over the subnodes of the current root node. For each of those subnodes, we try to find a BodyPartFormatter that can handle the type of the node. This can either be an internal function, such as processMultiPartAlternativeSubtype() or processTextHtmlSubtype(), or it can be an external plugin. More on external plugins later. When no matching formatter is found, defaultHandling() is called for that node. \par Multipart Nodes Those nodes that are of type multipart have subnodes. If one of those children needs to be processed normally, the processMultipartXXX() functions call stdChildHandling() for the node that should be handled normally. stdChildHandling() creates its own ObjectTreeParser, which is a clone of the current ObjectTreeParser, and processes the node. stdChildHandling() is not called for all children of the multipart node, for example processMultiPartAlternativeSubtype() only calls it on one of the children, as the other one doesn't need to be displayed. Similary, processMultiPartSignedSubtype() doesn't call stdChildHandling() for the signature node, only for the signed node. \par Processed and Unprocessed Nodes When a BodyPartFormatter has finished processing a node, it is processed. Nodes are set to being not processed at the beginning of parseObjectTree(). The processed state of a node is saved in a list in NodeHelper, see NodeHelper::setNodeProcessed(), NodeHelper::nodeProcessed() and the other related helper functions. It is the responsibility of the BodyPartFormatter to correctly call setNodeProcessed() and the related functions. This is important so that processing the same node twice can be prevented. The check that prevents duplicate processing is in parseObjectTree(). An example where duplicate processing would happen if we didn't check for it is in stdChildHandling(), which is for example called from processMultiPartAlternativeSubtype(). Let's say the setting is to prefer HTML over plain text. In this case, processMultiPartAlternativeSubtype() would call stdChildHandling() on the HTML node, which would create a new ObjectTreeParser and call parseObjectTree() on it. parseObjectTree() processes the node and all its siblings, and one of the siblings is the plain text node, which shouldn't be processed! Therefore processMultiPartAlternativeSubtype() sets the plain text node as been processed already. \par Plain Text Output Various nodes have plain text that should be displayed. This plain text is usually processed though writeBodyString() first. That method checks if the provided text is an inline PGP text and decrypts it if necessary. It also pushes the text through quotedHTML(), which does a number of things like coloring quoted lines or detecting links and creating real link tags for them. \par Modifying the Message The ObjectTreeParser does not only parse its message, in some circumstances it also modifies it before displaying. This is for example the case when displaying a decrypted message: The original message only contains a binary blob of crypto data, and processMultiPartEncryptedSubtype() decrypts that blob. After decryption, the current node is replaced with the decrypted node, which happens in insertAndParseNewChildNode(). \par Crypto Operations For signature and decryption handling, there are functions which help with generating the HTML code for the signature header and footer. These are writeDeferredDecryptionBlock(), writeSigstatFooter() and writeSigstatHeader(). As the name writeDeferredDecryptionBlock() suggests, a setting can cause the message to not be decrypted unless the user clicks a link. Whether the message should be decrypted or not can be controlled by Interface::ObjectTreeSource::decryptMessage(). When the user clicks the decryption link, the URLHandler for 'kmail:' URLs sets that variable to true and triggers an update of the Viewer, which will cause parseObjectTree() to be called again. \par Async Crypto Operations The above case describes decryption the message in place. However, decryption and also verifying of the signature can take a long time, so synchronous decryption and verifing would cause the Viewer to block. Therefore it is possible to run these operations in async mode, see allowAsync(). In the first run of the async mode, all the ObjectTreeParser does is starting the decrypt or the verify job, and informing the user that the operation is in progress with writeDecryptionInProgressBlock() or with writeSigstatHeader(). Then, it creates and associates a BodyPartMemento with the current node, for example a VerifyDetachedBodyPartMemento. Each node can have multiple mementos associated with it, which are differeniated by name. NodeHelper::setBodyPartMemento() and NodeHelper::bodyPartMemento() provide means to store and retrieve these mementos. A memento is basically a thin wrapper around the crypto job, it stores the job pointer, the job input data and the job result. Mementos can be used for any async situation, not just for crypto jobs, but I'll describe crypto jobs here. So in the first run of decrypting or verifying a message, the BodyPartFormatter only starts the crypto job, creates the BodyPartMemento and writes the HTML code that tells the user that the operation is in progress. parseObjectTree() thus finishes without waiting for anything, and the message is displayed. At some point, the crypto jobs then finish, which will cause slotResult() of the BodyPartMemento to be called. slotResult() then saves the result to some member variable and calls BodyPartMemento::notify(), which in the end will trigger an update of the Viewer. That update will, in ViewerPrivate::parseMsg(), create a new ObjectTreeParser and call parseObjectTree() on it. This is where the second run begins. The functions that deal with decrypting of verifying, like processMultiPartSignedSubtype() or processMultiPartEncryptedSubtype() will look if they find a BodyPartMemento that is associated with the current node. Now it finds that memento, since it was created in the first run. It checks if the memento's job has finished, and if so, the result can be written out (either the decrypted data or the verified signature). When dealing with encrypted nodes, new nodes are created with the decrypted data. It is important to note that the original MIME tree is never modified, and remains the same as the original one. The method createAndParseTempNode is called with the newly decrypted data, and it generates a new temporary node to store the decrypted data. When these nodes are created, it is important to keep track of them as otherwise some mementos that are added to the newly created temporary nodes will be constantly regenerated. As the regeneration triggers a viewer update when complete, it results in an infinite refresh loop. The function NodeHelper::linkAsPermanentDecrypted will create a link between the newly created node and the original parent. Conversely, the function NodeHelper::attachExtraContent will create a link in the other direction, from the parent node to the newly created temporary node. When generating some mementos for nodes that may be temporary nodes (for example, contact photo mementos), the function NodeHelper::setBodyPartMementoForPermanentParent is used. This will save the given body part memento for the closest found permanent parent node, rather than the transient node itself. Then when checking for the existence of a certain memento in a node, NodeHelper::findPermanentParentBodyPartMemento will check to see if any parent of the given temporary node is a permanent (encrypted) node that has been used to generate the asked-for node. To conclude: For async operations, parseObjectTree() is called twice: The first call starts the crypto operation and creates the BodyPartMemento, the second calls sees that the BodyPartMemento is there and can use its result for writing out the HTML. \par PartMetaData and ProcessResult For crypto operations, the class PartMetaData is used a lot, mainly to pass around info about the crypto state of a node. A PartMetaData can also be associated with a node by using NodeHelper::setPartMetaData(). The only user of that however is MessageAnalyzer::processPart() of the Nepomuk E-Mail Feeder, which also uses the ObjectTreeParser to analyze the message. You'll notice that a ProcessResult is passed to each formatter. The formatter is supposed to modify the ProcessResult to tell the callers something about the state of the nodes that were processed. One example for its use is to tell the caller about the crypto state of the node. \par BodyPartFormatter Plugins As mentioned way earlier, BodyPartFormatter can either be plugins or be internal. bodypartformatter.cpp contains some trickery so that the processXXX() methods of the ObjectTreeParser are called from a BodyPartFormatter associated with them, see the CREATE_BODY_PART_FORMATTER macro. The BodyPartFormatter code is work in progress, it was supposed to be refactored, but that has not yet happened at the time of writing. Therefore the code can seem a bit chaotic. External plugins are loaded with loadPlugins() in bodypartformatterfactory.cpp. External plugins can only use the classes in the interfaces/ directory, they include BodyPart, BodyPartMemento, BodyPartFormatterPlugin, BodyPartFormatter, BodyPartURLHandler, HtmlWriter and URLHandler. Therefore external plugins have powerful capabilities, which are needed for example in the iCal formatter or in the vCard formatter. \par Special HTML tags As also mentioned in the documentation of ViewerPrivate, the ObjectTreeParser writes out special links that are only understood by the viewer, for example 'kmail:' URLs or 'attachment:' URLs. Also, some special HTML tags are created, which the Viewer later uses for post-processing. For example a div with the id 'attachmentInjectionPoint', or a div with the id 'attachmentDiv', which is used to mark an attachment in the body with a yellow border when the user clicks the attachment in the header. Finally, parseObjectTree() creates an anchor with the id 'att%1', which is used in the Viewer to scroll to the attachment. */ class MIMETREEPARSER_EXPORT ObjectTreeParser { /** * @internal * Copies the context of @p other, but not it's rawDecryptedBody, plainTextContent or htmlContent. */ ObjectTreeParser(const ObjectTreeParser &other); public: explicit ObjectTreeParser(Interface::ObjectTreeSource *source, NodeHelper *nodeHelper = nullptr, bool showOneMimePart = false, const AttachmentStrategy *attachmentStrategy = nullptr); explicit ObjectTreeParser(const ObjectTreeParser *topLevelParser, bool showOneMimePart = false, const AttachmentStrategy *attachmentStrategy = nullptr); virtual ~ObjectTreeParser(); void setAllowAsync(bool allow); bool allowAsync() const; bool hasPendingAsyncJobs() const; /** * The text of the message, ie. what would appear in the * composer's text editor if this was edited or replied to. * This is usually the content of the first text/plain MIME part. */ QString plainTextContent() const; /** * Similar to plainTextContent(), but returns the HTML source of the first text/html MIME part. * * Not to be consfused with the HTML code that the message viewer widget displays, that HTML * is written out by htmlWriter() and a totally different pair of shoes. */ QString htmlContent() const; /** * The original charset of MIME part the plain text was extracted from. * * If there were more than one text/plain MIME parts in the mail, the this is the charset * of the last MIME part processed. */ QByteArray plainTextContentCharset() const; QByteArray htmlContentCharset() const; bool showOnlyOneMimePart() const; void setShowOnlyOneMimePart(bool show); const AttachmentStrategy *attachmentStrategy() const; HtmlWriter *htmlWriter() const; NodeHelper *nodeHelper() const; /** Parse beginning at a given node and recursively parsing the children of that node and it's next sibling. */ void parseObjectTree(KMime::Content *node); MessagePartPtr parsedPart() const; private: void extractNodeInfos(KMime::Content *curNode, bool isFirstTextPart); void setPlainTextContent(const QString &plainTextContent); /** * Does the actual work for parseObjectTree. Unlike parseObjectTree(), this does not change the * top-level content. */ MessagePartPtr parseObjectTreeInternal(KMime::Content *node, bool mOnlyOneMimePart); - Interface::MessagePartPtr processType(KMime::Content *node, MimeTreeParser::ProcessResult &processResult, const QByteArray &mimeType, bool onlyOneMimePart); + MessagePartPtr processType(KMime::Content *node, MimeTreeParser::ProcessResult &processResult, const QByteArray &mimeType, bool onlyOneMimePart); private: /** ctor helper */ void init(); const QTextCodec *codecFor(KMime::Content *node) const; void copyContentFrom(const ObjectTreeParser *other); private: Interface::ObjectTreeSource *mSource; NodeHelper *mNodeHelper; HtmlWriter *mHtmlWriter; QByteArray mPlainTextContentCharset; QByteArray mHtmlContentCharset; QString mPlainTextContent; QString mHtmlContent; KMime::Content *mTopLevelContent; MessagePartPtr mParsedPart; /// Show only one mime part means that the user has selected some node in the message structure /// viewer that is not the root, which means the user wants to only see the selected node and its /// children. If that is the case, this variable is set to true. /// The code needs to behave differently if this is set. For example, it should not process the /// siblings. Also, consider inline images: Normally, those nodes are completely hidden, as the /// HTML node embedds them. However, when showing only the node of the image, one has to show them, /// as their is no HTML node in which they are displayed. There are many more cases where this /// variable needs to be obeyed. /// This variable is set to false again when processing the children in stdChildHandling(), as /// the children can be completely displayed again. bool mShowOnlyOneMimePart; bool mHasPendingAsyncJobs; bool mAllowAsync; const AttachmentStrategy *mAttachmentStrategy; // DataUrl Icons cache QString mCollapseIcon; QString mExpandIcon; bool mDeleteNodeHelper; friend class PartNodeBodyPart; friend class MessagePart; friend class EncryptedMessagePart; friend class SignedMessagePart; friend class TextMessagePart; friend class HtmlMessagePart; friend class MultiPartSignedBodyPartFormatter; friend class ApplicationPkcs7MimeBodyPartFormatter; }; } #endif // __MIMETREEPARSER_OBJECTTREEPARSER_H__