File indexing completed on 2024-05-12 05:28:19
0001 // SPDX-FileCopyrightText: 2016 Sandro Knauß <sknauss@kde.org> 0002 // SPDX-FileCopyrightText: 2003 Marc Mutz <mutz@kde.org> 0003 // SPDX-FileCopyrightText: 2002-2003, 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net 0004 // SPDX-FileCopyrightText: 2009 Andras Mantia <andras@kdab.net> 0005 // SPDX-License-Identifier: LGPL-2.0-or-later 0006 0007 #pragma once 0008 0009 #include "messagepart.h" 0010 0011 #include <QSharedPointer> 0012 #include <functional> 0013 0014 class QString; 0015 0016 namespace KMime 0017 { 0018 class Content; 0019 } 0020 0021 namespace MimeTreeParser 0022 { 0023 0024 typedef QSharedPointer<MessagePart> MessagePartPtr; 0025 0026 /** 0027 Entry point to parse mime messages. 0028 0029 Content returned by the ObjectTreeParser (including messageparts), 0030 is normalized to not contain any CRLF's but only LF's (just like KMime). 0031 */ 0032 class ObjectTreeParser 0033 { 0034 // Disable copy 0035 ObjectTreeParser(const ObjectTreeParser &other); 0036 0037 public: 0038 explicit ObjectTreeParser() = default; 0039 virtual ~ObjectTreeParser() = default; 0040 0041 QString structureAsString() const; 0042 void print(); 0043 0044 /** 0045 * The text of the message, ie. what would appear in the 0046 * composer's text editor if this was edited or replied to. 0047 * This is usually the content of the first text/plain MIME part. 0048 */ 0049 QString plainTextContent(); 0050 0051 /** 0052 * Similar to plainTextContent(), but returns the HTML source of the first text/html MIME part. 0053 */ 0054 QString htmlContent(); 0055 0056 /** Parse beginning at a given node and recursively parsing 0057 the children of that node and it's next sibling. */ 0058 void parseObjectTree(KMime::Content *node); 0059 void parseObjectTree(const QByteArray &mimeMessage); 0060 MessagePartPtr parsedPart() const; 0061 KMime::Content *find(const std::function<bool(KMime::Content *)> &select); 0062 QVector<MessagePartPtr> collectContentParts(); 0063 QVector<MessagePartPtr> collectContentParts(MessagePart::Ptr start); 0064 QVector<MessagePartPtr> collectAttachmentParts(); 0065 0066 /** Decrypt parts and verify signatures */ 0067 void decryptAndVerify(); 0068 // DEPRECATED calls decryptAndVerify 0069 void decryptParts(); 0070 0071 /** Import any certificates found in the message */ 0072 void importCertificates(); 0073 0074 /** Embedd content referenced by cid by inlining */ 0075 QString resolveCidLinks(const QString &html); 0076 0077 private: 0078 /** 0079 * Does the actual work for parseObjectTree. Unlike parseObjectTree(), this does not change the 0080 * top-level content. 0081 */ 0082 MessagePartPtr parseObjectTreeInternal(KMime::Content *node, bool mOnlyOneMimePart); 0083 QVector<MessagePartPtr> processType(KMime::Content *node, const QByteArray &mediaType, const QByteArray &subType); 0084 0085 QVector<MessagePartPtr> defaultHandling(KMime::Content *node); 0086 0087 const QTextCodec *codecFor(KMime::Content *node) const; 0088 0089 KMime::Content *mTopLevelContent{nullptr}; 0090 MessagePartPtr mParsedPart; 0091 0092 KMime::Message::Ptr mMsg; 0093 0094 friend class MessagePart; 0095 friend class EncryptedMessagePart; 0096 friend class SignedMessagePart; 0097 friend class EncapsulatedRfc822MessagePart; 0098 friend class TextMessagePart; 0099 friend class HtmlMessagePart; 0100 friend class TextPlainBodyPartFormatter; 0101 friend class MultiPartSignedBodyPartFormatter; 0102 friend class ApplicationPkcs7MimeBodyPartFormatter; 0103 }; 0104 0105 }