diff --git a/mimetreeparser/src/interfaces/bodypart.h b/mimetreeparser/src/interfaces/bodypart.h index 9a20b51f..0c51b333 100644 --- a/mimetreeparser/src/interfaces/bodypart.h +++ b/mimetreeparser/src/interfaces/bodypart.h @@ -1,114 +1,106 @@ /* -*- mode: C++; c-file-style: "gnu" -*- bodypart.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_INTERFACES_BODYPART_H__ #define __MIMETREEPARSER_INTERFACES_BODYPART_H__ #include "mimetreeparser_export.h" namespace KMime { class Content; } namespace MimeTreeParser { class NodeHelper; class ObjectTreeParser; class ProcessResult; namespace Interface { class ObjectTreeSource; /** @short interface of classes that implement status for BodyPartFormatters. */ class MIMETREEPARSER_EXPORT BodyPartMemento { public: virtual ~BodyPartMemento(); virtual void detach() = 0; }; /** @short interface of message body parts. */ class MIMETREEPARSER_EXPORT BodyPart { public: virtual ~BodyPart(); /** @return the BodyPartMemento set for this part, or null, if none is set. */ virtual BodyPartMemento *memento() const = 0; - enum Display { - None, AsIcon, Inline - }; - /** - @return whether this body part should be displayed iconic or inline - */ - virtual Display defaultDisplay() const = 0; - /** Returns the KMime::Content node represented here. Makes most of the above obsolete and probably should be used in the interfaces in the first place. */ virtual KMime::Content *content() const = 0; /** * Returns the top-level content. * Note that this is _not_ necessarily the same as content()->topLevel(), for example the later * will not work for "extra nodes", i.e. nodes in encrypted parts of the mail. * topLevelContent() will return the correct result in this case. Also note that * topLevelContent() */ virtual KMime::Content *topLevelContent() const = 0; /** * Ok, this is ugly, exposing the node helper here, but there is too much useful stuff in there * for real-world plugins. Still, there should be a nicer way for this. */ virtual MimeTreeParser::NodeHelper *nodeHelper() const = 0; /** * For making it easier to refactor, add objectTreeParser */ virtual MimeTreeParser::ObjectTreeParser *objectTreeParser() const = 0; virtual MimeTreeParser::Interface::ObjectTreeSource *source() const = 0; virtual MimeTreeParser::ProcessResult *processResult() const = 0; }; } // namespace Interface } #endif // __MIMETREEPARSER_INTERFACES_BODYPART_H__ diff --git a/mimetreeparser/src/objecttreeparser.cpp b/mimetreeparser/src/objecttreeparser.cpp index c5450d9c..9f166d14 100644 --- a/mimetreeparser/src/objecttreeparser.cpp +++ b/mimetreeparser/src/objecttreeparser.cpp @@ -1,385 +1,381 @@ /* 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 "bodypartformatterfactory.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 "utils/util.h" #include #include // KDE includes // Qt includes #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->content(), true); } else if (auto _mp = mp.dynamicCast()) { if (_mp->mChildNodes.contains(Util::MultipartPlain)) { extractNodeInfos(_mp->mChildNodes[Util::MultipartPlain], true); } } setPlainTextContent(mp->text()); } if (htmlWriter()) { mSource->render(mParsedPart, htmlWriter()); } } } MessagePartPtr ObjectTreeParser::parsedPart() const { return mParsedPart; } MessagePartPtr ObjectTreeParser::processType(KMime::Content *node, ProcessResult &processResult, const QByteArray &mimeType) { 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 MessagePart::Ptr result = formatter->process(part); if (!result) { continue; } result->setAttachmentContent(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(node); if (i < 0) { return parsedPart; } else { 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(); } // unfortunately there's many emails where we can't trust the attachment mimetype // so try to see if we can find something better if (mimeType == "application/octet-stream") { NodeHelper::magicSetType(node); mimeType = node->contentType()->mimeType(); } const auto mp = processType(node, processResult, mimeType); 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; } 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/partnodebodypart.cpp b/mimetreeparser/src/partnodebodypart.cpp index c997e21a..e48e4f1e 100644 --- a/mimetreeparser/src/partnodebodypart.cpp +++ b/mimetreeparser/src/partnodebodypart.cpp @@ -1,74 +1,65 @@ /* partnodebodypart.cpp This file is part of KMail, the KDE mail client. 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. */ #include "partnodebodypart.h" #include "nodehelper.h" #include "objecttreeparser.h" #include "mimetreeparser_debug.h" #include using namespace MimeTreeParser; PartNodeBodyPart::PartNodeBodyPart(ObjectTreeParser *otp, ProcessResult *result, KMime::Content *topLevelContent, KMime::Content *content, NodeHelper *nodeHelper) : Interface::BodyPart() , mTopLevelContent(topLevelContent) , mContent(content) - , mDefaultDisplay(Interface::BodyPart::None) , mNodeHelper(nodeHelper) , mObjectTreeParser(otp) , mProcessResult(result) { } Interface::BodyPartMemento *PartNodeBodyPart::memento() const { /*TODO(Andras) Volker suggests to use a ContentIndex->Mememnto mapping Also review if the reader's bodyPartMemento should be returned or the NodeHelper's one */ return mNodeHelper->bodyPartMemento(mContent, "__plugin__"); } -Interface::BodyPart::Display PartNodeBodyPart::defaultDisplay() const -{ - return mDefaultDisplay; -} -void PartNodeBodyPart::setDefaultDisplay(Interface::BodyPart::Display d) -{ - mDefaultDisplay = d; -} Interface::ObjectTreeSource *PartNodeBodyPart::source() const { return mObjectTreeParser->mSource; } diff --git a/mimetreeparser/src/partnodebodypart.h b/mimetreeparser/src/partnodebodypart.h index c8127bb0..3fc122fa 100644 --- a/mimetreeparser/src/partnodebodypart.h +++ b/mimetreeparser/src/partnodebodypart.h @@ -1,96 +1,93 @@ /* partnodebodypart.h This file is part of KMail, the KDE mail client. 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_PARTNODEBODYPART_H__ #define __MIMETREEPARSER_PARTNODEBODYPART_H__ #include "mimetreeparser_export.h" #include "mimetreeparser/bodypart.h" namespace KMime { class Content; } namespace MimeTreeParser { class NodeHelper; } namespace MimeTreeParser { /** @short an implementation of the BodyPart interface using KMime::Content's */ class MIMETREEPARSER_EXPORT PartNodeBodyPart : public Interface::BodyPart { public: explicit PartNodeBodyPart(ObjectTreeParser *otp, ProcessResult *result, KMime::Content *topLevelContent, KMime::Content *content, NodeHelper *nodeHelper); Interface::BodyPartMemento *memento() const override; - BodyPart::Display defaultDisplay() const override; - void setDefaultDisplay(BodyPart::Display); KMime::Content *content() const override { return mContent; } KMime::Content *topLevelContent() const override { return mTopLevelContent; } NodeHelper *nodeHelper() const override { return mNodeHelper; } ObjectTreeParser *objectTreeParser() const override { return mObjectTreeParser; } ProcessResult *processResult() const override { return mProcessResult; } Interface::ObjectTreeSource *source() const override; private: KMime::Content *mTopLevelContent = nullptr; KMime::Content *mContent = nullptr; - BodyPart::Display mDefaultDisplay; NodeHelper *mNodeHelper = nullptr; ObjectTreeParser *mObjectTreeParser = nullptr; ProcessResult *mProcessResult = nullptr; }; } #endif // __MIMETREEPARSER_PARTNODEBODYPART_H__