Commit 859caf05 authored by Sandro Knauß's avatar Sandro Knauß
Browse files

Create utils for bodyformatter

parent fcaa3f62
......@@ -10,6 +10,7 @@ include_directories(${GPGME_INCLUDES})
set(libmimetreeparser_main_SRCS
bodyformatter/mailman.cpp
bodyformatter/utils.cpp
interfaces/bodypartformatter.cpp
job/kleojobexecutor.cpp
viewer/attachmentstrategy.cpp
......
......@@ -19,6 +19,8 @@
#include "mailman.h"
#include "utils.h"
#include "viewer/objecttreeparser.h"
#include "viewer/messagepart.h"
......@@ -47,27 +49,6 @@ Interface::BodyPartFormatter::Result MailmanBodyPartFormatter::format(Interface:
return Failed;
}
/**
1. Create a new partNode using 'content' data and Content-Description
found in 'cntDesc'.
2. Parse the 'node' to display the content.
*/
MimeMessagePart::Ptr createAndParseTempNode(Interface::BodyPart &part, KMime::Content *parentNode, const char *content, const char *cntDesc)
{
KMime::Content *newNode = new KMime::Content();
newNode->setContent(KMime::CRLFtoLF(content));
newNode->parse();
if (!newNode->head().isEmpty()) {
newNode->contentDescription()->from7BitString(cntDesc);
}
part.nodeHelper()->attachExtraContent(parentNode, newNode);
return MimeMessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), newNode, false));
}
bool MailmanBodyPartFormatter::isMailmanMessage(KMime::Content* curNode) const
{
if (!curNode || curNode->head().isEmpty()) {
......
#include "utils.h"
#include <MessageCore/NodeHelper>
using namespace MessageViewer;
MimeMessagePart::Ptr MessageViewer::createAndParseTempNode(Interface::BodyPart &part, KMime::Content *parentNode, const char *content, const char *cntDesc)
{
KMime::Content *newNode = new KMime::Content();
newNode->setContent(KMime::CRLFtoLF(content));
newNode->parse();
if (!newNode->head().isEmpty()) {
newNode->contentDescription()->from7BitString(cntDesc);
}
part.nodeHelper()->attachExtraContent(parentNode, newNode);
return MimeMessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), newNode, false));
}
KMime::Content *MessageViewer::findType(KMime::Content *content, const QByteArray &mimeType, bool deep, bool wide)
{
if ((!content->contentType()->isEmpty())
&& (mimeType.isEmpty() || (mimeType == content->contentType()->mimeType()))) {
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);
}
return Q_NULLPTR;
}
\ No newline at end of file
/*
Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef __MIMETREEPARSER_BODYFORAMATTER_UTILS_H__
#define __MIMETREEPARSER_BODYFORAMATTER_UTILS_H__
#include "interfaces/bodypart.h"
#include "viewer/messagepart.h"
#include <KMime/Content>
namespace MessageViewer
{
/**
1. Create a new partNode using 'content' data and Content-Description
found in 'cntDesc'.
2. Parse the 'node' to display the content.
*/
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);
}
#endif
\ No newline at end of file
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