From 964f0003584a0b745045db75ca6184f54eddd859 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 4 Jun 2017 15:21:05 +0200 Subject: Rely on isAttachment to collect attachments --- .../src/domain/mime/mimetreeparser/nodehelper.cpp | 85 ---------------------- 1 file changed, 85 deletions(-) (limited to 'framework/src/domain/mime/mimetreeparser/nodehelper.cpp') diff --git a/framework/src/domain/mime/mimetreeparser/nodehelper.cpp b/framework/src/domain/mime/mimetreeparser/nodehelper.cpp index 3005ea0f..4e60fa68 100644 --- a/framework/src/domain/mime/mimetreeparser/nodehelper.cpp +++ b/framework/src/domain/mime/mimetreeparser/nodehelper.cpp @@ -456,89 +456,4 @@ QList< KMime::Content * > NodeHelper::extraContents(KMime::Content *topLevelnode return mExtraContents.value(topLevelnode); } -void NodeHelper::mergeExtraNodes(KMime::Content *node) -{ - if (!node) { - return; - } - - const QList extraNodes = extraContents(node); - for (KMime::Content *extra : extraNodes) { - if (node->bodyIsMessage()) { - qCWarning(MIMETREEPARSER_LOG) << "Asked to attach extra content to a kmime::message, this does not make sense. Attaching to:" << node << - node->encodedContent() << "\n====== with =======\n" << extra << extra->encodedContent(); - continue; - } - KMime::Content *c = new KMime::Content(node); - c->setContent(extra->encodedContent()); - c->parse(); - node->addContent(c); - } - - Q_FOREACH (KMime::Content *child, node->contents()) { - mergeExtraNodes(child); - } -} - -void NodeHelper::cleanFromExtraNodes(KMime::Content *node) -{ - if (!node) { - return; - } - const QList extraNodes = extraContents(node); - for (KMime::Content *extra : extraNodes) { - QByteArray s = extra->encodedContent(); - const auto children = node->contents(); - for (KMime::Content *c : children) { - if (c->encodedContent() == s) { - node->removeContent(c); - } - } - } - Q_FOREACH (KMime::Content *child, node->contents()) { - cleanFromExtraNodes(child); - } -} - -KMime::Message *NodeHelper::messageWithExtraContent(KMime::Content *topLevelNode) -{ - /*The merge is done in several steps: - 1) merge the extra nodes into topLevelNode - 2) copy the modified (merged) node tree into a new node tree - 3) restore the original node tree in topLevelNode by removing the extra nodes from it - - The reason is that extra nodes are assigned by pointer value to the nodes in the original tree. - */ - if (!topLevelNode) { - return nullptr; - } - - mergeExtraNodes(topLevelNode); - - KMime::Message *m = new KMime::Message; - m->setContent(topLevelNode->encodedContent()); - m->parse(); - - cleanFromExtraNodes(topLevelNode); -// qCDebug(MIMETREEPARSER_LOG) << "MESSAGE WITH EXTRA: " << m->encodedContent(); -// qCDebug(MIMETREEPARSER_LOG) << "MESSAGE WITHOUT EXTRA: " << topLevelNode->encodedContent(); - - return m; -} - -QVector NodeHelper::attachmentsOfExtraContents() const -{ - QVector result; - for (auto it = mExtraContents.begin(); it != mExtraContents.end(); ++it) { - foreach (auto content, it.value()) { - if (KMime::isAttachment(content)) { - result.push_back(content); - } else { - result += content->attachments(); - } - } - } - return result; -} - } -- cgit v1.2.3