File indexing completed on 2024-06-16 05:01:10
0001 /* 0002 objecttreeparser.h 0003 0004 This file is part of KMail, the KDE mail client. 0005 Copyright (c) 2003 Marc Mutz <mutz@kde.org> 0006 Copyright (C) 2002-2003, 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net 0007 Copyright (c) 2009 Andras Mantia <andras@kdab.net> 0008 0009 KMail is free software; you can redistribute it and/or modify it 0010 under the terms of the GNU General Public License, version 2, as 0011 published by the Free Software Foundation. 0012 0013 KMail is distributed in the hope that it will be useful, but 0014 WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 General Public License for more details. 0017 0018 You should have received a copy of the GNU General Public License 0019 along with this program; if not, write to the Free Software 0020 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0021 0022 In addition, as a special exception, the copyright holders give 0023 permission to link the code of this program with any edition of 0024 the Qt library by Trolltech AS, Norway (or with modified versions 0025 of Qt that use the same license as Qt), and distribute linked 0026 combinations including the two. You must obey the GNU General 0027 Public License in all respects for all of the code used other than 0028 Qt. If you modify this file, you may extend this exception to 0029 your version of the file, but you are not obligated to do so. If 0030 you do not wish to do so, delete this exception statement from 0031 your version. 0032 */ 0033 #pragma once 0034 0035 #include "messagepart.h" 0036 0037 #include <functional> 0038 #include <QSharedPointer> 0039 0040 class QString; 0041 0042 namespace KMime 0043 { 0044 class Content; 0045 } 0046 0047 namespace MimeTreeParser 0048 { 0049 0050 typedef QSharedPointer<MessagePart> MessagePartPtr; 0051 0052 /** 0053 Entry point to parse mime messages. 0054 0055 Content returned by the ObjectTreeParser (including messageparts), 0056 is normalized to not contain any CRLF's but only LF's (just like KMime). 0057 */ 0058 class ObjectTreeParser 0059 { 0060 //Disable copy 0061 ObjectTreeParser(const ObjectTreeParser &other); 0062 public: 0063 explicit ObjectTreeParser() = default; 0064 virtual ~ObjectTreeParser() = default; 0065 0066 QString structureAsString() const; 0067 void print(); 0068 0069 /** 0070 * The text of the message, ie. what would appear in the 0071 * composer's text editor if this was edited or replied to. 0072 * This is usually the content of the first text/plain MIME part. 0073 */ 0074 QString plainTextContent(); 0075 0076 /** 0077 * Similar to plainTextContent(), but returns the HTML source of the first text/html MIME part. 0078 */ 0079 QString htmlContent(); 0080 0081 /** Parse beginning at a given node and recursively parsing 0082 the children of that node and it's next sibling. */ 0083 void parseObjectTree(KMime::Content *node); 0084 void parseObjectTree(const QByteArray &mimeMessage); 0085 MessagePartPtr parsedPart() const; 0086 KMime::Content *find(const std::function<bool(KMime::Content *)> &select); 0087 QVector<MessagePartPtr> collectContentParts(); 0088 QVector<MessagePartPtr> collectContentParts(MessagePart::Ptr start); 0089 QVector<MessagePartPtr> collectAttachmentParts(); 0090 0091 /** Decrypt parts and verify signatures */ 0092 void decryptAndVerify(); 0093 //DEPRECATED calls decryptAndVerify 0094 void decryptParts(); 0095 0096 /** Import any certificates found in the message */ 0097 void importCertificates(); 0098 0099 /** Embedd content referenced by cid by inlining */ 0100 QString resolveCidLinks(const QString &html); 0101 0102 private: 0103 /** 0104 * Does the actual work for parseObjectTree. Unlike parseObjectTree(), this does not change the 0105 * top-level content. 0106 */ 0107 MessagePartPtr parseObjectTreeInternal(KMime::Content *node, bool mOnlyOneMimePart); 0108 QVector<MessagePartPtr> processType(KMime::Content *node, const QByteArray &mediaType, const QByteArray &subType); 0109 0110 QVector<MessagePartPtr> defaultHandling(KMime::Content *node); 0111 0112 const QTextCodec *codecFor(KMime::Content *node) const; 0113 0114 KMime::Content *mTopLevelContent{nullptr}; 0115 MessagePartPtr mParsedPart; 0116 0117 KMime::Message::Ptr mMsg; 0118 0119 friend class MessagePart; 0120 friend class EncryptedMessagePart; 0121 friend class SignedMessagePart; 0122 friend class EncapsulatedRfc822MessagePart; 0123 friend class TextMessagePart; 0124 friend class HtmlMessagePart; 0125 friend class TextPlainBodyPartFormatter; 0126 friend class MultiPartSignedBodyPartFormatter; 0127 friend class ApplicationPkcs7MimeBodyPartFormatter; 0128 }; 0129 0130 } 0131