diff --git a/plugins/messageviewer/bodypartformatter/calendar/text_calendar.cpp b/plugins/messageviewer/bodypartformatter/calendar/text_calendar.cpp --- a/plugins/messageviewer/bodypartformatter/calendar/text_calendar.cpp +++ b/plugins/messageviewer/bodypartformatter/calendar/text_calendar.cpp @@ -41,12 +41,13 @@ #include #include +#include #include #include #include #include #include -#include +#include using namespace MessageViewer; #include @@ -74,6 +75,8 @@ #include #include +#include +#include #include #include #include @@ -157,7 +160,7 @@ class KMInvitationFormatterHelper : public KCalUtils::InvitationFormatterHelper { public: - KMInvitationFormatterHelper(MimeTreeParser::Interface::BodyPart *bodyPart, const KCalCore::MemoryCalendar::Ptr &calendar) + KMInvitationFormatterHelper(const MimeTreeParser::MessagePartPtr &bodyPart, const KCalCore::MemoryCalendar::Ptr &calendar) : mBodyPart(bodyPart) , mCalendar(calendar) { @@ -174,24 +177,23 @@ } private: - MimeTreeParser::Interface::BodyPart *mBodyPart = nullptr; + MimeTreeParser::MessagePartPtr mBodyPart; KCalCore::MemoryCalendar::Ptr mCalendar; }; -class Formatter : public MimeTreeParser::Interface::BodyPartFormatter +class Formatter : public MessageViewer::MessagePartRendererBase { public: - Result format(MimeTreeParser::Interface::BodyPart *bodyPart, MimeTreeParser::HtmlWriter *writer) const override + bool render(const MimeTreeParser::MessagePartPtr &msgPart, MimeTreeParser::HtmlWriter* writer, MessageViewer::RenderContext*) const override { - if (!writer) { - // Guard against crashes in createReply() - return Ok; - } - - auto nodeHelper = bodyPart->nodeHelper(); + QMimeDatabase db; + auto mt = db.mimeTypeForName(QString::fromLatin1(msgPart->content()->contentType()->mimeType().toLower())); + if (!mt.isValid() || mt.name() != QLatin1String("text/calendar")) + return false; + auto nodeHelper = msgPart->nodeHelper(); if (!nodeHelper) { - return Ok; + return false; } /** Formating is async now because we need to fetch incidences from akonadi. @@ -202,45 +204,45 @@ BodyPartMementos are documented in MessageViewer/ObjectTreeParser */ - MemoryCalendarMemento *memento = dynamic_cast(bodyPart->memento()); + MemoryCalendarMemento *memento = dynamic_cast(msgPart->memento()); if (memento) { - KMime::Message *const message = dynamic_cast(bodyPart->topLevelContent()); + KMime::Message *const message = dynamic_cast(msgPart->content()->topLevel()); if (!message) { qCWarning(TEXT_CALENDAR_LOG) << "The top-level content is not a message. Cannot handle the invitation then."; - return Failed; + return false; } if (memento->finished()) { - KMInvitationFormatterHelper helper(bodyPart, memento->calendar()); + KMInvitationFormatterHelper helper(msgPart, memento->calendar()); QString source; // If the bodypart does not have a charset specified, we need to fall back to utf8, // not the KMail fallback encoding, so get the contents as binary and decode explicitly. - if (bodyPart->contentTypeParameter("charset").isEmpty()) { - const QByteArray &ba = bodyPart->asBinary(); + if (msgPart->content()->contentType()->parameter(QStringLiteral("charset")).isEmpty()) { + const QByteArray &ba = msgPart->content()->decodedContent(); source = QString::fromUtf8(ba); } else { - source = bodyPart->asText(); + source = msgPart->text(); } MemoryCalendar::Ptr cl(new MemoryCalendar(QTimeZone::systemTimeZone())); const QString html = KCalUtils::IncidenceFormatter::formatICalInvitationNoHtml( source, cl, &helper, message->sender()->asUnicodeString()); if (html.isEmpty()) { - return AsIcon; + return false; } writer->write(html); } } else { MemoryCalendarMemento *memento = new MemoryCalendarMemento(); - bodyPart->setBodyPartMemento(memento); + msgPart->setMemento(memento); QObject::connect(memento, &MemoryCalendarMemento::update, nodeHelper, &MimeTreeParser::NodeHelper::update); } - return Ok; + return true; } }; @@ -1475,28 +1477,21 @@ } }; -class Plugin : public QObject, public MimeTreeParser::Interface::BodyPartFormatterPlugin, public MessageViewer::MessagePartRenderPlugin +class Plugin : public QObject, public MessageViewer::MessagePartRenderPlugin { Q_OBJECT - Q_INTERFACES(MimeTreeParser::Interface::BodyPartFormatterPlugin) Q_INTERFACES(MessageViewer::MessagePartRenderPlugin) Q_PLUGIN_METADATA(IID "com.kde.messageviewer.bodypartformatter" FILE "text_calendar.json") public: - const MimeTreeParser::Interface::BodyPartFormatter *bodyPartFormatter(int idx) const override + MessageViewer::MessagePartRendererBase* renderer(int idx) override { if (idx == 0) { return new Formatter(); } else { - return 0; + return nullptr; } } - MessageViewer::MessagePartRendererBase* renderer(int index) override - { - Q_UNUSED(index); - return nullptr; - } - const MessageViewer::Interface::BodyPartURLHandler *urlHandler(int idx) const override { if (idx == 0) { diff --git a/plugins/messageviewer/bodypartformatter/calendar/text_calendar.json b/plugins/messageviewer/bodypartformatter/calendar/text_calendar.json --- a/plugins/messageviewer/bodypartformatter/calendar/text_calendar.json +++ b/plugins/messageviewer/bodypartformatter/calendar/text_calendar.json @@ -3,6 +3,6 @@ { "mimetype": "text/calendar" } ], "renderer": [ - { "type": "MimeTreeParser::AttachmentMessagePart" } + { "type": "MimeTreeParser::TextMessagePart" } ] }