From 37f18e26ca729fac64fd29164b09f3d3f1143520 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 11 Jul 2017 16:01:27 +0200 Subject: Fixed multipart/alternative replies --- framework/src/CMakeLists.txt | 2 ++ .../src/domain/mime/mimetreeparser/objecttreeparser.cpp | 13 ++++++++++++- framework/src/domain/mime/tests/mailtemplatetest.cpp | 13 +++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index b935fbed..75357b68 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt @@ -47,6 +47,8 @@ qt5_use_modules(frameworkplugin Core Quick Qml WebEngineWidgets Test) target_link_libraries(frameworkplugin sink kube_otp KF5::Codecs KF5::Package KF5::Contacts KAsync) install(TARGETS frameworkplugin DESTINATION ${FRAMEWORK_INSTALL_DIR}) +set(BUILD_TESTING ON) + add_subdirectory(domain/mime/tests) add_subdirectory(domain/mime/mimetreeparser) diff --git a/framework/src/domain/mime/mimetreeparser/objecttreeparser.cpp b/framework/src/domain/mime/mimetreeparser/objecttreeparser.cpp index 7e2be0e4..fc1b9793 100644 --- a/framework/src/domain/mime/mimetreeparser/objecttreeparser.cpp +++ b/framework/src/domain/mime/mimetreeparser/objecttreeparser.cpp @@ -6,6 +6,7 @@ Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Copyright (c) 2009 Andras Mantia Copyright (c) 2015 Sandro Knauß + Copyright (c) 2017 Christian Mollekopf KMail is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as @@ -134,6 +135,9 @@ QString ObjectTreeParser::plainTextContent() if (dynamic_cast(part.data())) { return true; } + if (dynamic_cast(part.data())) { + return true; + } return false; }); for (const auto &part : plainParts) { @@ -155,10 +159,17 @@ QString ObjectTreeParser::htmlContent() if (dynamic_cast(part.data())) { return true; } + if (dynamic_cast(part.data())) { + return true; + } return false; }); for (const auto &part : contentParts) { - content += part->text(); + if (auto p = dynamic_cast(part.data())) { + content += p->htmlContent(); + } else { + content += part->text(); + } } } return content; diff --git a/framework/src/domain/mime/tests/mailtemplatetest.cpp b/framework/src/domain/mime/tests/mailtemplatetest.cpp index 4dc8e2bd..e9752c9e 100644 --- a/framework/src/domain/mime/tests/mailtemplatetest.cpp +++ b/framework/src/domain/mime/tests/mailtemplatetest.cpp @@ -93,6 +93,19 @@ private slots: QVERIFY(content.contains("i noticed a new branch")); } + void testMultipartAlternative() + { + auto msg = readMail("alternative.mbox"); + KMime::Message::Ptr result; + MailTemplates::reply(msg, [&] (const KMime::Message::Ptr &r) { + result = r; + }); + QTRY_VERIFY(result); + auto content = removeFirstLine(result->body()); + QVERIFY(!content.isEmpty()); + QCOMPARE(unquote(content), QLatin1String("If you can see this text it means that your email client couldn't display our newsletter properly.\nPlease visit this link to view the newsletter on our website: http://www.gog.com/newsletter/\n")); + } + }; QTEST_MAIN(MailTemplateTest) -- cgit v1.2.3