Messagelib

utils.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Sandro Knauß <sknauss@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "utils.h"
8
9using namespace MimeTreeParser;
10
11MimeMessagePart::Ptr MimeTreeParser::createAndParseTempNode(Interface::BodyPart &part, KMime::Content *parentNode, const char *content, const char *cntDesc)
12{
13 auto newNode = new KMime::Content();
14 newNode->setContent(KMime::CRLFtoLF(content));
15 newNode->parse();
16
17 if (!newNode->head().isEmpty()) {
18 newNode->contentDescription()->from7BitString(cntDesc);
19 }
20 part.nodeHelper()->attachExtraContent(parentNode, newNode);
21
22 return MimeMessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), newNode, false));
23}
24
25KMime::Content *MimeTreeParser::findTypeInDirectChilds(KMime::Content *content, const QByteArray &mimeType)
26{
27 if (mimeType.isEmpty()) {
28 return content;
29 }
30
31 const auto contents = content->contents();
32 for (const auto child : contents) {
33 if ((!child->contentType()->isEmpty()) && (mimeType == child->contentType(false)->mimeType())) {
34 return child;
35 }
36 }
37 return nullptr;
38}
39
40MessagePart::Ptr MimeTreeParser::toplevelTextNode(MessagePart::Ptr messageTree)
41{
42 const auto subParts = messageTree->subParts();
43 for (const auto &mp : subParts) {
44 auto text = mp.dynamicCast<TextMessagePart>();
45 auto attach = mp.dynamicCast<AttachmentMessagePart>();
46 if (text && !attach) {
47 return text;
48 } else if (const auto alternative = mp.dynamicCast<AlternativeMessagePart>()) {
49 return alternative;
50 } else {
51 auto ret = toplevelTextNode(mp);
52 if (ret) {
53 return ret;
54 }
55 }
56 }
57 return {};
58}
QList< Content * > contents() const
interface of message body parts.
Definition bodypart.h:45
virtual MimeTreeParser::ObjectTreeParser * objectTreeParser() const =0
For making it easier to refactor, add objectTreeParser.
virtual MimeTreeParser::NodeHelper * nodeHelper() const =0
Ok, this is ugly, exposing the node helper here, but there is too much useful stuff in there for real...
void attachExtraContent(KMime::Content *topLevelNode, KMime::Content *content)
Attach an extra node to an existing node.
KCALUTILS_EXPORT QString mimeType()
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:12:43 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.