File indexing completed on 2025-01-19 04:51:56
0001 /* 0002 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> 0003 0004 This library is free software; you can redistribute it and/or modify it 0005 under the terms of the GNU Library General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or (at your 0007 option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, but WITHOUT 0010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 0012 License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to the 0016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0017 02110-1301, USA. 0018 */ 0019 #include "messageparser.h" 0020 0021 #include <sink/mimetreeparser/objecttreeparser.h> 0022 #include <QElapsedTimer> 0023 #include <sink/log.h> 0024 0025 #include "partmodel.h" 0026 #include "attachmentmodel.h" 0027 // #include "modeltest.h" 0028 #include "async.h" 0029 0030 class MessagePartPrivate 0031 { 0032 public: 0033 std::shared_ptr<MimeTreeParser::ObjectTreeParser> mParser; 0034 }; 0035 0036 MessageParser::MessageParser(QObject *parent) 0037 : QObject(parent) 0038 , d(std::unique_ptr<MessagePartPrivate>(new MessagePartPrivate)) 0039 { 0040 0041 } 0042 0043 MessageParser::~MessageParser() 0044 { 0045 0046 } 0047 0048 QVariant MessageParser::message() const 0049 { 0050 return QVariant(); 0051 } 0052 0053 void MessageParser::setMessage(const QVariant &message) 0054 { 0055 mRawContent = message.toString(); 0056 asyncRun<std::shared_ptr<MimeTreeParser::ObjectTreeParser>>(this, [=] { 0057 QElapsedTimer time; 0058 time.start(); 0059 auto parser = std::make_shared<MimeTreeParser::ObjectTreeParser>(); 0060 parser->parseObjectTree(message.toByteArray()); 0061 SinkLog() << "Message parsing took: " << time.elapsed(); 0062 parser->decryptParts(); 0063 SinkLog() << "Message parsing and decryption/verification: " << time.elapsed(); 0064 return parser; 0065 }, 0066 [this](const std::shared_ptr<MimeTreeParser::ObjectTreeParser> &parser) { 0067 d->mParser = parser; 0068 emit htmlChanged(); 0069 }); 0070 } 0071 0072 QString MessageParser::rawContent() const 0073 { 0074 return mRawContent; 0075 } 0076 0077 bool MessageParser::loaded() const 0078 { 0079 return bool{d->mParser}; 0080 } 0081 0082 QString MessageParser::structureAsString() const 0083 { 0084 if (!d->mParser) { 0085 return nullptr; 0086 } 0087 return d->mParser->structureAsString(); 0088 } 0089 0090 QAbstractItemModel *MessageParser::parts() const 0091 { 0092 if (!d->mParser) { 0093 return nullptr; 0094 } 0095 const auto model = new PartModel(d->mParser); 0096 // new ModelTest(model, model); 0097 return model; 0098 } 0099 0100 QAbstractItemModel *MessageParser::attachments() const 0101 { 0102 if (!d->mParser) { 0103 return nullptr; 0104 } 0105 const auto model = new AttachmentModel(d->mParser); 0106 // new ModelTest(model, model); 0107 return model; 0108 }