summaryrefslogtreecommitdiffstats
path: root/framework/src
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src')
-rw-r--r--framework/src/domain/mimetreeparser/otp/CMakeLists.txt1
-rw-r--r--framework/src/domain/mimetreeparser/otp/bodypartformatter.h2
-rw-r--r--framework/src/domain/mimetreeparser/otp/bodypartformatter_impl.cpp193
-rw-r--r--framework/src/domain/mimetreeparser/otp/bodypartformatterbasefactory.cpp29
4 files changed, 195 insertions, 30 deletions
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
27 textplain.cpp 27 textplain.cpp
28 texthtml.cpp 28 texthtml.cpp
29 utils.cpp 29 utils.cpp
30 bodypartformatter_impl.cpp
30 31
31 #Interfaces 32 #Interfaces
32 bodypartformatter.cpp 33 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 @@
37#include <QObject> 37#include <QObject>
38#include <QSharedPointer> 38#include <QSharedPointer>
39 39
40#include "mimetreeparser/objecttreeparser.h" 40#include "objecttreeparser.h"
41 41
42namespace MimeTreeParser 42namespace MimeTreeParser
43{ 43{
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 @@
1/* -*- c++ -*-
2 bodypartformatter.cpp
3
4 This file is part of KMail, the KDE mail client.
5 Copyright (c) 2003 Marc Mutz <mutz@kde.org>
6
7 KMail is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License, version 2, as
9 published by the Free Software Foundation.
10
11 KMail is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20 In addition, as a special exception, the copyright holders give
21 permission to link the code of this program with any edition of
22 the Qt library by Trolltech AS, Norway (or with modified versions
23 of Qt that use the same license as Qt), and distribute linked
24 combinations including the two. You must obey the GNU General
25 Public License in all respects for all of the code used other than
26 Qt. If you modify this file, you may extend this exception to
27 your version of the file, but you are not obligated to do so. If
28 you do not wish to do so, delete this exception statement from
29 your version.
30*/
31
32#include "mimetreeparser_debug.h"
33
34#include "applicationpgpencrypted.h"
35#include "applicationpkcs7mime.h"
36#include "mailman.h"
37#include "multipartalternative.h"
38#include "multipartmixed.h"
39#include "multipartencrypted.h"
40#include "multipartsigned.h"
41#include "texthtml.h"
42#include "textplain.h"
43
44#include "bodypartformatter.h"
45#include "bodypart.h"
46
47#include "bodypartformatterbasefactory.h"
48#include "bodypartformatterbasefactory_p.h"
49
50#include "attachmentstrategy.h"
51#include "objecttreeparser.h"
52#include "messagepart.h"
53
54#include <KMime/Content>
55
56using namespace MimeTreeParser;
57
58namespace
59{
60class AnyTypeBodyPartFormatter
61 : public MimeTreeParser::Interface::BodyPartFormatter
62{
63 static const AnyTypeBodyPartFormatter *self;
64public:
65 Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE
66 {
67 qCDebug(MIMETREEPARSER_LOG) << "Acting as a Interface::BodyPartFormatter!";
68 return AsIcon;
69 }
70
71 // unhide the overload with three arguments
72 using MimeTreeParser::Interface::BodyPartFormatter::format;
73
74 void adaptProcessResult(ProcessResult &result) const Q_DECL_OVERRIDE
75 {
76 result.setNeverDisplayInline(true);
77 }
78 static const MimeTreeParser::Interface::BodyPartFormatter *create()
79 {
80 if (!self) {
81 self = new AnyTypeBodyPartFormatter();
82 }
83 return self;
84 }
85};
86
87const AnyTypeBodyPartFormatter *AnyTypeBodyPartFormatter::self = nullptr;
88
89class ImageTypeBodyPartFormatter
90 : public MimeTreeParser::Interface::BodyPartFormatter
91{
92 static const ImageTypeBodyPartFormatter *self;
93public:
94 Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE
95 {
96 return AsIcon;
97 }
98
99 // unhide the overload with three arguments
100 using MimeTreeParser::Interface::BodyPartFormatter::format;
101
102 void adaptProcessResult(ProcessResult &result) const Q_DECL_OVERRIDE
103 {
104 result.setNeverDisplayInline(false);
105 result.setIsImage(true);
106 }
107 static const MimeTreeParser::Interface::BodyPartFormatter *create()
108 {
109 if (!self) {
110 self = new ImageTypeBodyPartFormatter();
111 }
112 return self;
113 }
114};
115
116const ImageTypeBodyPartFormatter *ImageTypeBodyPartFormatter::self = nullptr;
117
118class MessageRfc822BodyPartFormatter
119 : public MimeTreeParser::Interface::BodyPartFormatter
120{
121 static const MessageRfc822BodyPartFormatter *self;
122public:
123 Interface::MessagePart::Ptr process(Interface::BodyPart &) const Q_DECL_OVERRIDE;
124 MimeTreeParser::Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE;
125 using MimeTreeParser::Interface::BodyPartFormatter::format;
126 static const MimeTreeParser::Interface::BodyPartFormatter *create();
127};
128
129const MessageRfc822BodyPartFormatter *MessageRfc822BodyPartFormatter::self;
130
131const MimeTreeParser::Interface::BodyPartFormatter *MessageRfc822BodyPartFormatter::create()
132{
133 if (!self) {
134 self = new MessageRfc822BodyPartFormatter();
135 }
136 return self;
137}
138
139Interface::MessagePart::Ptr MessageRfc822BodyPartFormatter::process(Interface::BodyPart &part) const
140{
141 const KMime::Message::Ptr message = part.content()->bodyAsMessage();
142 return MessagePart::Ptr(new EncapsulatedRfc822MessagePart(part.objectTreeParser(), part.content(), message));
143}
144
145Interface::BodyPartFormatter::Result MessageRfc822BodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const
146{
147 Q_UNUSED(writer)
148 const ObjectTreeParser *otp = part->objectTreeParser();
149 const auto p = process(*part);
150 const auto mp = static_cast<MessagePart *>(p.data());
151 if (mp) {
152 if (!otp->attachmentStrategy()->inlineNestedMessages() && !otp->showOnlyOneMimePart()) {
153 return Failed;
154 } else {
155 mp->html(true);
156 return Ok;
157 }
158 } else {
159 return Failed;
160 }
161}
162
163typedef TextPlainBodyPartFormatter ApplicationPgpBodyPartFormatter;
164
165} // anon namespace
166
167void BodyPartFormatterBaseFactoryPrivate::messageviewer_create_builtin_bodypart_formatters()
168{
169 insert("application", "octet-stream", AnyTypeBodyPartFormatter::create());
170 insert("application", "pgp", ApplicationPgpBodyPartFormatter::create());
171 insert("application", "pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create());
172 insert("application", "x-pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create());
173 insert("application", "pgp-encrypted", ApplicationPGPEncryptedBodyPartFormatter::create());
174 insert("application", "*", AnyTypeBodyPartFormatter::create());
175
176 insert("text", "html", TextHtmlBodyPartFormatter::create());
177 insert("text", "rtf", AnyTypeBodyPartFormatter::create());
178 insert("text", "plain", MailmanBodyPartFormatter::create());
179 insert("text", "plain", TextPlainBodyPartFormatter::create());
180 insert("text", "*", MailmanBodyPartFormatter::create());
181 insert("text", "*", TextPlainBodyPartFormatter::create());
182
183 insert("image", "*", ImageTypeBodyPartFormatter::create());
184
185 insert("message", "rfc822", MessageRfc822BodyPartFormatter::create());
186 insert("message", "*", AnyTypeBodyPartFormatter::create());
187
188 insert("multipart", "alternative", MultiPartAlternativeBodyPartFormatter::create());
189 insert("multipart", "encrypted", MultiPartEncryptedBodyPartFormatter::create());
190 insert("multipart", "signed", MultiPartSignedBodyPartFormatter::create());
191 insert("multipart", "*", MultiPartMixedBodyPartFormatter::create());
192 insert("*", "*", AnyTypeBodyPartFormatter::create());
193}
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
83 subtype_reg.insert(std::make_pair(subtype, formatter)); 83 subtype_reg.insert(std::make_pair(subtype, formatter));
84} 84}
85 85
86void BodyPartFormatterBaseFactoryPrivate::messageviewer_create_builtin_bodypart_formatters()
87{
88 //FIXME defined in bodypartformatter.cpp
89 // insert("application", "octet-stream", AnyTypeBodyPartFormatter::create());
90 // insert("application", "pgp", ApplicationPgpBodyPartFormatter::create());
91 // insert("application", "pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create());
92 // insert("application", "x-pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create());
93 // insert("application", "pgp-encrypted", ApplicationPGPEncryptedBodyPartFormatter::create());
94 // insert("application", "*", AnyTypeBodyPartFormatter::create());
95
96 // insert("text", "html", TextHtmlBodyPartFormatter::create());
97 // insert("text", "rtf", AnyTypeBodyPartFormatter::create());
98 // insert("text", "plain", MailmanBodyPartFormatter::create());
99 // insert("text", "plain", TextPlainBodyPartFormatter::create());
100 // insert("text", "*", MailmanBodyPartFormatter::create());
101 // insert("text", "*", TextPlainBodyPartFormatter::create());
102
103 // insert("image", "*", ImageTypeBodyPartFormatter::create());
104
105 // insert("message", "rfc822", MessageRfc822BodyPartFormatter::create());
106 // insert("message", "*", AnyTypeBodyPartFormatter::create());
107
108 // insert("multipart", "alternative", MultiPartAlternativeBodyPartFormatter::create());
109 // insert("multipart", "encrypted", MultiPartEncryptedBodyPartFormatter::create());
110 // insert("multipart", "signed", MultiPartSignedBodyPartFormatter::create());
111 // insert("multipart", "*", MultiPartMixedBodyPartFormatter::create());
112 // insert("*", "*", AnyTypeBodyPartFormatter::create());
113}
114
115BodyPartFormatterBaseFactory::BodyPartFormatterBaseFactory() 86BodyPartFormatterBaseFactory::BodyPartFormatterBaseFactory()
116 : d(new BodyPartFormatterBaseFactoryPrivate(this)) 87 : d(new BodyPartFormatterBaseFactoryPrivate(this))
117{ 88{