From 7739ec0878746ad78330c117eb3cf49cb1b337a7 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 23 May 2017 19:42:45 +0200 Subject: Full functionality restored --- .../src/domain/mimetreeparser/otp/CMakeLists.txt | 1 + .../domain/mimetreeparser/otp/bodypartformatter.h | 2 +- .../mimetreeparser/otp/bodypartformatter_impl.cpp | 193 +++++++++++++++++++++ .../otp/bodypartformatterbasefactory.cpp | 29 ---- 4 files changed, 195 insertions(+), 30 deletions(-) create mode 100644 framework/src/domain/mimetreeparser/otp/bodypartformatter_impl.cpp (limited to 'framework') diff --git a/framework/src/domain/mimetreeparser/otp/CMakeLists.txt b/framework/src/domain/mimetreeparser/otp/CMakeLists.txt index f79277c8..baa6decd 100644 --- a/framework/src/domain/mimetreeparser/otp/CMakeLists.txt +++ b/framework/src/domain/mimetreeparser/otp/CMakeLists.txt @@ -27,6 +27,7 @@ set(libmimetreeparser_SRCS textplain.cpp texthtml.cpp utils.cpp + bodypartformatter_impl.cpp #Interfaces bodypartformatter.cpp diff --git a/framework/src/domain/mimetreeparser/otp/bodypartformatter.h b/framework/src/domain/mimetreeparser/otp/bodypartformatter.h index 682f9391..0116c2e4 100644 --- a/framework/src/domain/mimetreeparser/otp/bodypartformatter.h +++ b/framework/src/domain/mimetreeparser/otp/bodypartformatter.h @@ -37,7 +37,7 @@ #include #include -#include "mimetreeparser/objecttreeparser.h" +#include "objecttreeparser.h" namespace MimeTreeParser { diff --git a/framework/src/domain/mimetreeparser/otp/bodypartformatter_impl.cpp b/framework/src/domain/mimetreeparser/otp/bodypartformatter_impl.cpp new file mode 100644 index 00000000..c8622ba3 --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/bodypartformatter_impl.cpp @@ -0,0 +1,193 @@ +/* -*- 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 "applicationpgpencrypted.h" +#include "applicationpkcs7mime.h" +#include "mailman.h" +#include "multipartalternative.h" +#include "multipartmixed.h" +#include "multipartencrypted.h" +#include "multipartsigned.h" +#include "texthtml.h" +#include "textplain.h" + +#include "bodypartformatter.h" +#include "bodypart.h" + +#include "bodypartformatterbasefactory.h" +#include "bodypartformatterbasefactory_p.h" + +#include "attachmentstrategy.h" +#include "objecttreeparser.h" +#include "messagepart.h" + +#include + +using namespace MimeTreeParser; + +namespace +{ +class AnyTypeBodyPartFormatter + : public MimeTreeParser::Interface::BodyPartFormatter +{ + static const AnyTypeBodyPartFormatter *self; +public: + Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE + { + qCDebug(MIMETREEPARSER_LOG) << "Acting as a Interface::BodyPartFormatter!"; + return AsIcon; + } + + // unhide the overload with three arguments + using MimeTreeParser::Interface::BodyPartFormatter::format; + + void adaptProcessResult(ProcessResult &result) const Q_DECL_OVERRIDE + { + result.setNeverDisplayInline(true); + } + 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: + Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE + { + return AsIcon; + } + + // unhide the overload with three arguments + using MimeTreeParser::Interface::BodyPartFormatter::format; + + void adaptProcessResult(ProcessResult &result) const Q_DECL_OVERRIDE + { + result.setNeverDisplayInline(false); + result.setIsImage(true); + } + static const MimeTreeParser::Interface::BodyPartFormatter *create() + { + if (!self) { + self = new ImageTypeBodyPartFormatter(); + } + return self; + } +}; + +const ImageTypeBodyPartFormatter *ImageTypeBodyPartFormatter::self = nullptr; + +class MessageRfc822BodyPartFormatter + : public MimeTreeParser::Interface::BodyPartFormatter +{ + static const MessageRfc822BodyPartFormatter *self; +public: + Interface::MessagePart::Ptr process(Interface::BodyPart &) const Q_DECL_OVERRIDE; + MimeTreeParser::Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE; + using MimeTreeParser::Interface::BodyPartFormatter::format; + 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 +{ + const KMime::Message::Ptr message = part.content()->bodyAsMessage(); + return MessagePart::Ptr(new EncapsulatedRfc822MessagePart(part.objectTreeParser(), part.content(), message)); +} + +Interface::BodyPartFormatter::Result MessageRfc822BodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const +{ + Q_UNUSED(writer) + const ObjectTreeParser *otp = part->objectTreeParser(); + const auto p = process(*part); + const auto mp = static_cast(p.data()); + if (mp) { + if (!otp->attachmentStrategy()->inlineNestedMessages() && !otp->showOnlyOneMimePart()) { + return Failed; + } else { + mp->html(true); + return Ok; + } + } else { + return Failed; + } +} + +typedef TextPlainBodyPartFormatter ApplicationPgpBodyPartFormatter; + +} // anon namespace + +void BodyPartFormatterBaseFactoryPrivate::messageviewer_create_builtin_bodypart_formatters() +{ + insert("application", "octet-stream", AnyTypeBodyPartFormatter::create()); + insert("application", "pgp", ApplicationPgpBodyPartFormatter::create()); + insert("application", "pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create()); + insert("application", "x-pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create()); + insert("application", "pgp-encrypted", ApplicationPGPEncryptedBodyPartFormatter::create()); + insert("application", "*", AnyTypeBodyPartFormatter::create()); + + insert("text", "html", TextHtmlBodyPartFormatter::create()); + insert("text", "rtf", AnyTypeBodyPartFormatter::create()); + insert("text", "plain", MailmanBodyPartFormatter::create()); + insert("text", "plain", TextPlainBodyPartFormatter::create()); + insert("text", "*", MailmanBodyPartFormatter::create()); + insert("text", "*", TextPlainBodyPartFormatter::create()); + + insert("image", "*", ImageTypeBodyPartFormatter::create()); + + insert("message", "rfc822", MessageRfc822BodyPartFormatter::create()); + insert("message", "*", AnyTypeBodyPartFormatter::create()); + + insert("multipart", "alternative", MultiPartAlternativeBodyPartFormatter::create()); + insert("multipart", "encrypted", MultiPartEncryptedBodyPartFormatter::create()); + insert("multipart", "signed", MultiPartSignedBodyPartFormatter::create()); + insert("multipart", "*", MultiPartMixedBodyPartFormatter::create()); + insert("*", "*", AnyTypeBodyPartFormatter::create()); +} diff --git a/framework/src/domain/mimetreeparser/otp/bodypartformatterbasefactory.cpp b/framework/src/domain/mimetreeparser/otp/bodypartformatterbasefactory.cpp index a44576b8..fb02945b 100644 --- a/framework/src/domain/mimetreeparser/otp/bodypartformatterbasefactory.cpp +++ b/framework/src/domain/mimetreeparser/otp/bodypartformatterbasefactory.cpp @@ -83,35 +83,6 @@ void BodyPartFormatterBaseFactoryPrivate::insert(const char *type, const char *s subtype_reg.insert(std::make_pair(subtype, formatter)); } -void BodyPartFormatterBaseFactoryPrivate::messageviewer_create_builtin_bodypart_formatters() -{ - //FIXME defined in bodypartformatter.cpp - // insert("application", "octet-stream", AnyTypeBodyPartFormatter::create()); - // insert("application", "pgp", ApplicationPgpBodyPartFormatter::create()); - // insert("application", "pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create()); - // insert("application", "x-pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create()); - // insert("application", "pgp-encrypted", ApplicationPGPEncryptedBodyPartFormatter::create()); - // insert("application", "*", AnyTypeBodyPartFormatter::create()); - - // insert("text", "html", TextHtmlBodyPartFormatter::create()); - // insert("text", "rtf", AnyTypeBodyPartFormatter::create()); - // insert("text", "plain", MailmanBodyPartFormatter::create()); - // insert("text", "plain", TextPlainBodyPartFormatter::create()); - // insert("text", "*", MailmanBodyPartFormatter::create()); - // insert("text", "*", TextPlainBodyPartFormatter::create()); - - // insert("image", "*", ImageTypeBodyPartFormatter::create()); - - // insert("message", "rfc822", MessageRfc822BodyPartFormatter::create()); - // insert("message", "*", AnyTypeBodyPartFormatter::create()); - - // insert("multipart", "alternative", MultiPartAlternativeBodyPartFormatter::create()); - // insert("multipart", "encrypted", MultiPartEncryptedBodyPartFormatter::create()); - // insert("multipart", "signed", MultiPartSignedBodyPartFormatter::create()); - // insert("multipart", "*", MultiPartMixedBodyPartFormatter::create()); - // insert("*", "*", AnyTypeBodyPartFormatter::create()); -} - BodyPartFormatterBaseFactory::BodyPartFormatterBaseFactory() : d(new BodyPartFormatterBaseFactoryPrivate(this)) { -- cgit v1.2.3