Commit 22000fd9 authored by Sandro Knauß's avatar Sandro Knauß
Browse files

Prepare removal of MessageCore::NodeHelper dependency for MimeTreeParser

parent bbbdb2b4
......@@ -64,18 +64,16 @@ Interface::MessagePart::Ptr ApplicationPGPEncryptedBodyPartFormatter::process(In
qCWarning(MIMETREEPARSER_LOG) << "Unknown PGP Version String:" << node->decodedContent().trimmed();
}
KMime::Content *data = findType(part.content(), "application/octet-stream", false, true);
if (!part.content()->parent()) {
return MessagePart::Ptr();
}
KMime::Content *data = findTypeInDirectChilds(part.content()->parent(), "application/octet-stream");
if (!data) {
return MessagePart::Ptr(); //new MimeMessagePart(part.objectTreeParser(), node, false));
}
KMime::Content *dataChild = MessageCore::NodeHelper::firstChild(data);
if (dataChild) {
Q_ASSERT(false);
return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), dataChild, false));
}
part.nodeHelper()->setEncryptionState(node, KMMsgFullyEncrypted);
CryptoMessagePart::Ptr mp(new CryptoMessagePart(part.objectTreeParser(),
......
......@@ -24,8 +24,6 @@
#include "viewer/objecttreeparser.h"
#include "viewer/messagepart.h"
#include <MessageCore/NodeHelper>
#include <KMime/Content>
#include "mimetreeparser_debug.h"
......@@ -55,21 +53,20 @@ Interface::BodyPartFormatter::Result MultiPartAlternativeBodyPartFormatter::form
Interface::MessagePart::Ptr MultiPartAlternativeBodyPartFormatter::process(Interface::BodyPart &part) const
{
const KMime::Content *node = part.content();
KMime::Content *child = MessageCore::NodeHelper::firstChild(node);
if (!child) {
KMime::Content *node = part.content();
if (node->contents().isEmpty()) {
return MessagePart::Ptr();
}
KMime::Content *dataHtml = findType(child, "text/html", false, true);
KMime::Content *dataPlain = findType(child, "text/plain", false, true);
KMime::Content *dataHtml = findTypeInDirectChilds(node, "text/html");
KMime::Content *dataPlain = findTypeInDirectChilds(node, "text/plain");
if (!dataHtml) {
// If we didn't find the HTML part as the first child of the multipart/alternative, it might
// be that this is a HTML message with images, and text/plain and multipart/related are the
// immediate children of this multipart/alternative node.
// In this case, the HTML node is a child of multipart/related.
dataHtml = findType(child, "multipart/related", false, true);
dataHtml = findTypeInDirectChilds(node, "multipart/related");
// Still not found? Stupid apple mail actually puts the attachments inside of the
// multipart/alternative, which is wrong. Therefore we also have to look for multipart/mixed
......@@ -77,7 +74,7 @@ Interface::MessagePart::Ptr MultiPartAlternativeBodyPartFormatter::process(Inter
// Do this only when prefering HTML mail, though, since otherwise the attachments are hidden
// when displaying plain text.
if (!dataHtml && part.source()->htmlMail()) {
dataHtml = findType(child, "multipart/mixed", false, true);
dataHtml = findTypeInDirectChilds(node, "multipart/mixed");
}
}
......@@ -101,6 +98,6 @@ Interface::MessagePart::Ptr MultiPartAlternativeBodyPartFormatter::process(Inter
return mp;
}
MimeMessagePart::Ptr mp(new MimeMessagePart(part.objectTreeParser(), child, false));
MimeMessagePart::Ptr mp(new MimeMessagePart(part.objectTreeParser(), node->contents().at(0), false));
return mp;
}
......@@ -24,7 +24,6 @@
#include "viewer/objecttreeparser.h"
#include "viewer/messagepart.h"
#include <MessageCore/NodeHelper>
#include <KMime/Content>
#include <Libkleo/CryptoBackendFactory>
......@@ -57,8 +56,7 @@ Interface::BodyPartFormatter::Result MultiPartEncryptedBodyPartFormatter::format
Interface::MessagePart::Ptr MultiPartEncryptedBodyPartFormatter::process(Interface::BodyPart &part) const
{
KMime::Content *node = part.content();
KMime::Content *child = MessageCore::NodeHelper::firstChild(node);
if (!child) {
if (node->contents().isEmpty()) {
Q_ASSERT(false);
return MessagePart::Ptr();
}
......@@ -68,12 +66,12 @@ Interface::MessagePart::Ptr MultiPartEncryptedBodyPartFormatter::process(Interfa
/*
ATTENTION: This code is to be replaced by the new 'auto-detect' feature. --------------------------------------
*/
KMime::Content *data = findType(child, "application/octet-stream", false, true);
KMime::Content *data = findTypeInDirectChilds(node, "application/octet-stream");
if (data) {
useThisCryptProto = Kleo::CryptoBackendFactory::instance()->openpgp();
}
if (!data) {
data = findType(child, "application/pkcs7-mime", false, true);
data = findTypeInDirectChilds(node, "application/pkcs7-mime");
if (data) {
useThisCryptProto = Kleo::CryptoBackendFactory::instance()->smime();
}
......@@ -83,13 +81,7 @@ Interface::MessagePart::Ptr MultiPartEncryptedBodyPartFormatter::process(Interfa
*/
if (!data) {
return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), child, false));
}
KMime::Content *dataChild = MessageCore::NodeHelper::firstChild(data);
if (dataChild) {
Q_ASSERT(false);
return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), dataChild, false));
return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), node->contents().at(0), false));
}
part.nodeHelper()->setEncryptionState(node, KMMsgFullyEncrypted);
......
......@@ -57,16 +57,19 @@ Interface::BodyPartFormatter::Result MultiPartSignedBodyPartFormatter::format(In
Interface::MessagePart::Ptr MultiPartSignedBodyPartFormatter::process(Interface::BodyPart &part) const
{
KMime::Content *node = part.content();
KMime::Content *signedData = MessageCore::NodeHelper::firstChild(node);
assert(signedData);
if (node->contents().size() != 2) {
qCDebug(MIMETREEPARSER_LOG) << "mulitpart/signed must have exactly two child parts!" << endl
<< "processing as multipart/mixed";
return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), signedData, false));
if (!node->contents().isEmpty()) {
return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), node->contents().at(0), false));
} else {
return MessagePart::Ptr();
}
}
KMime::Content *signedData = node->contents().at(0);
KMime::Content *signature = node->contents().at(1);
assert(signedData);
assert(signature);
QString protocolContentType = node->contentType()->parameter(QStringLiteral("protocol")).toLower();
......
......@@ -19,8 +19,6 @@
#include "utils.h"
#include <MessageCore/NodeHelper>
using namespace MimeTreeParser;
MimeMessagePart::Ptr MimeTreeParser::createAndParseTempNode(Interface::BodyPart &part, KMime::Content *parentNode, const char *content, const char *cntDesc)
......@@ -37,21 +35,17 @@ MimeMessagePart::Ptr MimeTreeParser::createAndParseTempNode(Interface::BodyPart
return MimeMessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), newNode, false));
}
KMime::Content *MimeTreeParser::findType(KMime::Content *content, const QByteArray &mimeType, bool deep, bool wide)
KMime::Content *MimeTreeParser::findTypeInDirectChilds(KMime::Content *content, const QByteArray &mimeType)
{
if ((!content->contentType()->isEmpty())
&& (mimeType.isEmpty() || (mimeType == content->contentType()->mimeType()))) {
if (mimeType.isEmpty()) {
return content;
}
KMime::Content *child = MessageCore::NodeHelper::firstChild(content);
if (child && deep) { //first child
return findType(child, mimeType, deep, wide);
}
KMime::Content *next = MessageCore::NodeHelper::nextSibling(content);
if (next && wide) { //next on the same level
return findType(next, mimeType, deep, wide);
foreach (auto child, content->contents()) {
if ((!child->contentType()->isEmpty())
&& (mimeType == child->contentType()->mimeType())) {
return child;
}
}
return Q_NULLPTR;
}
\ No newline at end of file
......@@ -35,7 +35,7 @@ namespace MimeTreeParser
MimeMessagePart::Ptr createAndParseTempNode(Interface::BodyPart &part, KMime::Content *parentNode, const char *content, const char *cntDesc);
KMime::Content *findType(KMime::Content *content, const QByteArray &mimeType, bool deep, bool wide);
KMime::Content *findTypeInDirectChilds(KMime::Content* content, const QByteArray& mimeType);
}
#endif
......@@ -276,7 +276,7 @@ MessagePart::Ptr ObjectTreeParser::parseObjectTreeInternal(KMime::Content *node)
if (showOnlyOneMimePart()) {
// ... this node and all descendants
mNodeHelper->setNodeUnprocessed(node, false);
if (MessageCore::NodeHelper::firstChild(node)) {
if (!node->contents().isEmpty()) {
mNodeHelper->setNodeUnprocessed(node, true);
}
} else if (!node->parent()) {
......@@ -287,8 +287,14 @@ MessagePart::Ptr ObjectTreeParser::parseObjectTreeInternal(KMime::Content *node)
const bool isRoot = node->isTopLevel();
MessagePartList::Ptr mpl(new MessagePartList(this));
mpl->setIsRoot(isRoot);
for (; node; node = MessageCore::NodeHelper::nextSibling(node)) {
KMime::Content *parent = node->parent();
auto contents = parent ? parent->contents(): KMime::Content::List();
if (contents.isEmpty()) {
contents.append(node);
}
int i = contents.indexOf(const_cast<KMime::Content *>(node));
for (; i < contents.size(); ++i) {
node = contents.at(i);
if (mNodeHelper->nodeProcessed(node)) {
continue;
}
......
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