diff options
-rw-r--r-- | framework/src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | framework/src/domain/mime/mailtemplates.cpp | 10 | ||||
-rw-r--r-- | framework/src/domain/mime/tests/CMakeLists.txt | 15 | ||||
-rw-r--r-- | framework/src/domain/mime/tests/mailtemplatetest.cpp | 99 |
4 files changed, 121 insertions, 4 deletions
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index 1c53530f..b935fbed 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt | |||
@@ -47,6 +47,7 @@ qt5_use_modules(frameworkplugin Core Quick Qml WebEngineWidgets Test) | |||
47 | target_link_libraries(frameworkplugin sink kube_otp KF5::Codecs KF5::Package KF5::Contacts KAsync) | 47 | target_link_libraries(frameworkplugin sink kube_otp KF5::Codecs KF5::Package KF5::Contacts KAsync) |
48 | install(TARGETS frameworkplugin DESTINATION ${FRAMEWORK_INSTALL_DIR}) | 48 | install(TARGETS frameworkplugin DESTINATION ${FRAMEWORK_INSTALL_DIR}) |
49 | 49 | ||
50 | add_subdirectory(domain/mime/tests) | ||
50 | add_subdirectory(domain/mime/mimetreeparser) | 51 | add_subdirectory(domain/mime/mimetreeparser) |
51 | 52 | ||
52 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) | 53 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) |
diff --git a/framework/src/domain/mime/mailtemplates.cpp b/framework/src/domain/mime/mailtemplates.cpp index d41039db..c202af80 100644 --- a/framework/src/domain/mime/mailtemplates.cpp +++ b/framework/src/domain/mime/mailtemplates.cpp | |||
@@ -396,9 +396,11 @@ void plainMessageText(const QString &plainTextContent, const QString &htmlConten | |||
396 | auto page = new QWebEnginePage; | 396 | auto page = new QWebEnginePage; |
397 | setupPage(page); | 397 | setupPage(page); |
398 | page->setHtml(htmlContent); | 398 | page->setHtml(htmlContent); |
399 | page->toPlainText([=] (const QString &plaintext) { | 399 | QObject::connect(page, &QWebEnginePage::loadFinished, [=] (bool ok) { |
400 | page->deleteLater(); | 400 | page->toPlainText([=] (const QString &plaintext) { |
401 | callback(plaintext); | 401 | page->deleteLater(); |
402 | callback(plaintext); | ||
403 | }); | ||
402 | }); | 404 | }); |
403 | return; | 405 | return; |
404 | } | 406 | } |
@@ -860,7 +862,7 @@ void MailTemplates::reply(const KMime::Message::Ptr &origMsg, const std::functio | |||
860 | makeValidHtml(htmlBodyResult, headElement); | 862 | makeValidHtml(htmlBodyResult, headElement); |
861 | } | 863 | } |
862 | 864 | ||
863 | //Assemble the message */ | 865 | //Assemble the message |
864 | addProcessedBodyToMessage(msg, plainBodyResult, htmlBodyResult, false); | 866 | addProcessedBodyToMessage(msg, plainBodyResult, htmlBodyResult, false); |
865 | applyCharset(msg, origMsg); | 867 | applyCharset(msg, origMsg); |
866 | msg->assemble(); | 868 | msg->assemble(); |
diff --git a/framework/src/domain/mime/tests/CMakeLists.txt b/framework/src/domain/mime/tests/CMakeLists.txt new file mode 100644 index 00000000..4fad00a1 --- /dev/null +++ b/framework/src/domain/mime/tests/CMakeLists.txt | |||
@@ -0,0 +1,15 @@ | |||
1 | add_definitions( -DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../testdata" ) | ||
2 | |||
3 | include_directories( | ||
4 | ${CMAKE_CURRENT_BINARY_DIR} | ||
5 | ${CMAKE_CURRENT_SOURCE_DIR}/.. | ||
6 | ) | ||
7 | |||
8 | include(ECMAddTests) | ||
9 | find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Core Test WebEngine) | ||
10 | |||
11 | ecm_add_test(mailtemplatetest.cpp | ||
12 | TEST_NAME "mailtemplatetest" | ||
13 | NAME_PREFIX "" | ||
14 | LINK_LIBRARIES Qt5::Core Qt5::Test Qt5::WebEngine frameworkplugin | ||
15 | ) | ||
diff --git a/framework/src/domain/mime/tests/mailtemplatetest.cpp b/framework/src/domain/mime/tests/mailtemplatetest.cpp new file mode 100644 index 00000000..18f315f1 --- /dev/null +++ b/framework/src/domain/mime/tests/mailtemplatetest.cpp | |||
@@ -0,0 +1,99 @@ | |||
1 | #include <QTest> | ||
2 | #include <QDebug> | ||
3 | #include <QSignalSpy> | ||
4 | #include <functional> | ||
5 | #include <QStandardPaths> | ||
6 | #include <QDir> | ||
7 | #include <QtWebEngine> | ||
8 | |||
9 | #include "mailtemplates.h" | ||
10 | |||
11 | static QByteArray readMailFromFile(const QString &mailFile) | ||
12 | { | ||
13 | Q_ASSERT(!QString::fromLatin1(MAIL_DATA_DIR).isEmpty()); | ||
14 | QFile file(QLatin1String(MAIL_DATA_DIR) + QLatin1Char('/') + mailFile); | ||
15 | file.open(QIODevice::ReadOnly); | ||
16 | Q_ASSERT(file.isOpen()); | ||
17 | return file.readAll(); | ||
18 | } | ||
19 | |||
20 | |||
21 | static KMime::Message::Ptr readMail(const QString &mailFile) | ||
22 | { | ||
23 | auto msg = KMime::Message::Ptr::create(); | ||
24 | msg->setContent(readMailFromFile(mailFile)); | ||
25 | msg->parse(); | ||
26 | return msg; | ||
27 | } | ||
28 | |||
29 | static QString removeFirstLine(const QString &s) | ||
30 | { | ||
31 | return s.mid(s.indexOf("\n") + 1); | ||
32 | } | ||
33 | |||
34 | static QString normalize(const QString &s) | ||
35 | { | ||
36 | auto text = s; | ||
37 | text.replace(">", ""); | ||
38 | text.replace("\n", ""); | ||
39 | text.replace(" ", ""); | ||
40 | return text; | ||
41 | } | ||
42 | |||
43 | static QString unquote(const QString &s) | ||
44 | { | ||
45 | auto text = s; | ||
46 | text.replace("> ", ""); | ||
47 | return text; | ||
48 | } | ||
49 | |||
50 | class MailTemplateTest : public QObject | ||
51 | { | ||
52 | Q_OBJECT | ||
53 | private slots: | ||
54 | |||
55 | void initTestCase() | ||
56 | { | ||
57 | QtWebEngine::initialize(); | ||
58 | } | ||
59 | |||
60 | void testPlain() | ||
61 | { | ||
62 | auto msg = readMail("plaintext.mbox"); | ||
63 | KMime::Message::Ptr result; | ||
64 | MailTemplates::reply(msg, [&] (const KMime::Message::Ptr &r) { | ||
65 | result = r; | ||
66 | }); | ||
67 | QTRY_VERIFY(result); | ||
68 | QCOMPARE(normalize(removeFirstLine(result->body())), normalize(msg->body())); | ||
69 | } | ||
70 | |||
71 | void testHtml() | ||
72 | { | ||
73 | auto msg = readMail("html.mbox"); | ||
74 | KMime::Message::Ptr result; | ||
75 | MailTemplates::reply(msg, [&] (const KMime::Message::Ptr &r) { | ||
76 | result = r; | ||
77 | }); | ||
78 | QTRY_VERIFY(result); | ||
79 | QCOMPARE(unquote(removeFirstLine(result->body())), QLatin1String("HTML text")); | ||
80 | } | ||
81 | |||
82 | void testMultipartSigned() | ||
83 | { | ||
84 | auto msg = readMail("openpgp-signed-mailinglist.mbox"); | ||
85 | KMime::Message::Ptr result; | ||
86 | MailTemplates::reply(msg, [&] (const KMime::Message::Ptr &r) { | ||
87 | result = r; | ||
88 | }); | ||
89 | QTRY_VERIFY(result); | ||
90 | auto content = normalize(removeFirstLine(result->body())); | ||
91 | QVERIFY(!content.isEmpty()); | ||
92 | QEXPECT_FAIL("", "Not implemented yet.", Continue); | ||
93 | QVERIFY(content.contains("i noticed a new branch")); | ||
94 | } | ||
95 | |||
96 | }; | ||
97 | |||
98 | QTEST_MAIN(MailTemplateTest) | ||
99 | #include "mailtemplatetest.moc" | ||