From b5c2e787f863b60e00bf31ac558249216febc1b6 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 7 May 2018 12:05:37 +0200 Subject: Separate multipart/related formatter --- .../src/domain/mime/mimetreeparser/CMakeLists.txt | 1 - .../mime/mimetreeparser/bodypartformatter_impl.cpp | 48 +++++++++++++++++- .../domain/mime/mimetreeparser/multipartmixed.cpp | 57 ---------------------- .../domain/mime/mimetreeparser/multipartmixed.h | 39 --------------- 4 files changed, 47 insertions(+), 98 deletions(-) delete mode 100644 framework/src/domain/mime/mimetreeparser/multipartmixed.cpp delete mode 100644 framework/src/domain/mime/mimetreeparser/multipartmixed.h diff --git a/framework/src/domain/mime/mimetreeparser/CMakeLists.txt b/framework/src/domain/mime/mimetreeparser/CMakeLists.txt index c3f317ee..432234cf 100644 --- a/framework/src/domain/mime/mimetreeparser/CMakeLists.txt +++ b/framework/src/domain/mime/mimetreeparser/CMakeLists.txt @@ -17,7 +17,6 @@ set(libmimetreeparser_SRCS mailman.cpp multipartalternative.cpp multipartencrypted.cpp - multipartmixed.cpp multipartsigned.cpp textplain.cpp texthtml.cpp diff --git a/framework/src/domain/mime/mimetreeparser/bodypartformatter_impl.cpp b/framework/src/domain/mime/mimetreeparser/bodypartformatter_impl.cpp index 3522a144..882dfc05 100644 --- a/framework/src/domain/mime/mimetreeparser/bodypartformatter_impl.cpp +++ b/framework/src/domain/mime/mimetreeparser/bodypartformatter_impl.cpp @@ -35,7 +35,6 @@ #include "applicationpkcs7mime.h" #include "mailman.h" #include "multipartalternative.h" -#include "multipartmixed.h" #include "multipartencrypted.h" #include "multipartsigned.h" #include "texthtml.h" @@ -113,6 +112,52 @@ public: const HeadersBodyPartFormatter *HeadersBodyPartFormatter::self = nullptr; +class MultiPartRelatedBodyPartFormatter: public MimeTreeParser::Interface::BodyPartFormatter { + static const MultiPartRelatedBodyPartFormatter *self; +public: + MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE { + if (part.content()->contents().isEmpty()) { + return MessagePart::Ptr(); + } + //We rely on the order of the parts. + //Theoretically there could also be a Start parameter which would break this.. + //https://tools.ietf.org/html/rfc2387#section-4 + return MimeMessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), part.content()->contents().at(0), true)); + } + + static const MimeTreeParser::Interface::BodyPartFormatter *create() { + if (!self) { + self = new MultiPartRelatedBodyPartFormatter(); + } + return self; + } +}; + +const MultiPartRelatedBodyPartFormatter *MultiPartRelatedBodyPartFormatter::self = nullptr; + +class MultiPartMixedBodyPartFormatter: public MimeTreeParser::Interface::BodyPartFormatter { + static const MultiPartMixedBodyPartFormatter *self; +public: + MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE { + if (part.content()->contents().isEmpty()) { + return {}; + } + //FIXME sometimes we get attachments in here as well + //TODO look for attachment parts anyways + // normal treatment of the parts in the mp/mixed container + return MimeMessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), part.content()->contents().at(0), false)); + } + + static const MimeTreeParser::Interface::BodyPartFormatter *create() { + if (!self) { + self = new MultiPartMixedBodyPartFormatter(); + } + return self; + } +}; + +const MultiPartMixedBodyPartFormatter *MultiPartMixedBodyPartFormatter::self = nullptr; + } // anon namespace void BodyPartFormatterBaseFactoryPrivate::messageviewer_create_builtin_bodypart_formatters() @@ -140,6 +185,7 @@ void BodyPartFormatterBaseFactoryPrivate::messageviewer_create_builtin_bodypart_ insert("multipart", "alternative", MultiPartAlternativeBodyPartFormatter::create()); insert("multipart", "encrypted", MultiPartEncryptedBodyPartFormatter::create()); insert("multipart", "signed", MultiPartSignedBodyPartFormatter::create()); + insert("multipart", "related", MultiPartRelatedBodyPartFormatter::create()); insert("multipart", "*", MultiPartMixedBodyPartFormatter::create()); insert("*", "*", AnyTypeBodyPartFormatter::create()); } diff --git a/framework/src/domain/mime/mimetreeparser/multipartmixed.cpp b/framework/src/domain/mime/mimetreeparser/multipartmixed.cpp deleted file mode 100644 index 4231021e..00000000 --- a/framework/src/domain/mime/mimetreeparser/multipartmixed.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - Copyright (c) 2016 Sandro Knauß - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library 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 Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "multipartmixed.h" - -#include "objecttreeparser.h" -#include "messagepart.h" - -#include - -#include "mimetreeparser_debug.h" - -using namespace MimeTreeParser; - -const MultiPartMixedBodyPartFormatter *MultiPartMixedBodyPartFormatter::self; - -const Interface::BodyPartFormatter *MultiPartMixedBodyPartFormatter::create() -{ - if (!self) { - self = new MultiPartMixedBodyPartFormatter(); - } - return self; -} -MessagePart::Ptr MultiPartMixedBodyPartFormatter::process(Interface::BodyPart &part) const -{ - if (part.content()->contents().isEmpty()) { - return MessagePart::Ptr(); - } - - //In case of multipart/related we relay on the order of the parts. - //Theoretically there could also be a Start parameter which would break this.. - //https://tools.ietf.org/html/rfc2387#section-4 - bool showOnlyOneMimePart = [&] { - if (auto ct = part.content()->contentType(false)) { - return ct->mimeType() == "multipart/related"; - } - return false; - }(); - // normal treatment of the parts in the mp/mixed container - return MimeMessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), part.content()->contents().at(0), showOnlyOneMimePart)); -} diff --git a/framework/src/domain/mime/mimetreeparser/multipartmixed.h b/framework/src/domain/mime/mimetreeparser/multipartmixed.h deleted file mode 100644 index 7dfd85f6..00000000 --- a/framework/src/domain/mime/mimetreeparser/multipartmixed.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright (c) 2016 Sandro Knauß - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library 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 Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTMIXED_H__ -#define __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTMIXED_H__ - -#include "bodypartformatter.h" -#include "bodypart.h" - -namespace MimeTreeParser -{ - -class MultiPartMixedBodyPartFormatter : public Interface::BodyPartFormatter -{ - static const MultiPartMixedBodyPartFormatter *self; -public: - MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE; - static const Interface::BodyPartFormatter *create(); -}; - -} - -#endif -- cgit v1.2.3