Commit b0224174 authored by Volker Krause's avatar Volker Krause

Extend MessagePart API as needed for the TNEF plugin

Summary:
Mainly NodeHelper and temporary file access. This enabled a bit of cleanup
in the built-in rendering code too, towards getting rid of the friendship
overuse.

Reviewers: knauss

Reviewed By: knauss

Subscribers: #kde_pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D8170
parent ece5d7d4
......@@ -378,7 +378,7 @@ void DefaultRendererPrivate::render(const EncapsulatedRfc822MessagePart::Ptr &mp
c.insert(QStringLiteral("block"), &block);
block.setProperty("link",
mp->mOtp->nodeHelper()->asHREF(mp->mMessage.data(), QStringLiteral("body")));
mp->nodeHelper()->asHREF(mp->mMessage.data(), QStringLiteral("body")));
c.insert(QStringLiteral("msgHeader"), mp->source()->createMessageHeader(mp->mMessage.data()));
c.insert(QStringLiteral("content"), QVariant::fromValue<GrantleeCallback>([this, mp, htmlWriter](Grantlee::OutputStream *) {
......@@ -414,7 +414,7 @@ void DefaultRendererPrivate::render(const HtmlMessagePart::Ptr &mp, HtmlWriter *
QString bodyText = processHtml(mp->mBodyHTML, extraHead);
if (isHtmlPreferred) {
mp->mOtp->nodeHelper()->setNodeDisplayedEmbedded(mp->content(), true);
mp->nodeHelper()->setNodeDisplayedEmbedded(mp->content(), true);
htmlWriter->extraHead(extraHead);
}
......
......@@ -50,8 +50,6 @@ bool AttachmentMessagePartRenderer::render(const MimeTreeParser::MessagePartPtr
}
KMime::Content *node = mp->content();
NodeHelper *nodeHelper = mp->mOtp->nodeHelper();
if (mp->isHidden()) {
return true;
}
......@@ -71,11 +69,11 @@ bool AttachmentMessagePartRenderer::render(const MimeTreeParser::MessagePartPtr
QString iconPath;
if (tmpAsIcon == MimeTreeParser::IconInline) {
iconPath = nodeHelper->writeNodeToTempFile(node);
iconPath = mp->temporaryFilePath();
} else {
iconPath = MessageViewer::Util::iconPathForContent(node, KIconLoader::Desktop);
if (iconPath.right(14) == QLatin1String("mime_empty.png")) {
nodeHelper->magicSetType(node);
NodeHelper::magicSetType(node);
iconPath = MessageViewer::Util::iconPathForContent(node, KIconLoader::Desktop);
}
}
......
......@@ -49,13 +49,12 @@ MessagePart::Ptr TextPlainBodyPartFormatter::process(Interface::BodyPart &part)
const bool bDrawFrame = !isFirstTextPart
&& !part.objectTreeParser()->showOnlyOneMimePart()
&& !label.isEmpty();
const QString fileName = part.nodeHelper()->writeNodeToTempFile(node);
TextMessagePart::Ptr mp;
if (isFirstTextPart) {
mp = TextMessagePart::Ptr(new TextMessagePart(part.objectTreeParser(), node, bDrawFrame, !fileName.isEmpty(), part.source()->decryptMessage()));
mp = TextMessagePart::Ptr(new TextMessagePart(part.objectTreeParser(), node, bDrawFrame, part.source()->decryptMessage()));
} else {
mp = TextMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, bDrawFrame, !fileName.isEmpty(), part.source()->decryptMessage()));
mp = TextMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, bDrawFrame, part.source()->decryptMessage()));
}
part.processResult()->setInlineSignatureState(mp->signatureState());
......
......@@ -66,7 +66,7 @@ public:
MessagePart::Ptr process(Interface::BodyPart &part) const override
{
KMime::Content *node = part.content();
const auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, false, true, part.source()->decryptMessage()));
const auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, false, part.source()->decryptMessage()));
part.processResult()->setInlineSignatureState(mp->signatureState());
part.processResult()->setInlineEncryptionState(mp->encryptionState());
part.processResult()->setNeverDisplayInline(true);
......@@ -101,7 +101,7 @@ public:
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()));
auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, false, part.source()->decryptMessage()));
mp->setIsImage(true);
part.processResult()->setInlineSignatureState(mp->signatureState());
part.processResult()->setInlineEncryptionState(mp->encryptionState());
......@@ -109,7 +109,7 @@ public:
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 fileName = mp->temporaryFilePath();
QString href = QUrl::fromLocalFile(fileName).url();
QByteArray cid = node->contentID()->identifier();
if (part.objectTreeParser()->htmlWriter()) {
......
......@@ -170,6 +170,12 @@ Interface::ObjectTreeSource *MessagePart::source() const
return mOtp->mSource;
}
NodeHelper* MessagePart::nodeHelper() const
{
Q_ASSERT(mOtp);
return mOtp->nodeHelper();
}
void MessagePart::parseInternal(KMime::Content *node, bool onlyOneMimePart)
{
auto subMessagePart = mOtp->parseObjectTreeInternal(node, onlyOneMimePart);
......@@ -264,10 +270,9 @@ QString MessagePartList::htmlContent() const
//-----TextMessageBlock----------------------
TextMessagePart::TextMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool showLink, bool decryptMessage)
TextMessagePart::TextMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool decryptMessage)
: MessagePartList(otp)
, mDrawFrame(drawFrame)
, mShowLink(showLink)
, mDecryptMessage(decryptMessage)
, mIsHidden(false)
{
......@@ -385,7 +390,7 @@ bool TextMessagePart::isHidden() const
bool TextMessagePart::showLink() const
{
return mShowLink;
return !temporaryFilePath().isEmpty();
}
bool TextMessagePart::showTextFrame() const
......@@ -393,6 +398,11 @@ bool TextMessagePart::showTextFrame() const
return mDrawFrame;
}
void TextMessagePart::setShowTextFrame(bool showFrame)
{
mDrawFrame = showFrame;
}
QString TextMessagePart::label() const
{
const QString name = content()->contentType()->name();
......@@ -412,10 +422,15 @@ QString TextMessagePart::comment() const
return comment;
}
QString TextMessagePart::temporaryFilePath() const
{
return nodeHelper()->writeNodeToTempFile(content());
}
//-----AttachmentMessageBlock----------------------
AttachmentMessagePart::AttachmentMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool showLink, bool decryptMessage)
: TextMessagePart(otp, node, drawFrame, showLink, decryptMessage)
AttachmentMessagePart::AttachmentMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool decryptMessage)
: TextMessagePart(otp, node, drawFrame, decryptMessage)
, mIsImage(false)
, mNeverDisplayInline(false)
{
......
......@@ -122,6 +122,7 @@ public:
bool hasSubParts() const;
Interface::ObjectTreeSource *source() const;
NodeHelper* nodeHelper() const;
protected:
void parseInternal(KMime::Content *node, bool onlyOneMimePart);
......@@ -195,7 +196,7 @@ class MIMETREEPARSER_EXPORT TextMessagePart : public MessagePartList
Q_PROPERTY(QString comment READ comment CONSTANT)
public:
typedef QSharedPointer<TextMessagePart> Ptr;
TextMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool showLink, bool decryptMessage);
TextMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool decryptMessage);
virtual ~TextMessagePart();
KMMsgSignatureState signatureState() const;
......@@ -207,11 +208,14 @@ public:
bool showLink() const;
bool showTextFrame() const;
void setShowTextFrame(bool showFrame);
/** The attachment filename, or the closest approximation thereof we have. */
QString label() const;
/** A description of this attachment, if provided. */
QString comment() const;
/** Temporary file containing the part content. */
QString temporaryFilePath() const;
private:
void parseContent();
......@@ -219,11 +223,9 @@ private:
KMMsgSignatureState mSignatureState;
KMMsgEncryptionState mEncryptionState;
bool mDrawFrame;
bool mShowLink;
bool mDecryptMessage;
bool mIsHidden;
friend class MessageViewer::AttachmentMessagePartRenderer;
friend class ObjectTreeParser;
};
......@@ -232,7 +234,7 @@ class MIMETREEPARSER_EXPORT AttachmentMessagePart : public TextMessagePart
Q_OBJECT
public:
typedef QSharedPointer<AttachmentMessagePart> Ptr;
AttachmentMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool showLink, bool decryptMessage);
AttachmentMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool decryptMessage);
virtual ~AttachmentMessagePart();
IconType asIcon() const;
......
......@@ -76,7 +76,7 @@ public:
* If autoDecode is true the decoded body will be used for mime type
* determination (this does not change the body itself).
*/
void magicSetType(KMime::Content *node, bool autoDecode = true);
static void magicSetType(KMime::Content *node, bool autoDecode = true);
/**
* Return this mails subject, with all "forward" and "reply"
......
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