diff --git a/messageviewer/autotests/data/encapsulated-with-attachment.mbox b/messageviewer/autotests/data/encapsulated-with-attachment.mbox --- a/messageviewer/autotests/data/encapsulated-with-attachment.mbox +++ b/messageviewer/autotests/data/encapsulated-with-attachment.mbox @@ -12,7 +12,7 @@ Content-Transfer-Encoding: 7bit Content-Disposition: inline -This is the encapsulating message. +This is the first encapsulating message. --Boundary-00=_zmUeKB+A8hGfCVZ Content-Type: message/rfc822; @@ -37,7 +37,7 @@ -This is the encapsulated message. +This is the second encapsulated message. --Boundary-00=_WmUeKQpGb0DHyx1 Content-Type: text/plain; diff --git a/messageviewer/autotests/data/encapsulated-with-attachment.mbox.html b/messageviewer/autotests/data/encapsulated-with-attachment.mbox.html --- a/messageviewer/autotests/data/encapsulated-with-attachment.mbox.html +++ b/messageviewer/autotests/data/encapsulated-with-attachment.mbox.html @@ -383,7 +383,7 @@
-
This is the encapsulating message.
+
This is the first encapsulating message.
@@ -401,7 +401,7 @@
-
This is the encapsulated message.
+
This is the second encapsulated message.
diff --git a/messageviewer/autotests/objecttreeparsertest.cpp b/messageviewer/autotests/objecttreeparsertest.cpp --- a/messageviewer/autotests/objecttreeparsertest.cpp +++ b/messageviewer/autotests/objecttreeparsertest.cpp @@ -62,8 +62,8 @@ otp.parseObjectTree(msg.data()); // Check that the textual content and the charset have the expected values - QCOMPARE(otp.plainTextContent(), QStringLiteral("This is the message text.")); - QCOMPARE(otp.convertedTextContent().toLatin1().data(), "This is the message text.\n"); + QCOMPARE(otp.plainTextContent(), QStringLiteral("This is the message text.\n")); + QCOMPARE(otp.convertedTextContent().toLatin1().data(), "This is the message text.\n\n"); QVERIFY(otp.htmlContent().isEmpty()); QCOMPARE(otp.plainTextContentCharset().toLower(), QByteArray("iso-8859-15")); @@ -110,7 +110,7 @@ QCOMPARE(msg->contents().at(1)->contents().first()->contents().at(1)->contents().size(), 0); // Check that the textual content and the charset have the expected values - QCOMPARE(otp.plainTextContent(), QStringLiteral("This is the encapsulating message.")); + QCOMPARE(otp.plainTextContent(), QStringLiteral("This is the first encapsulating message.\n")); QCOMPARE(otp.plainTextContentCharset().toLower(), QByteArray("iso-8859-15")); QVERIFY(otp.htmlContent().isEmpty()); diff --git a/messageviewer/src/viewer/messagepart.h b/messageviewer/src/viewer/messagepart.h --- a/messageviewer/src/viewer/messagepart.h +++ b/messageviewer/src/viewer/messagepart.h @@ -46,6 +46,8 @@ class HTMLBlock { public: + typedef QSharedPointer Ptr; + HTMLBlock() : entered(false) { } @@ -94,6 +96,22 @@ HtmlWriter *mWriter; }; +class TextBlock : public HTMLBlock +{ +public: + TextBlock(MessageViewer::HtmlWriter* writer, MessageViewer::NodeHelper* nodeHelper, KMime::Content* node, bool link); + virtual ~TextBlock(); +private: + void internalEnter(); + void internalExit(); +private: + HtmlWriter* mWriter; + NodeHelper *mNodeHelper; + KMime::Content* mNode; + QString mFileName; + bool mLink; +}; + class MessagePart { public: diff --git a/messageviewer/src/viewer/messagepart.cpp b/messageviewer/src/viewer/messagepart.cpp --- a/messageviewer/src/viewer/messagepart.cpp +++ b/messageviewer/src/viewer/messagepart.cpp @@ -21,14 +21,20 @@ #include "messageviewer_debug.h" #include "objecttreeparser.h" +#include + +#include + #include #include #include #include #include -#include #include +#include + +#include using namespace MessageViewer; @@ -104,6 +110,60 @@ entered = false; } + +TextBlock::TextBlock(MessageViewer::HtmlWriter *writer, MessageViewer::NodeHelper *nodeHelper, KMime::Content *node, bool link) + : mWriter(writer) + , mNodeHelper(nodeHelper) + , mNode(node) + , mLink(link) +{ + internalEnter(); +} + +TextBlock::~TextBlock() +{ + internalExit(); +} + +void TextBlock::internalEnter() +{ + if (!mWriter || entered) { + return; + } + entered = true; + + const QString label = MessageCore::StringUtil::quoteHtmlChars(NodeHelper::fileName(mNode), true); + + const QString comment = + MessageCore::StringUtil::quoteHtmlChars(mNode->contentDescription()->asUnicodeString(), true); + + const QString dir = QApplication::isRightToLeft() ? QStringLiteral("rtl") : QStringLiteral("ltr"); + + mWriter->queue(QLatin1String("" + "
")); + if (!mLink) + mWriter->queue(QLatin1String("asHREF(mNode, QStringLiteral("body")) + QLatin1String("\">") + + label + QLatin1String("")); + else { + mWriter->queue(label); + } + if (!comment.isEmpty()) { + mWriter->queue(QLatin1String("
") + comment); + } + mWriter->queue(QLatin1String("
")); +} + +void TextBlock::internalExit() +{ + if (!entered) { + return; + } + + entered = false; + + mWriter->queue(QStringLiteral("
")); +} + //------MessagePart----------------------- MessagePart::MessagePart(ObjectTreeParser *otp, const QString &text) diff --git a/messageviewer/src/viewer/objecttreeparser.cpp b/messageviewer/src/viewer/objecttreeparser.cpp --- a/messageviewer/src/viewer/objecttreeparser.cpp +++ b/messageviewer/src/viewer/objecttreeparser.cpp @@ -1017,51 +1017,22 @@ const bool bDrawFrame = !isFirstTextPart && !showOnlyOneMimePart() && !label.isEmpty(); - if (bDrawFrame && htmlWriter()) { - label = StringUtil::quoteHtmlChars(label, true); + const QString fileName = mNodeHelper->writeNodeToTempFile(curNode); - const QString comment = - StringUtil::quoteHtmlChars(curNode->contentDescription()->asUnicodeString(), true); - - const QString fileName; - mNodeHelper->writeNodeToTempFile(curNode); - const QString dir = QApplication::isRightToLeft() ? QStringLiteral("rtl") : QStringLiteral("ltr"); - - QString htmlStr = QLatin1String("" - "
"); - if (!fileName.isEmpty()) - htmlStr += QLatin1String("asHREF(curNode, QStringLiteral("body")) + QLatin1String("\">") - + label + QLatin1String(""); - else { - htmlStr += label; - } - if (!comment.isEmpty()) { - htmlStr += QLatin1String("
") + comment; - } - htmlStr += QLatin1String("
"); - - htmlWriter()->queue(htmlStr); - } // process old style not-multipart Mailman messages to // enable verification of the embedded messages' signatures if (!isMailmanMessage(curNode) || !processMailmanMessage(curNode)) { - const QString oldPlainText = mPlainTextContent; - writeBodyString(curNode->decodedContent(), NodeHelper::fromAsString(curNode), - codecFor(curNode), result, !bDrawFrame); - // Revert changes to mPlainTextContent made by writeBodyString if this is not the first - // text part. The plain text content shall not contain any text/plain attachment, as it is content - // of the main text node. - if (!isFirstTextPart) { - mPlainTextContent = oldPlainText; + TextMessagePart mp(this, curNode, bDrawFrame, !fileName.isEmpty()); + mp.html(!bDrawFrame); + + if (isFirstTextPart) { + mPlainTextContent = mp.text(); } + mNodeHelper->setNodeDisplayedEmbedded(curNode, true); } - if (bDrawFrame && htmlWriter()) { - htmlWriter()->queue(QStringLiteral("
")); - } - return true; }