Messagelib

bodypartformatter.cpp
1/* -*- c++ -*-
2 bodypartformatter.cpp
3
4 This file is part of KMail, the KDE mail client.
5 SPDX-FileCopyrightText: 2003 Marc Mutz <mutz@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#include "bodyformatter/applicationpgpencrypted.h"
11#include "bodyformatter/applicationpkcs7mime.h"
12#include "bodyformatter/encrypted.h"
13#include "bodyformatter/mailman.h"
14#include "bodyformatter/multipartalternative.h"
15#include "bodyformatter/multipartencrypted.h"
16#include "bodyformatter/multipartmixed.h"
17#include "bodyformatter/multipartsigned.h"
18#include "bodyformatter/texthtml.h"
19#include "bodyformatter/textplain.h"
20
21#include "interfaces/bodypart.h"
22#include "interfaces/bodypartformatter.h"
23
24#include "bodypartformatterfactory_p.h"
25
26#include "messagepart.h"
27#include "objecttreeparser.h"
28
29#include <KMime/Content>
30
31using namespace MimeTreeParser;
32
33namespace
34{
35class AnyTypeBodyPartFormatter : public MimeTreeParser::Interface::BodyPartFormatter
36{
37 static const AnyTypeBodyPartFormatter *self;
38
39public:
40 MessagePart::Ptr process(Interface::BodyPart &part) const override
41 {
42 KMime::Content *node = part.content();
43 const auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, part.source()->decryptMessage()));
44 part.processResult()->setInlineSignatureState(mp->signatureState());
45 part.processResult()->setInlineEncryptionState(mp->encryptionState());
46 part.processResult()->setNeverDisplayInline(true);
47 mp->setNeverDisplayInline(true);
48 mp->setIsImage(false);
49 return mp;
50 }
51
53 {
54 if (!self) {
55 self = new AnyTypeBodyPartFormatter();
56 }
57 return self;
58 }
59};
60
61const AnyTypeBodyPartFormatter *AnyTypeBodyPartFormatter::self = nullptr;
62
63class ImageTypeBodyPartFormatter : public MimeTreeParser::Interface::BodyPartFormatter
64{
65 static const ImageTypeBodyPartFormatter *self;
66
67public:
69 {
70 if (!self) {
71 self = new ImageTypeBodyPartFormatter();
72 }
73 return self;
74 }
75
76 MessagePart::Ptr process(Interface::BodyPart &part) const override
77 {
78 KMime::Content *node = part.content();
79 auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, part.source()->decryptMessage()));
80 mp->setIsImage(true);
81 part.processResult()->setInlineSignatureState(mp->signatureState());
82 part.processResult()->setInlineEncryptionState(mp->encryptionState());
83
84 auto preferredMode = part.source()->preferredMode();
85 const bool isHtmlPreferred = (preferredMode == Util::Html) || (preferredMode == Util::MultipartHtml);
86 if (node->parent() && node->parent()->contentType()->subType() == "related" && isHtmlPreferred) {
87 part.nodeHelper()->setNodeDisplayedEmbedded(node, true);
88 part.nodeHelper()->setNodeDisplayedHidden(node, true);
89 return mp;
90 }
91
92 return mp;
93 }
94};
95
96const ImageTypeBodyPartFormatter *ImageTypeBodyPartFormatter::self = nullptr;
97
98class MessageRfc822BodyPartFormatter : public MimeTreeParser::Interface::BodyPartFormatter
99{
100 static const MessageRfc822BodyPartFormatter *self;
101
102public:
103 MessagePart::Ptr process(Interface::BodyPart &) const override;
105};
106
107const MessageRfc822BodyPartFormatter *MessageRfc822BodyPartFormatter::self;
108
109const MimeTreeParser::Interface::BodyPartFormatter *MessageRfc822BodyPartFormatter::create()
110{
111 if (!self) {
112 self = new MessageRfc822BodyPartFormatter();
113 }
114 return self;
115}
116
117MessagePart::Ptr MessageRfc822BodyPartFormatter::process(Interface::BodyPart &part) const
118{
119 const KMime::Message::Ptr message = part.content()->bodyAsMessage();
120 return MessagePart::Ptr(new EncapsulatedRfc822MessagePart(part.objectTreeParser(), part.content(), message));
121}
122} // anon namespace
123
124void BodyPartFormatterFactoryPrivate::messageviewer_create_builtin_bodypart_formatters()
125{
126 insert(QStringLiteral("application/pkcs7-mime"), ApplicationPkcs7MimeBodyPartFormatter::create());
127 insert(QStringLiteral("application/x-pkcs7-mime"), ApplicationPkcs7MimeBodyPartFormatter::create());
128 insert(QStringLiteral("application/pgp-encrypted"), ApplicationPGPEncryptedBodyPartFormatter::create());
129
130 insert(QStringLiteral("application/octet-stream"), ApplicationPkcs7MimeBodyPartFormatter::create());
131 insert(QStringLiteral("application/octet-stream"), EncryptedBodyPartFormatter::create(EncryptedBodyPartFormatter::AutoPGP));
132 insert(QStringLiteral("application/octet-stream"), AnyTypeBodyPartFormatter::create());
133
134 insert(QStringLiteral("text/pgp"), EncryptedBodyPartFormatter::create(EncryptedBodyPartFormatter::ForcePGP));
135 insert(QStringLiteral("text/html"), TextHtmlBodyPartFormatter::create());
136 insert(QStringLiteral("text/rtf"), AnyTypeBodyPartFormatter::create());
137 insert(QStringLiteral("text/plain"), MailmanBodyPartFormatter::create());
138 insert(QStringLiteral("text/plain"), TextPlainBodyPartFormatter::create());
139
140 insert(QStringLiteral("image/png"), ImageTypeBodyPartFormatter::create());
141 insert(QStringLiteral("image/jpeg"), ImageTypeBodyPartFormatter::create());
142 insert(QStringLiteral("image/gif"), ImageTypeBodyPartFormatter::create());
143 insert(QStringLiteral("image/svg+xml"), ImageTypeBodyPartFormatter::create());
144 insert(QStringLiteral("image/bmp"), ImageTypeBodyPartFormatter::create());
145 insert(QStringLiteral("image/vnd.microsoft.icon"), ImageTypeBodyPartFormatter::create());
146
147 insert(QStringLiteral("message/rfc822"), MessageRfc822BodyPartFormatter::create());
148
149 insert(QStringLiteral("multipart/alternative"), MultiPartAlternativeBodyPartFormatter::create());
150 insert(QStringLiteral("multipart/encrypted"), MultiPartEncryptedBodyPartFormatter::create());
151 insert(QStringLiteral("multipart/signed"), MultiPartSignedBodyPartFormatter::create());
152 insert(QStringLiteral("multipart/mixed"), MultiPartMixedBodyPartFormatter::create());
153}
const Headers::ContentType * contentType() const
Content * parent()
QSharedPointer< Message > bodyAsMessage()
QByteArray subType() const
interface of message body parts.
Definition bodypart.h:45
virtual MimeTreeParser::ObjectTreeParser * objectTreeParser() const =0
For making it easier to refactor, add objectTreeParser.
virtual MimeTreeParser::NodeHelper * nodeHelper() const =0
Ok, this is ugly, exposing the node helper here, but there is too much useful stuff in there for real...
virtual KMime::Content * content() const =0
Returns the KMime::Content node represented here.
virtual MimeTreeParser::Util::HtmlMode preferredMode() const =0
Return the mode that is the preferred to display.
virtual bool decryptMessage() const =0
Return true if an encrypted mail should be decrypted.
bool insert(Part *part, qint64 *insertId=nullptr)
QAction * create(StandardAction id, const Receiver *recvr, Func slot, QObject *parent, std::optional< Qt::ConnectionType > connectionType=std::nullopt)
@ Html
A HTML message, non-multipart.
@ MultipartHtml
A multipart/alternative message, the HTML part is currently displayed.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.