diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-06-30 16:23:20 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-06-30 16:23:20 +0200 |
commit | ab912af8158028206cf43b0a6ca0eac8eef040f4 (patch) | |
tree | 01010326905cf61a816b74b693b520a719ef22ac /framework/src/domain/mime/tests/mailtemplatetest.cpp | |
parent | 2945877a9f6062e6a2c5aaf2e6a1fe9c545a6869 (diff) | |
download | kube-ab912af8158028206cf43b0a6ca0eac8eef040f4.tar.gz kube-ab912af8158028206cf43b0a6ca0eac8eef040f4.zip |
Fixed html to plaintext conversion
Diffstat (limited to 'framework/src/domain/mime/tests/mailtemplatetest.cpp')
-rw-r--r-- | framework/src/domain/mime/tests/mailtemplatetest.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
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" | ||