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 @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -40,6 +41,7 @@ { class ObjectTreeParser; class HtmlWriter; +class NodeHelper; class HTMLBlock { @@ -118,6 +120,23 @@ PartMetaData mMetaData; }; +class TextMessagePart : public MessagePart +{ +public: + typedef QSharedPointer Ptr; + TextMessagePart(MessageViewer::ObjectTreeParser* otp, KMime::Content* node, bool drawFrame, bool showLink); + virtual ~TextMessagePart(); + + QString text() const Q_DECL_OVERRIDE; + void html(bool decorate) Q_DECL_OVERRIDE; + +private: + KMime::Content* mNode; + bool mDrawFrame; + bool mShowLink; + QVector mBlocks; +}; + class MimeMessagePart : public 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 @@ -182,6 +182,51 @@ return mSubOtp->plainTextContent(); } +//-----TextMessageBlock---------------------- + +TextMessagePart::TextMessagePart(ObjectTreeParser* otp, KMime::Content* node, bool drawFrame, bool showLink) + : MessagePart(otp, QString()) + , mNode(node) + , mDrawFrame(drawFrame) + , mShowLink(showLink) +{ + if (!mNode) { + qCWarning(MESSAGEVIEWER_LOG) << "not a valid node"; + return; + } + + KMMsgSignatureState inlineSignatureState; + KMMsgEncryptionState inlineEncryptionState; + mBlocks = mOtp->writeBodyStr2(mNode->decodedContent(), mOtp->codecFor(mNode), NodeHelper::fromAsString(mNode), inlineSignatureState, inlineEncryptionState); +} + +TextMessagePart::~TextMessagePart() +{ + +} + +void TextMessagePart::html(bool decorate) +{ + HTMLBlock::Ptr block; + MessageViewer::HtmlWriter *writer = mOtp->htmlWriter(); + if (mDrawFrame) { + block = HTMLBlock::Ptr(new TextBlock(writer, mOtp->nodeHelper(), mNode, mShowLink)); + } + + foreach (const MessagePart::Ptr &mp, mBlocks) { + mp->html(decorate); + } +} + +QString TextMessagePart::text() const +{ + QString text; + foreach (const MessagePart::Ptr &mp, mBlocks) { + text += mp->text(); + } + return text; +} + //-----MimeMessageBlock---------------------- MimeMessagePart::MimeMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool onlyOneMimePart) diff --git a/messageviewer/src/viewer/objecttreeparser.h b/messageviewer/src/viewer/objecttreeparser.h --- a/messageviewer/src/viewer/objecttreeparser.h +++ b/messageviewer/src/viewer/objecttreeparser.h @@ -443,6 +443,11 @@ KMMsgEncryptionState &inlineEncryptionState, bool decorate); + QVector writeBodyStr2(const QByteArray &aStr, const QTextCodec *aCodec, + const QString &fromAddress, + KMMsgSignatureState &inlineSignatureState, + KMMsgEncryptionState &inlineEncryptionState); + bool isMailmanMessage(KMime::Content *curNode); public: @@ -511,6 +516,7 @@ friend class MessagePart; friend class CryptoMessagePart; friend class EncapsulatedRfc822MessagePart; + friend class TextMessagePart; }; } 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 @@ -2379,22 +2379,15 @@ } //----------------------------------------------------------------------------- -void ObjectTreeParser::writeBodyStr(const QByteArray &aStr, const QTextCodec *aCodec, +QVector ObjectTreeParser::writeBodyStr2(const QByteArray &aStr, const QTextCodec *aCodec, const QString &fromAddress, KMMsgSignatureState &inlineSignatureState, - KMMsgEncryptionState &inlineEncryptionState, - bool decorate) + KMMsgEncryptionState &inlineEncryptionState) { - const QString dir = (QApplication::isRightToLeft() ? QStringLiteral("rtl") : QStringLiteral("ltr")); - //QString headerStr = QString::fromLatin1("
").arg(dir); - inlineSignatureState = KMMsgNotSigned; inlineEncryptionState = KMMsgNotEncrypted; QList blocks = prepareMessageForDecryption(aStr); - bool updatePlainText = false; // If there are encrypted or signed parts inside the node - // we need to update mPlainTextContent - QVector mpl; if (!blocks.isEmpty()) { @@ -2427,7 +2420,6 @@ fullySignedOrEncryptedTmp = false; mpl.append(MessagePart::Ptr(new MessagePart(this, aCodec->toUnicode(block.text())))); } else if (block.type() == PgpMessageBlock) { - updatePlainText = true; CryptoMessagePart::Ptr mp(new CryptoMessagePart(this, QString(), cryptoProtocol(), fromAddress, 0)); mpl.append(mp); if (!mSource->decryptMessage()) { @@ -2440,7 +2432,6 @@ } else if (block.type() == ClearsignedBlock) { CryptoMessagePart::Ptr mp(new CryptoMessagePart(this, QString(), cryptoProtocol(), fromAddress, 0)); mpl.append(mp); - updatePlainText = true; mp->startVerification(block.text(), aCodec); } else { continue; @@ -2470,13 +2461,27 @@ inlineEncryptionState = KMMsgFullyEncrypted; } } + } + return mpl; +} + +void ObjectTreeParser::writeBodyStr(const QByteArray &aStr, const QTextCodec *aCodec, + const QString &fromAddress, + KMMsgSignatureState &inlineSignatureState, + KMMsgEncryptionState &inlineEncryptionState, + bool decorate) +{ + const auto mpl = writeBodyStr2(aStr, aCodec, fromAddress, inlineSignatureState, inlineEncryptionState); + if (!mpl.isEmpty()) { if (htmlWriter()) { foreach (const MessagePart::Ptr &mp, mpl) { mp->html(decorate); } } + const bool updatePlainText = (inlineSignatureState != KMMsgNotSigned + || inlineEncryptionState != KMMsgNotEncrypted); if (updatePlainText || mPlainTextContent.isEmpty()) { mPlainTextContent.clear(); foreach (const MessagePart::Ptr &mp, mpl) {