Commit 4d3f178e authored by Volker Krause's avatar Volker Krause

Move image attachment handling to the correct place in the formatter

parent fd0b5cf2
......@@ -43,6 +43,7 @@
#include "interfaces/bodypartformatter.h"
#include "interfaces/bodypart.h"
#include "interfaces/htmlwriter.h"
#include "viewer/bodypartformatterbasefactory.h"
#include "viewer/bodypartformatterbasefactory_p.h"
......@@ -53,6 +54,8 @@
#include <KMime/Content>
#include <QUrl>
using namespace MimeTreeParser;
namespace {
......@@ -94,15 +97,6 @@ public:
return AsIcon;
}
// unhide the overload with three arguments
using MimeTreeParser::Interface::BodyPartFormatter::format;
void adaptProcessResult(ProcessResult &result) const override
{
result.setNeverDisplayInline(false);
result.setIsImage(true);
}
static const MimeTreeParser::Interface::BodyPartFormatter *create()
{
if (!self) {
......@@ -110,6 +104,37 @@ public:
}
return self;
}
Interface::MessagePart::Ptr process(Interface::BodyPart &part) const override
{
KMime::Content *node = part.content();
auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, false, true, part.source()->decryptMessage()));
mp->setIsImage(true);
part.processResult()->setInlineSignatureState(mp->signatureState());
part.processResult()->setInlineEncryptionState(mp->encryptionState());
auto preferredMode = part.source()->preferredMode();
bool isHtmlPreferred = (preferredMode == Util::Html) || (preferredMode == Util::MultipartHtml);
if (node->parent() && node->parent()->contentType()->subType() == "related" && isHtmlPreferred && !part.objectTreeParser()->showOnlyOneMimePart()) {
QString fileName = part.nodeHelper()->writeNodeToTempFile(node);
QString href = QUrl::fromLocalFile(fileName).url();
QByteArray cid = node->contentID()->identifier();
if (part.objectTreeParser()->htmlWriter()) {
part.objectTreeParser()->htmlWriter()->embedPart(cid, href);
}
part.nodeHelper()->setNodeDisplayedEmbedded(node, true);
part.nodeHelper()->setNodeDisplayedHidden(node, true);
return mp;
}
// Show it inline if showOnlyOneMimePart(), which means the user clicked the image
// in the message structure viewer manually, and therefore wants to see the full image
if (part.objectTreeParser()->showOnlyOneMimePart() && !part.processResult()->neverDisplayInline()) {
part.nodeHelper()->setNodeDisplayedEmbedded(node, true);
}
return mp;
}
};
const ImageTypeBodyPartFormatter *ImageTypeBodyPartFormatter::self = nullptr;
......
......@@ -341,29 +341,6 @@ Interface::MessagePart::Ptr ObjectTreeParser::defaultHandling(KMime::Content *no
_mp->setNeverDisplayInline(result.neverDisplayInline());
_mp->setIsImage(result.isImage());
mp = _mp;
// always show images in multipart/related when showing in html, not with an additional icon
auto preferredMode = mSource->preferredMode();
bool isHtmlPreferred = (preferredMode == Util::Html) || (preferredMode == Util::MultipartHtml);
if (result.isImage() && node->parent()
&& node->parent()->contentType()->subType() == "related" && isHtmlPreferred && !onlyOneMimePart) {
QString fileName = mNodeHelper->writeNodeToTempFile(node);
QString href = QUrl::fromLocalFile(fileName).url();
QByteArray cid = node->contentID()->identifier();
if (htmlWriter()) {
htmlWriter()->embedPart(cid, href);
}
nodeHelper()->setNodeDisplayedEmbedded(node, true);
mNodeHelper->setNodeDisplayedHidden(node, true);
return mp;
}
// Show it inline if showOnlyOneMimePart(), which means the user clicked the image
// in the message structure viewer manually, and therefore wants to see the full image
if (result.isImage() && onlyOneMimePart && !result.neverDisplayInline()) {
mNodeHelper->setNodeDisplayedEmbedded(node, true);
}
return mp;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment