diff options
Diffstat (limited to 'framework/src/domain/mime/mimetreeparser/bodypartformatter_impl.cpp')
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/bodypartformatter_impl.cpp | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/bodypartformatter_impl.cpp b/framework/src/domain/mime/mimetreeparser/bodypartformatter_impl.cpp new file mode 100644 index 00000000..532a906e --- /dev/null +++ b/framework/src/domain/mime/mimetreeparser/bodypartformatter_impl.cpp | |||
@@ -0,0 +1,145 @@ | |||
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 "objecttreeparser.h" | ||
51 | #include "messagepart.h" | ||
52 | |||
53 | #include <KMime/Content> | ||
54 | |||
55 | using namespace MimeTreeParser; | ||
56 | |||
57 | namespace | ||
58 | { | ||
59 | class AnyTypeBodyPartFormatter | ||
60 | : public MimeTreeParser::Interface::BodyPartFormatter | ||
61 | { | ||
62 | static const AnyTypeBodyPartFormatter *self; | ||
63 | public: | ||
64 | static const MimeTreeParser::Interface::BodyPartFormatter *create() | ||
65 | { | ||
66 | if (!self) { | ||
67 | self = new AnyTypeBodyPartFormatter(); | ||
68 | } | ||
69 | return self; | ||
70 | } | ||
71 | }; | ||
72 | |||
73 | const AnyTypeBodyPartFormatter *AnyTypeBodyPartFormatter::self = nullptr; | ||
74 | |||
75 | class ImageTypeBodyPartFormatter : public MimeTreeParser::Interface::BodyPartFormatter | ||
76 | { | ||
77 | static const ImageTypeBodyPartFormatter *self; | ||
78 | public: | ||
79 | static const MimeTreeParser::Interface::BodyPartFormatter *create() | ||
80 | { | ||
81 | if (!self) { | ||
82 | self = new ImageTypeBodyPartFormatter(); | ||
83 | } | ||
84 | return self; | ||
85 | } | ||
86 | }; | ||
87 | |||
88 | const ImageTypeBodyPartFormatter *ImageTypeBodyPartFormatter::self = nullptr; | ||
89 | |||
90 | class MessageRfc822BodyPartFormatter | ||
91 | : public MimeTreeParser::Interface::BodyPartFormatter | ||
92 | { | ||
93 | static const MessageRfc822BodyPartFormatter *self; | ||
94 | public: | ||
95 | MessagePart::Ptr process(Interface::BodyPart &) const Q_DECL_OVERRIDE; | ||
96 | static const MimeTreeParser::Interface::BodyPartFormatter *create(); | ||
97 | }; | ||
98 | |||
99 | const MessageRfc822BodyPartFormatter *MessageRfc822BodyPartFormatter::self; | ||
100 | |||
101 | const MimeTreeParser::Interface::BodyPartFormatter *MessageRfc822BodyPartFormatter::create() | ||
102 | { | ||
103 | if (!self) { | ||
104 | self = new MessageRfc822BodyPartFormatter(); | ||
105 | } | ||
106 | return self; | ||
107 | } | ||
108 | |||
109 | MessagePart::Ptr MessageRfc822BodyPartFormatter::process(Interface::BodyPart &part) const | ||
110 | { | ||
111 | const KMime::Message::Ptr message = part.content()->bodyAsMessage(); | ||
112 | return MessagePart::Ptr(new EncapsulatedRfc822MessagePart(part.objectTreeParser(), part.content(), message)); | ||
113 | } | ||
114 | |||
115 | typedef TextPlainBodyPartFormatter ApplicationPgpBodyPartFormatter; | ||
116 | |||
117 | } // anon namespace | ||
118 | |||
119 | void BodyPartFormatterBaseFactoryPrivate::messageviewer_create_builtin_bodypart_formatters() | ||
120 | { | ||
121 | insert("application", "octet-stream", AnyTypeBodyPartFormatter::create()); | ||
122 | insert("application", "pgp", ApplicationPgpBodyPartFormatter::create()); | ||
123 | insert("application", "pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create()); | ||
124 | insert("application", "x-pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create()); | ||
125 | insert("application", "pgp-encrypted", ApplicationPGPEncryptedBodyPartFormatter::create()); | ||
126 | insert("application", "*", AnyTypeBodyPartFormatter::create()); | ||
127 | |||
128 | insert("text", "html", TextHtmlBodyPartFormatter::create()); | ||
129 | insert("text", "rtf", AnyTypeBodyPartFormatter::create()); | ||
130 | insert("text", "plain", MailmanBodyPartFormatter::create()); | ||
131 | insert("text", "plain", TextPlainBodyPartFormatter::create()); | ||
132 | insert("text", "*", MailmanBodyPartFormatter::create()); | ||
133 | insert("text", "*", TextPlainBodyPartFormatter::create()); | ||
134 | |||
135 | insert("image", "*", ImageTypeBodyPartFormatter::create()); | ||
136 | |||
137 | insert("message", "rfc822", MessageRfc822BodyPartFormatter::create()); | ||
138 | insert("message", "*", AnyTypeBodyPartFormatter::create()); | ||
139 | |||
140 | insert("multipart", "alternative", MultiPartAlternativeBodyPartFormatter::create()); | ||
141 | insert("multipart", "encrypted", MultiPartEncryptedBodyPartFormatter::create()); | ||
142 | insert("multipart", "signed", MultiPartSignedBodyPartFormatter::create()); | ||
143 | insert("multipart", "*", MultiPartMixedBodyPartFormatter::create()); | ||
144 | insert("*", "*", AnyTypeBodyPartFormatter::create()); | ||
145 | } | ||