diff options
Diffstat (limited to 'framework/src/domain/mime/tests/mailtemplatetest.cpp')
-rw-r--r-- | framework/src/domain/mime/tests/mailtemplatetest.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/framework/src/domain/mime/tests/mailtemplatetest.cpp b/framework/src/domain/mime/tests/mailtemplatetest.cpp index fbe5568d..62b17a6c 100644 --- a/framework/src/domain/mime/tests/mailtemplatetest.cpp +++ b/framework/src/domain/mime/tests/mailtemplatetest.cpp | |||
@@ -6,7 +6,52 @@ | |||
6 | #include <QDir> | 6 | #include <QDir> |
7 | #include <QtWebEngine> | 7 | #include <QtWebEngine> |
8 | 8 | ||
9 | #include <QGpgME/KeyListJob> | ||
10 | #include <QGpgME/Protocol> | ||
11 | #include <gpgme++/key.h> | ||
12 | #include <gpgme++/keylistresult.h> | ||
13 | |||
9 | #include "mailtemplates.h" | 14 | #include "mailtemplates.h" |
15 | #include "mailcrypto.h" | ||
16 | |||
17 | static std::vector< GpgME::Key, std::allocator< GpgME::Key > > getKeys(bool smime = false) | ||
18 | { | ||
19 | QGpgME::KeyListJob *job = nullptr; | ||
20 | |||
21 | if (smime) { | ||
22 | const QGpgME::Protocol *const backend = QGpgME::smime(); | ||
23 | Q_ASSERT(backend); | ||
24 | job = backend->keyListJob(false); | ||
25 | } else { | ||
26 | const QGpgME::Protocol *const backend = QGpgME::openpgp(); | ||
27 | Q_ASSERT(backend); | ||
28 | job = backend->keyListJob(false); | ||
29 | } | ||
30 | Q_ASSERT(job); | ||
31 | |||
32 | std::vector< GpgME::Key > keys; | ||
33 | GpgME::KeyListResult res = job->exec(QStringList(), true, keys); | ||
34 | |||
35 | if (!smime) { | ||
36 | Q_ASSERT(keys.size() == 3); | ||
37 | } | ||
38 | |||
39 | Q_ASSERT(!res.error()); | ||
40 | |||
41 | /* | ||
42 | qDebug() << "got private keys:" << keys.size(); | ||
43 | |||
44 | for (std::vector< GpgME::Key >::iterator i = keys.begin(); i != keys.end(); ++i) { | ||
45 | qDebug() << "key isnull:" << i->isNull() << "isexpired:" << i->isExpired(); | ||
46 | qDebug() << "key numuserIds:" << i->numUserIDs(); | ||
47 | for (uint k = 0; k < i->numUserIDs(); ++k) { | ||
48 | qDebug() << "userIDs:" << i->userID(k).email(); | ||
49 | } | ||
50 | } | ||
51 | */ | ||
52 | |||
53 | return keys; | ||
54 | } | ||
10 | 55 | ||
11 | static QByteArray readMailFromFile(const QString &mailFile) | 56 | static QByteArray readMailFromFile(const QString &mailFile) |
12 | { | 57 | { |
@@ -147,6 +192,29 @@ private slots: | |||
147 | //1 Plain + 2 Attachments | 192 | //1 Plain + 2 Attachments |
148 | QCOMPARE(contents.size(), 3); | 193 | QCOMPARE(contents.size(), 3); |
149 | } | 194 | } |
195 | |||
196 | void testCreatePlainMailSigned() | ||
197 | { | ||
198 | QStringList to = {{"to@example.org"}}; | ||
199 | QStringList cc = {{"cc@example.org"}};; | ||
200 | QStringList bcc = {{"bcc@example.org"}};; | ||
201 | KMime::Types::Mailbox from; | ||
202 | from.fromUnicodeString("from@example.org"); | ||
203 | QString subject = "subject"; | ||
204 | QString body = "body"; | ||
205 | QList<Attachment> attachments; | ||
206 | |||
207 | std::vector<GpgME::Key> keys = getKeys(); | ||
208 | |||
209 | auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, attachments, keys); | ||
210 | |||
211 | QVERIFY(result); | ||
212 | qWarning() << "---------------------------------"; | ||
213 | qWarning().noquote() << result->encodedContent(); | ||
214 | qWarning() << "---------------------------------"; | ||
215 | QCOMPARE(result->subject()->asUnicodeString(), subject); | ||
216 | QVERIFY(result->contentType()->isMimeType("multipart/signed")); | ||
217 | } | ||
150 | }; | 218 | }; |
151 | 219 | ||
152 | QTEST_MAIN(MailTemplateTest) | 220 | QTEST_MAIN(MailTemplateTest) |