diff --git a/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp b/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp --- a/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp +++ b/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp @@ -378,7 +378,7 @@ c.insert(QStringLiteral("block"), &block); block.setProperty("link", - mp->mOtp->nodeHelper()->asHREF(mp->mMessage.data(), QStringLiteral("body"))); + mp->nodeHelper()->asHREF(mp->mMessage.data(), QStringLiteral("body"))); c.insert(QStringLiteral("msgHeader"), mp->source()->createMessageHeader(mp->mMessage.data())); c.insert(QStringLiteral("content"), QVariant::fromValue([this, mp, htmlWriter](Grantlee::OutputStream *) { @@ -414,7 +414,7 @@ QString bodyText = processHtml(mp->mBodyHTML, extraHead); if (isHtmlPreferred) { - mp->mOtp->nodeHelper()->setNodeDisplayedEmbedded(mp->content(), true); + mp->nodeHelper()->setNodeDisplayedEmbedded(mp->content(), true); htmlWriter->extraHead(extraHead); } diff --git a/messageviewer/src/messagepartthemes/default/plugins/attachmentmessagepartrenderer.cpp b/messageviewer/src/messagepartthemes/default/plugins/attachmentmessagepartrenderer.cpp --- a/messageviewer/src/messagepartthemes/default/plugins/attachmentmessagepartrenderer.cpp +++ b/messageviewer/src/messagepartthemes/default/plugins/attachmentmessagepartrenderer.cpp @@ -50,8 +50,6 @@ } KMime::Content *node = mp->content(); - NodeHelper *nodeHelper = mp->mOtp->nodeHelper(); - if (mp->isHidden()) { return true; } @@ -71,11 +69,11 @@ QString iconPath; if (tmpAsIcon == MimeTreeParser::IconInline) { - iconPath = nodeHelper->writeNodeToTempFile(node); + iconPath = mp->temporaryFilePath(); } else { iconPath = MessageViewer::Util::iconPathForContent(node, KIconLoader::Desktop); if (iconPath.right(14) == QLatin1String("mime_empty.png")) { - nodeHelper->magicSetType(node); + NodeHelper::magicSetType(node); iconPath = MessageViewer::Util::iconPathForContent(node, KIconLoader::Desktop); } } diff --git a/mimetreeparser/src/bodyformatter/textplain.cpp b/mimetreeparser/src/bodyformatter/textplain.cpp --- a/mimetreeparser/src/bodyformatter/textplain.cpp +++ b/mimetreeparser/src/bodyformatter/textplain.cpp @@ -49,13 +49,12 @@ 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())); + mp = TextMessagePart::Ptr(new TextMessagePart(part.objectTreeParser(), node, bDrawFrame, part.source()->decryptMessage())); } else { - mp = TextMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, bDrawFrame, !fileName.isEmpty(), part.source()->decryptMessage())); + mp = TextMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, bDrawFrame, part.source()->decryptMessage())); } part.processResult()->setInlineSignatureState(mp->signatureState()); diff --git a/mimetreeparser/src/viewer/bodypartformatter.cpp b/mimetreeparser/src/viewer/bodypartformatter.cpp --- a/mimetreeparser/src/viewer/bodypartformatter.cpp +++ b/mimetreeparser/src/viewer/bodypartformatter.cpp @@ -66,7 +66,7 @@ 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())); + const auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, false, part.source()->decryptMessage())); part.processResult()->setInlineSignatureState(mp->signatureState()); part.processResult()->setInlineEncryptionState(mp->encryptionState()); part.processResult()->setNeverDisplayInline(true); @@ -101,15 +101,15 @@ 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())); + auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, false, 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 fileName = mp->temporaryFilePath(); QString href = QUrl::fromLocalFile(fileName).url(); QByteArray cid = node->contentID()->identifier(); if (part.objectTreeParser()->htmlWriter()) { diff --git a/mimetreeparser/src/viewer/messagepart.h b/mimetreeparser/src/viewer/messagepart.h --- a/mimetreeparser/src/viewer/messagepart.h +++ b/mimetreeparser/src/viewer/messagepart.h @@ -122,6 +122,7 @@ bool hasSubParts() const; Interface::ObjectTreeSource *source() const; + NodeHelper* nodeHelper() const; protected: void parseInternal(KMime::Content *node, bool onlyOneMimePart); @@ -195,7 +196,7 @@ Q_PROPERTY(QString comment READ comment CONSTANT) public: typedef QSharedPointer Ptr; - TextMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool showLink, bool decryptMessage); + TextMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool decryptMessage); virtual ~TextMessagePart(); KMMsgSignatureState signatureState() const; @@ -207,32 +208,33 @@ bool showLink() const; bool showTextFrame() const; + void setShowTextFrame(bool showFrame); /** The attachment filename, or the closest approximation thereof we have. */ QString label() const; /** A description of this attachment, if provided. */ QString comment() const; + /** Temporary file containing the part content. */ + QString temporaryFilePath() const; private: void parseContent(); KMMsgSignatureState mSignatureState; KMMsgEncryptionState mEncryptionState; bool mDrawFrame; - bool mShowLink; bool mDecryptMessage; bool mIsHidden; - friend class MessageViewer::AttachmentMessagePartRenderer; friend class ObjectTreeParser; }; 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); + AttachmentMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool decryptMessage); virtual ~AttachmentMessagePart(); IconType asIcon() const; diff --git a/mimetreeparser/src/viewer/messagepart.cpp b/mimetreeparser/src/viewer/messagepart.cpp --- a/mimetreeparser/src/viewer/messagepart.cpp +++ b/mimetreeparser/src/viewer/messagepart.cpp @@ -170,6 +170,12 @@ return mOtp->mSource; } +NodeHelper* MessagePart::nodeHelper() const +{ + Q_ASSERT(mOtp); + return mOtp->nodeHelper(); +} + void MessagePart::parseInternal(KMime::Content *node, bool onlyOneMimePart) { auto subMessagePart = mOtp->parseObjectTreeInternal(node, onlyOneMimePart); @@ -264,10 +270,9 @@ //-----TextMessageBlock---------------------- -TextMessagePart::TextMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool showLink, bool decryptMessage) +TextMessagePart::TextMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool decryptMessage) : MessagePartList(otp) , mDrawFrame(drawFrame) - , mShowLink(showLink) , mDecryptMessage(decryptMessage) , mIsHidden(false) { @@ -385,14 +390,19 @@ bool TextMessagePart::showLink() const { - return mShowLink; + return !temporaryFilePath().isEmpty(); } bool TextMessagePart::showTextFrame() const { return mDrawFrame; } +void TextMessagePart::setShowTextFrame(bool showFrame) +{ + mDrawFrame = showFrame; +} + QString TextMessagePart::label() const { const QString name = content()->contentType()->name(); @@ -412,10 +422,15 @@ return comment; } +QString TextMessagePart::temporaryFilePath() const +{ + return nodeHelper()->writeNodeToTempFile(content()); +} + //-----AttachmentMessageBlock---------------------- -AttachmentMessagePart::AttachmentMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool showLink, bool decryptMessage) - : TextMessagePart(otp, node, drawFrame, showLink, decryptMessage) +AttachmentMessagePart::AttachmentMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool decryptMessage) + : TextMessagePart(otp, node, drawFrame, decryptMessage) , mIsImage(false) , mNeverDisplayInline(false) { diff --git a/mimetreeparser/src/viewer/nodehelper.h b/mimetreeparser/src/viewer/nodehelper.h --- a/mimetreeparser/src/viewer/nodehelper.h +++ b/mimetreeparser/src/viewer/nodehelper.h @@ -76,7 +76,7 @@ * If autoDecode is true the decoded body will be used for mime type * determination (this does not change the body itself). */ - void magicSetType(KMime::Content *node, bool autoDecode = true); + static void magicSetType(KMime::Content *node, bool autoDecode = true); /** * Return this mails subject, with all "forward" and "reply"