12#include "attachmentstrategy.h"
14#include <MimeTreeParser/NodeHelper>
15#include <MimeTreeParser/Util>
17#include <KMime/Content>
21#include "messageviewer_debug.h"
23using namespace MessageViewer;
25static AttachmentStrategy::Display smartDisplay(
KMime::Content *node)
29 if (cd->disposition() == KMime::Headers::CDinline) {
31 return AttachmentStrategy::Inline;
33 if (cd->disposition() == KMime::Headers::CDattachment) {
35 return AttachmentStrategy::AsIcon;
40 if (ct && ct->isText() && ct->name().trimmed().isEmpty() && (!cd || cd->filename().trimmed().isEmpty())) {
42 return AttachmentStrategy::Inline;
44 return AttachmentStrategy::AsIcon;
54 friend class AttachmentStrategy;
57 IconicAttachmentStrategy()
58 : AttachmentStrategy()
62 ~IconicAttachmentStrategy()
override =
default;
65 [[nodiscard]]
const char *name()
const override
70 [[nodiscard]]
bool inlineNestedMessages()
const override
75 Display defaultDisplay(KMime::Content *node)
const override
95 friend class AttachmentStrategy;
98 SmartAttachmentStrategy()
99 : AttachmentStrategy()
103 ~SmartAttachmentStrategy()
override =
default;
106 [[nodiscard]]
const char *name()
const override
111 [[nodiscard]]
bool inlineNestedMessages()
const override
116 Display defaultDisplay(KMime::Content *node)
const override
118 return smartDisplay(node);
129 friend class AttachmentStrategy;
132 InlinedAttachmentStrategy()
133 : AttachmentStrategy()
137 ~InlinedAttachmentStrategy()
override =
default;
140 [[nodiscard]]
const char *name()
const override
145 [[nodiscard]]
bool inlineNestedMessages()
const override
150 Display defaultDisplay(KMime::Content *)
const override
163 friend class AttachmentStrategy;
166 HiddenAttachmentStrategy()
167 : AttachmentStrategy()
171 ~HiddenAttachmentStrategy()
override =
default;
174 [[nodiscard]]
const char *name()
const override
179 [[nodiscard]]
bool inlineNestedMessages()
const override
184 Display defaultDisplay(KMime::Content *node)
const override
205 friend class AttachmentStrategy;
208 HeaderOnlyAttachmentStrategy()
209 : AttachmentStrategy()
213 ~HeaderOnlyAttachmentStrategy()
override =
default;
216 [[nodiscard]]
const char *name()
const override
221 [[nodiscard]]
bool inlineNestedMessages()
const override
226 Display defaultDisplay(KMime::Content *node)
const override
229 return smartDisplay(node);
232 if (!MimeTreeParser::Util::labelForContent(node).isEmpty() &&
QIcon::hasThemeIcon(MimeTreeParser::Util::iconNameForContent(node))
233 && !MimeTreeParser::Util::isTypeBlacklisted(node)) {
236 return smartDisplay(node);
239 [[nodiscard]]
bool requiresAttachmentListInHeader()
const override
249AttachmentStrategy::AttachmentStrategy() =
default;
251AttachmentStrategy::~AttachmentStrategy() =
default;
267 qCCritical(MESSAGEVIEWER_LOG) <<
"Unknown attachment strategy ( type ==" <<
static_cast<int>(type) <<
") requested!";
273 const QString lowerType = type.toLower();
274 if (lowerType == QLatin1StringView(
"iconic")) {
278 if (lowerType == QLatin1StringView(
"inlined")) {
281 if (lowerType == QLatin1StringView(
"hidden")) {
284 if (lowerType == QLatin1StringView(
"headeronly")) {
300 if (!iconicStrategy) {
301 iconicStrategy =
new IconicAttachmentStrategy();
303 return iconicStrategy;
308 if (!smartStrategy) {
309 smartStrategy =
new SmartAttachmentStrategy();
311 return smartStrategy;
316 if (!inlinedStrategy) {
317 inlinedStrategy =
new InlinedAttachmentStrategy();
319 return inlinedStrategy;
324 if (!hiddenStrategy) {
325 hiddenStrategy =
new HiddenAttachmentStrategy();
327 return hiddenStrategy;
332 if (!headerOnlyStrategy) {
333 headerOnlyStrategy =
new HeaderOnlyAttachmentStrategy();
335 return headerOnlyStrategy;
338bool AttachmentStrategy::requiresAttachmentListInHeader()
const
const Headers::ContentType * contentType() const
const Headers::ContentDisposition * contentDisposition() const
The AttachmentStrategy class.
static bool isInEncapsulatedMessage(KMime::Content *node)
bool hasThemeIcon(const QString &name)
bool isEmpty() const const
QString trimmed() const const