Commit 159668f1 authored by Volker Krause's avatar Volker Krause
Browse files

Search the entire MIME hierarchy upwards for a matching header

The old code did that as well, and it's still necessary for the partial
MIME message extraction that the KMail plugin does. That also has nested
MIME messages in a single KMime tree, which breaks when just considering
the top-level element.
parent 89203fd5
...@@ -43,6 +43,25 @@ bool MimeDocumentProcessor::canHandleData(const QByteArray &encodedData, QString ...@@ -43,6 +43,25 @@ bool MimeDocumentProcessor::canHandleData(const QByteArray &encodedData, QString
fileName.endsWith(QLatin1String(".mbox"), Qt::CaseInsensitive); fileName.endsWith(QLatin1String(".mbox"), Qt::CaseInsensitive);
} }
template <typename T>
static const T* findHeader(KMime::Content *content)
{
auto h = content->header<T>();
if (h || !content->parent()) {
return h;
}
return findHeader<T>(content->parent());
}
static const KMime::Headers::Base* findHeader(KMime::Content *content, const char *headerType)
{
auto h = content->headerByType(headerType);
if (h || !content->parent()) {
return h;
}
return findHeader(content->parent(), headerType);
}
ExtractorDocumentNode MimeDocumentProcessor::createNodeFromData(const QByteArray &encodedData) const ExtractorDocumentNode MimeDocumentProcessor::createNodeFromData(const QByteArray &encodedData) const
{ {
auto msg = new KMime::Message; auto msg = new KMime::Message;
...@@ -56,7 +75,7 @@ ExtractorDocumentNode MimeDocumentProcessor::createNodeFromData(const QByteArray ...@@ -56,7 +75,7 @@ ExtractorDocumentNode MimeDocumentProcessor::createNodeFromData(const QByteArray
ExtractorDocumentNode node; ExtractorDocumentNode node;
node.setContent<Internal::OwnedPtr<KMime::Content>>(msg); node.setContent<Internal::OwnedPtr<KMime::Content>>(msg);
auto dateHdr = msg->header<KMime::Headers::Date>(); auto dateHdr = findHeader<KMime::Headers::Date>(msg);
if (dateHdr) { if (dateHdr) {
node.setContextDateTime(dateHdr->dateTime()); node.setContextDateTime(dateHdr->dateTime());
} }
...@@ -130,7 +149,7 @@ void MimeDocumentProcessor::expandNode(ExtractorDocumentNode &node, const Extrac ...@@ -130,7 +149,7 @@ void MimeDocumentProcessor::expandNode(ExtractorDocumentNode &node, const Extrac
bool MimeDocumentProcessor::matches(const ExtractorFilter &filter, const ExtractorDocumentNode &node) const bool MimeDocumentProcessor::matches(const ExtractorFilter &filter, const ExtractorDocumentNode &node) const
{ {
const auto content = node.content<KMime::Content*>(); const auto content = node.content<KMime::Content*>();
const auto header = content->headerByType(filter.fieldName().toUtf8().constData()); const auto header = findHeader(content, filter.fieldName().toUtf8().constData());
return header ? filter.matches(header->asUnicodeString()) : false; return header ? filter.matches(header->asUnicodeString()) : false;
} }
......
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