From 2fdddd2f795da4645dc9a48fee4865324143a21b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Mon, 18 Jul 2016 15:35:07 +0200 Subject: first tests with mimetreeparser interface --- .../domain/mimetreeparser/tests/interfacetest.cpp | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 framework/domain/mimetreeparser/tests/interfacetest.cpp (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp new file mode 100644 index 00000000..1e8c5302 --- /dev/null +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -0,0 +1,47 @@ +/* + Copyright (c) 2016 Sandro Knauß + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include "interface.h" + +#include + +QByteArray readMailFromFile(const QString &mailFile) +{ + QFile file(QLatin1String(MAIL_DATA_DIR) + QLatin1Char('/') + mailFile); + file.open(QIODevice::ReadOnly); + Q_ASSERT(file.isOpen()); + return file.readAll(); +} + + +class InterfaceTest : public QObject +{ + Q_OBJECT +private slots: + + void testTextMail() + { + Parser parser(readMailFromFile("plaintext.mbox")); + auto contentPart = parser.collectContentPart(); + //QVERIFY((bool)contentPart); + } +}; + +QTEST_GUILESS_MAIN(InterfaceTest) +#include "interfacetest.moc" \ No newline at end of file -- cgit v1.2.3 From 9516f3b02f74f239ce2776abf7cf1147952065cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Tue, 19 Jul 2016 14:46:23 +0200 Subject: new mimetreeparser interface Reviewers: cmollekopf Maniphest Tasks: T3208 Differential Revision: https://phabricator.kde.org/D2221 --- .../domain/mimetreeparser/tests/interfacetest.cpp | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index 1e8c5302..fd828960 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -39,7 +39,30 @@ private slots: { Parser parser(readMailFromFile("plaintext.mbox")); auto contentPart = parser.collectContentPart(); - //QVERIFY((bool)contentPart); + QVERIFY((bool)contentPart); + QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); + auto contentList = contentPart->content(ContentPart::PlainText); + QCOMPARE(contentList.size(), 1); + QCOMPARE(contentList[0]->content(), QStringLiteral("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\n- GOG.com Team\n\n").toLocal8Bit()); + QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + QCOMPARE(contentList[0]->encryptions().size(), 0); + QCOMPARE(contentList[0]->signatures().size(), 0); + } + + void testTextAlternative() + { + Parser parser(readMailFromFile("alternative.mbox")); + auto contentPart = parser.collectContentPart(); + QVERIFY((bool)contentPart); + QCOMPARE(contentPart->availableContents(), ContentPart::PlainText | ContentPart::Html); + } + + void testTextHtml() + { + Parser parser(readMailFromFile("html.mbox")); + auto contentPart = parser.collectContentPart(); + QVERIFY((bool)contentPart); + QCOMPARE(contentPart->availableContents(), ContentPart::Html); } }; -- cgit v1.2.3 From 550aa371cbf39d7d0cb735f890b338a3ac6883ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Wed, 20 Jul 2016 10:04:49 +0200 Subject: add encrypted tests --- .../domain/mimetreeparser/tests/interfacetest.cpp | 77 +++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index fd828960..88691539 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -18,6 +18,7 @@ */ #include "interface.h" +#include "interface_p.h" #include @@ -33,6 +34,15 @@ QByteArray readMailFromFile(const QString &mailFile) class InterfaceTest : public QObject { Q_OBJECT +private: + void printTree(const Part::Ptr &start, QString pre) + { + foreach (const auto &part, start->subParts()) { + qWarning() << QStringLiteral("%1* %2").arg(pre).arg(QString::fromLatin1(part->type())); + printTree(part,pre + QStringLiteral(" ")); + } + } + private slots: void testTextMail() @@ -43,10 +53,13 @@ private slots: QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); auto contentList = contentPart->content(ContentPart::PlainText); QCOMPARE(contentList.size(), 1); - QCOMPARE(contentList[0]->content(), QStringLiteral("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\n- GOG.com Team\n\n").toLocal8Bit()); + QCOMPARE(contentList[0]->content(), QStringLiteral("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/").toLocal8Bit()); QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); QCOMPARE(contentList[0]->encryptions().size(), 0); QCOMPARE(contentList[0]->signatures().size(), 0); + + contentList = contentPart->content(ContentPart::Html); + QCOMPARE(contentList.size(), 0); } void testTextAlternative() @@ -55,6 +68,19 @@ private slots: auto contentPart = parser.collectContentPart(); QVERIFY((bool)contentPart); QCOMPARE(contentPart->availableContents(), ContentPart::PlainText | ContentPart::Html); + auto contentList = contentPart->content(ContentPart::PlainText); + QCOMPARE(contentList.size(), 1); + QCOMPARE(contentList[0]->content(), QStringLiteral("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").toLocal8Bit()); + QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + QCOMPARE(contentList[0]->encryptions().size(), 0); + QCOMPARE(contentList[0]->signatures().size(), 0); + + contentList = contentPart->content(ContentPart::Html); + QCOMPARE(contentList.size(), 1); + QCOMPARE(contentList[0]->content(), QStringLiteral("

HTML text

\n\n").toLocal8Bit()); + QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + QCOMPARE(contentList[0]->encryptions().size(), 0); + QCOMPARE(contentList[0]->signatures().size(), 0); } void testTextHtml() @@ -63,6 +89,55 @@ private slots: auto contentPart = parser.collectContentPart(); QVERIFY((bool)contentPart); QCOMPARE(contentPart->availableContents(), ContentPart::Html); + + auto contentList = contentPart->content(ContentPart::PlainText); + QCOMPARE(contentList.size(), 0); + + contentList = contentPart->content(ContentPart::Html); + QCOMPARE(contentList.size(), 1); + QCOMPARE(contentList[0]->content(), QStringLiteral("

HTML text

").toLocal8Bit()); + QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + QCOMPARE(contentList[0]->encryptions().size(), 0); + QCOMPARE(contentList[0]->signatures().size(), 0); + } + + void testSMimeEncrypted() + { + Parser parser(readMailFromFile("smime-encrypted.mbox")); + printTree(parser.d->mTree,QString()); + auto contentPart = parser.collectContentPart(); + QVERIFY((bool)contentPart); + QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); + auto contentList = contentPart->content(ContentPart::PlainText); + QCOMPARE(contentList.size(), 1); + QCOMPARE(contentList[0]->content(), QStringLiteral("The quick brown fox jumped over the lazy dog.").toLocal8Bit()); + QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + } + + void testOpenPGPEncryptedAttachment() + { + Parser parser(readMailFromFile("openpgp-encrypted-attachment-and-non-encrypted-attachment.mbox")); + printTree(parser.d->mTree,QString()); + auto contentPart = parser.collectContentPart(); + QVERIFY((bool)contentPart); + QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); + auto contentList = contentPart->content(ContentPart::PlainText); + QCOMPARE(contentList.size(), 1); + QCOMPARE(contentList[0]->content(), QStringLiteral("test text").toLocal8Bit()); + QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + } + + void testOpenPPGInline() + { + Parser parser(readMailFromFile("openpgp-inline-charset-encrypted.mbox")); + printTree(parser.d->mTree,QString()); + auto contentPart = parser.collectContentPart(); + QVERIFY((bool)contentPart); + QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); + auto contentList = contentPart->content(ContentPart::PlainText); + QCOMPARE(contentList.size(), 1); + QCOMPARE(contentList[0]->content(), QStringLiteral("asdasd asd asd asdf sadf sdaf sadf äöü").toLocal8Bit()); + QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); } }; -- cgit v1.2.3 From 903960116eb3329631702723bba11f5463eff573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Fri, 22 Jul 2016 13:23:17 +0200 Subject: fixes the build issues --- .../domain/mimetreeparser/tests/interfacetest.cpp | 54 +++++++++++++--------- 1 file changed, 33 insertions(+), 21 deletions(-) (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index 88691539..822d530c 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -48,34 +48,38 @@ private slots: void testTextMail() { Parser parser(readMailFromFile("plaintext.mbox")); - auto contentPart = parser.collectContentPart(); + auto contentPartList = parser.collectContentParts(); + QCOMPARE(contentPartList.size(), 1); + auto contentPart = contentPartList[0]; QVERIFY((bool)contentPart); - QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); - auto contentList = contentPart->content(ContentPart::PlainText); + QCOMPARE(contentPart->availableContents(), "plaintext"); + auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("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/").toLocal8Bit()); QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); QCOMPARE(contentList[0]->encryptions().size(), 0); QCOMPARE(contentList[0]->signatures().size(), 0); - contentList = contentPart->content(ContentPart::Html); + contentList = contentPart->content("html"); QCOMPARE(contentList.size(), 0); } void testTextAlternative() { Parser parser(readMailFromFile("alternative.mbox")); - auto contentPart = parser.collectContentPart(); + auto contentPartList = parser.collectContentParts(); + QCOMPARE(contentPartList.size(), 1); + auto contentPart = contentPartList[0]; QVERIFY((bool)contentPart); - QCOMPARE(contentPart->availableContents(), ContentPart::PlainText | ContentPart::Html); - auto contentList = contentPart->content(ContentPart::PlainText); + QCOMPARE(contentPart->availableContents(), QVector() << "html" << "plaintext"); + auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("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").toLocal8Bit()); QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); QCOMPARE(contentList[0]->encryptions().size(), 0); QCOMPARE(contentList[0]->signatures().size(), 0); - contentList = contentPart->content(ContentPart::Html); + contentList = contentPart->content("html"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("

HTML text

\n\n").toLocal8Bit()); QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); @@ -86,14 +90,16 @@ private slots: void testTextHtml() { Parser parser(readMailFromFile("html.mbox")); - auto contentPart = parser.collectContentPart(); + auto contentPartList = parser.collectContentParts(); + QCOMPARE(contentPartList.size(), 1); + auto contentPart = contentPartList[0]; QVERIFY((bool)contentPart); - QCOMPARE(contentPart->availableContents(), ContentPart::Html); + QCOMPARE(contentPart->availableContents(), "html"); - auto contentList = contentPart->content(ContentPart::PlainText); + auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 0); - contentList = contentPart->content(ContentPart::Html); + contentList = contentPart->content("html"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("

HTML text

").toLocal8Bit()); QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); @@ -105,10 +111,12 @@ private slots: { Parser parser(readMailFromFile("smime-encrypted.mbox")); printTree(parser.d->mTree,QString()); - auto contentPart = parser.collectContentPart(); + auto contentPartList = parser.collectContentParts(); + QCOMPARE(contentPartList.size(), 1); + auto contentPart = contentPartList[0]; QVERIFY((bool)contentPart); - QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); - auto contentList = contentPart->content(ContentPart::PlainText); + QCOMPARE(contentPart->availableContents(), "plaintext"); + auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("The quick brown fox jumped over the lazy dog.").toLocal8Bit()); QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); @@ -118,10 +126,12 @@ private slots: { Parser parser(readMailFromFile("openpgp-encrypted-attachment-and-non-encrypted-attachment.mbox")); printTree(parser.d->mTree,QString()); - auto contentPart = parser.collectContentPart(); + auto contentPartList = parser.collectContentParts(); + QCOMPARE(contentPartList.size(), 1); + auto contentPart = contentPartList[0]; QVERIFY((bool)contentPart); - QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); - auto contentList = contentPart->content(ContentPart::PlainText); + QCOMPARE(contentPart->availableContents(), "plaintext"); + auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("test text").toLocal8Bit()); QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); @@ -131,10 +141,12 @@ private slots: { Parser parser(readMailFromFile("openpgp-inline-charset-encrypted.mbox")); printTree(parser.d->mTree,QString()); - auto contentPart = parser.collectContentPart(); + auto contentPartList = parser.collectContentParts(); + QCOMPARE(contentPartList.size(), 1); + auto contentPart = contentPartList[0]; QVERIFY((bool)contentPart); - QCOMPARE(contentPart->availableContents(), ContentPart::PlainText); - auto contentList = contentPart->content(ContentPart::PlainText); + QCOMPARE(contentPart->availableContents(), "plaintext"); + auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("asdasd asd asd asdf sadf sdaf sadf äöü").toLocal8Bit()); QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); -- cgit v1.2.3 From 0272f1e8bb7f8c86c86958e3e022aac8b34a266c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Tue, 26 Jul 2016 13:52:06 +0200 Subject: make the tests compile again --- framework/domain/mimetreeparser/tests/interfacetest.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index 822d530c..83de97f7 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -52,7 +52,7 @@ private slots: QCOMPARE(contentPartList.size(), 1); auto contentPart = contentPartList[0]; QVERIFY((bool)contentPart); - QCOMPARE(contentPart->availableContents(), "plaintext"); + QCOMPARE(contentPart->availableContents(), QVector() << "plaintext"); auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("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/").toLocal8Bit()); @@ -94,7 +94,7 @@ private slots: QCOMPARE(contentPartList.size(), 1); auto contentPart = contentPartList[0]; QVERIFY((bool)contentPart); - QCOMPARE(contentPart->availableContents(), "html"); + QCOMPARE(contentPart->availableContents(), QVector() << "html"); auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 0); @@ -115,7 +115,7 @@ private slots: QCOMPARE(contentPartList.size(), 1); auto contentPart = contentPartList[0]; QVERIFY((bool)contentPart); - QCOMPARE(contentPart->availableContents(), "plaintext"); + QCOMPARE(contentPart->availableContents(), QVector() << "plaintext"); auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("The quick brown fox jumped over the lazy dog.").toLocal8Bit()); @@ -130,7 +130,7 @@ private slots: QCOMPARE(contentPartList.size(), 1); auto contentPart = contentPartList[0]; QVERIFY((bool)contentPart); - QCOMPARE(contentPart->availableContents(), "plaintext"); + QCOMPARE(contentPart->availableContents(), QVector() << "plaintext"); auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("test text").toLocal8Bit()); @@ -145,7 +145,7 @@ private slots: QCOMPARE(contentPartList.size(), 1); auto contentPart = contentPartList[0]; QVERIFY((bool)contentPart); - QCOMPARE(contentPart->availableContents(), "plaintext"); + QCOMPARE(contentPart->availableContents(), QVector() << "plaintext"); auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("asdasd asd asd asdf sadf sdaf sadf äöü").toLocal8Bit()); -- cgit v1.2.3 From c64288bfe549ccc95eb6b887f3b803b397ae412c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Tue, 2 Aug 2016 09:33:02 +0200 Subject: Make encrypted tests pass automatically --- .../domain/mimetreeparser/tests/interfacetest.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index 83de97f7..615d5742 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -30,6 +30,19 @@ QByteArray readMailFromFile(const QString &mailFile) return file.readAll(); } +QByteArray join(QVector vec, QByteArray sep) +{ + QByteArray ret; + bool bInit = true; + foreach(const auto &entry, vec) { + if (!bInit) { + ret += sep; + } + bInit = false; + ret += entry; + } + return ret; +} class InterfaceTest : public QObject { @@ -38,7 +51,10 @@ private: void printTree(const Part::Ptr &start, QString pre) { foreach (const auto &part, start->subParts()) { - qWarning() << QStringLiteral("%1* %2").arg(pre).arg(QString::fromLatin1(part->type())); + qWarning() << QStringLiteral("%1* %2(%3)") + .arg(pre) + .arg(QString::fromLatin1(part->type())) + .arg(QString::fromLatin1(join(part->availableContents(),", "))); printTree(part,pre + QStringLiteral(" ")); } } @@ -48,6 +64,7 @@ private slots: void testTextMail() { Parser parser(readMailFromFile("plaintext.mbox")); + printTree(parser.d->mTree,QString()); auto contentPartList = parser.collectContentParts(); QCOMPARE(contentPartList.size(), 1); auto contentPart = contentPartList[0]; @@ -67,6 +84,7 @@ private slots: void testTextAlternative() { Parser parser(readMailFromFile("alternative.mbox")); + printTree(parser.d->mTree,QString()); auto contentPartList = parser.collectContentParts(); QCOMPARE(contentPartList.size(), 1); auto contentPart = contentPartList[0]; @@ -90,6 +108,7 @@ private slots: void testTextHtml() { Parser parser(readMailFromFile("html.mbox")); + printTree(parser.d->mTree,QString()); auto contentPartList = parser.collectContentParts(); QCOMPARE(contentPartList.size(), 1); auto contentPart = contentPartList[0]; -- cgit v1.2.3 From 2d0608ddf1b84991ca7a693ce00e70b6447644d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Tue, 2 Aug 2016 10:11:23 +0200 Subject: Implement collectAttachmentParts --- framework/domain/mimetreeparser/tests/interfacetest.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index 615d5742..fb073fc1 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -79,6 +79,8 @@ private slots: contentList = contentPart->content("html"); QCOMPARE(contentList.size(), 0); + auto contentAttachmentList = parser.collectAttachmentParts(); + QCOMPARE(contentAttachmentList.size(), 0); } void testTextAlternative() @@ -103,6 +105,8 @@ private slots: QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); QCOMPARE(contentList[0]->encryptions().size(), 0); QCOMPARE(contentList[0]->signatures().size(), 0); + auto contentAttachmentList = parser.collectAttachmentParts(); + QCOMPARE(contentAttachmentList.size(), 0); } void testTextHtml() @@ -124,6 +128,8 @@ private slots: QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); QCOMPARE(contentList[0]->encryptions().size(), 0); QCOMPARE(contentList[0]->signatures().size(), 0); + auto contentAttachmentList = parser.collectAttachmentParts(); + QCOMPARE(contentAttachmentList.size(), 0); } void testSMimeEncrypted() @@ -139,6 +145,8 @@ private slots: QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("The quick brown fox jumped over the lazy dog.").toLocal8Bit()); QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + auto contentAttachmentList = parser.collectAttachmentParts(); + QCOMPARE(contentAttachmentList.size(), 0); } void testOpenPGPEncryptedAttachment() @@ -154,6 +162,12 @@ private slots: QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("test text").toLocal8Bit()); QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + auto contentAttachmentList = parser.collectAttachmentParts(); + QCOMPARE(contentAttachmentList.size(), 2); + QCOMPARE(contentAttachmentList[0]->availableContents(), QVector() << "text/plain"); + QCOMPARE(contentAttachmentList[0]->content().size(), 1); + QCOMPARE(contentAttachmentList[1]->availableContents(), QVector() << "image/png"); + QCOMPARE(contentAttachmentList[1]->content().size(), 1); } void testOpenPPGInline() @@ -169,6 +183,8 @@ private slots: QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("asdasd asd asd asdf sadf sdaf sadf äöü").toLocal8Bit()); QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + auto contentAttachmentList = parser.collectAttachmentParts(); + QCOMPARE(contentAttachmentList.size(), 0); } }; -- cgit v1.2.3 From 92d6fbd8f6a504da869454ca85f861e30c89a73c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Tue, 2 Aug 2016 18:14:00 +0200 Subject: make signs & encrytiopn work --- framework/domain/mimetreeparser/tests/interfacetest.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index fb073fc1..ac77b025 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -145,6 +145,8 @@ private slots: QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("The quick brown fox jumped over the lazy dog.").toLocal8Bit()); QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + QCOMPARE(contentList[0]->encryptions().size(), 1); + QCOMPARE(contentList[0]->signatures().size(), 0); auto contentAttachmentList = parser.collectAttachmentParts(); QCOMPARE(contentAttachmentList.size(), 0); } @@ -162,12 +164,18 @@ private slots: QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("test text").toLocal8Bit()); QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + QCOMPARE(contentList[0]->encryptions().size(), 1); + QCOMPARE(contentList[0]->signatures().size(), 1); auto contentAttachmentList = parser.collectAttachmentParts(); QCOMPARE(contentAttachmentList.size(), 2); QCOMPARE(contentAttachmentList[0]->availableContents(), QVector() << "text/plain"); QCOMPARE(contentAttachmentList[0]->content().size(), 1); + QCOMPARE(contentAttachmentList[0]->encryptions().size(), 1); + QCOMPARE(contentAttachmentList[0]->signatures().size(), 1); QCOMPARE(contentAttachmentList[1]->availableContents(), QVector() << "image/png"); QCOMPARE(contentAttachmentList[1]->content().size(), 1); + QCOMPARE(contentAttachmentList[1]->encryptions().size(), 0); + QCOMPARE(contentAttachmentList[1]->signatures().size(), 0); } void testOpenPPGInline() @@ -179,10 +187,14 @@ private slots: auto contentPart = contentPartList[0]; QVERIFY((bool)contentPart); QCOMPARE(contentPart->availableContents(), QVector() << "plaintext"); + QCOMPARE(contentPart->encryptions().size(), 0); + QCOMPARE(contentPart->signatures().size(), 0); auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("asdasd asd asd asdf sadf sdaf sadf äöü").toLocal8Bit()); QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + QCOMPARE(contentList[0]->encryptions().size(), 1); + QCOMPARE(contentList[0]->signatures().size(), 1); auto contentAttachmentList = parser.collectAttachmentParts(); QCOMPARE(contentAttachmentList.size(), 0); } -- cgit v1.2.3 From 1974c19eadd497e355ac985a00d0571f3e6c7712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Tue, 11 Oct 2016 16:18:50 +0200 Subject: create model for new mailviewer --- .../domain/mimetreeparser/tests/interfacetest.cpp | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index ac77b025..5a3cbb87 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -198,7 +198,32 @@ private slots: auto contentAttachmentList = parser.collectAttachmentParts(); QCOMPARE(contentAttachmentList.size(), 0); } + + void testOpenPPGInlineWithNonEncText() + { + Parser parser(readMailFromFile("openpgp-inline-encrypted+nonenc.mbox")); + printTree(parser.d->mTree,QString()); + auto contentPartList = parser.collectContentParts(); + QCOMPARE(contentPartList.size(), 1); + auto contentPart = contentPartList[0]; + QVERIFY((bool)contentPart); + QCOMPARE(contentPart->availableContents(), QVector() << "plaintext"); + QCOMPARE(contentPart->encryptions().size(), 0); + QCOMPARE(contentPart->signatures().size(), 0); + auto contentList = contentPart->content("plaintext"); + QCOMPARE(contentList.size(), 2); + QCOMPARE(contentList[0]->content(), QStringLiteral("Not encrypted not signed :(\n\n").toLocal8Bit()); + QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + QCOMPARE(contentList[0]->encryptions().size(), 0); + QCOMPARE(contentList[0]->signatures().size(), 0); + QCOMPARE(contentList[1]->content(), QStringLiteral("some random text").toLocal8Bit()); + QCOMPARE(contentList[1]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + QCOMPARE(contentList[1]->encryptions().size(), 1); + QCOMPARE(contentList[1]->signatures().size(), 0); + auto contentAttachmentList = parser.collectAttachmentParts(); + QCOMPARE(contentAttachmentList.size(), 0); + } }; QTEST_GUILESS_MAIN(InterfaceTest) -#include "interfacetest.moc" \ No newline at end of file +#include "interfacetest.moc" -- cgit v1.2.3 From b40e6c476e54c5dab834c4d01936d1f7bc33c60e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Wed, 12 Oct 2016 16:41:00 +0200 Subject: Make nested mails work with mailviewer --- framework/domain/mimetreeparser/tests/interfacetest.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index 5a3cbb87..fa372a60 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -223,6 +223,21 @@ private slots: auto contentAttachmentList = parser.collectAttachmentParts(); QCOMPARE(contentAttachmentList.size(), 0); } + + void testRelatedAlternative() + { + Parser parser(readMailFromFile("cid-links.mbox")); + printTree(parser.d->mTree,QString()); + auto contentPartList = parser.collectContentParts(); + QCOMPARE(contentPartList.size(), 1); + auto contentPart = contentPartList[0]; + QVERIFY((bool)contentPart); + QCOMPARE(contentPart->availableContents(), QVector() << "html" << "plaintext"); + QCOMPARE(contentPart->encryptions().size(), 0); + QCOMPARE(contentPart->signatures().size(), 0); + auto contentList = contentPart->content("plaintext"); + QCOMPARE(contentList.size(), 1); + } }; QTEST_GUILESS_MAIN(InterfaceTest) -- cgit v1.2.3 From 988f0fe074faef56c053742fb582d0bb7b980d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Mon, 17 Oct 2016 12:24:32 +0200 Subject: do not include multipart/related in attachmentlist --- framework/domain/mimetreeparser/tests/interfacetest.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index fa372a60..923a7446 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -237,6 +237,8 @@ private slots: QCOMPARE(contentPart->signatures().size(), 0); auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 1); + auto contentAttachmentList = parser.collectAttachmentParts(); + QCOMPARE(contentAttachmentList.size(), 0); } }; -- cgit v1.2.3 From b7a02699eefd84c68ff602bfea91640faec5c4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Mon, 17 Oct 2016 13:05:43 +0200 Subject: find part by cid --- framework/domain/mimetreeparser/tests/interfacetest.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index 923a7446..d52606c2 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -240,6 +240,15 @@ private slots: auto contentAttachmentList = parser.collectAttachmentParts(); QCOMPARE(contentAttachmentList.size(), 0); } + + void testCidLink() + { + Parser parser(readMailFromFile("cid-links.mbox")); + printTree(parser.d->mTree,QString()); + QCOMPARE(parser.getPart(QUrl("cid:9359201d15e53f31a68c307b3369b6@info")), parser.d->mTree->subParts().at(1)); + QVERIFY(!parser.getPart(QUrl("cid:"))); + QVERIFY(!parser.getPart(QUrl("cid:unknown"))); + } }; QTEST_GUILESS_MAIN(InterfaceTest) -- cgit v1.2.3 From 5cb20dd3886ee229d74068c75250691c840e89a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Mon, 17 Oct 2016 16:33:03 +0200 Subject: Read correct charset out of mailpart --- framework/domain/mimetreeparser/tests/interfacetest.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index d52606c2..0259471e 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -144,7 +144,7 @@ private slots: auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("The quick brown fox jumped over the lazy dog.").toLocal8Bit()); - QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + QCOMPARE(contentList[0]->charset(), QStringLiteral("us-ascii").toLocal8Bit()); QCOMPARE(contentList[0]->encryptions().size(), 1); QCOMPARE(contentList[0]->signatures().size(), 0); auto contentAttachmentList = parser.collectAttachmentParts(); @@ -163,7 +163,7 @@ private slots: auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("test text").toLocal8Bit()); - QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + QCOMPARE(contentList[0]->charset(), QStringLiteral("us-ascii").toLocal8Bit()); QCOMPARE(contentList[0]->encryptions().size(), 1); QCOMPARE(contentList[0]->signatures().size(), 1); auto contentAttachmentList = parser.collectAttachmentParts(); @@ -178,7 +178,7 @@ private slots: QCOMPARE(contentAttachmentList[1]->signatures().size(), 0); } - void testOpenPPGInline() + void testOpenPGPInline() { Parser parser(readMailFromFile("openpgp-inline-charset-encrypted.mbox")); printTree(parser.d->mTree,QString()); @@ -192,7 +192,7 @@ private slots: auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 1); QCOMPARE(contentList[0]->content(), QStringLiteral("asdasd asd asd asdf sadf sdaf sadf äöü").toLocal8Bit()); - QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + QCOMPARE(contentList[0]->charset(), QStringLiteral("ISO-8859-15").toLocal8Bit()); QCOMPARE(contentList[0]->encryptions().size(), 1); QCOMPARE(contentList[0]->signatures().size(), 1); auto contentAttachmentList = parser.collectAttachmentParts(); @@ -213,11 +213,11 @@ private slots: auto contentList = contentPart->content("plaintext"); QCOMPARE(contentList.size(), 2); QCOMPARE(contentList[0]->content(), QStringLiteral("Not encrypted not signed :(\n\n").toLocal8Bit()); - QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + QCOMPARE(contentList[0]->charset(), QStringLiteral("us-ascii").toLocal8Bit()); QCOMPARE(contentList[0]->encryptions().size(), 0); QCOMPARE(contentList[0]->signatures().size(), 0); QCOMPARE(contentList[1]->content(), QStringLiteral("some random text").toLocal8Bit()); - QCOMPARE(contentList[1]->charset(), QStringLiteral("utf-8").toLocal8Bit()); + QCOMPARE(contentList[1]->charset(), QStringLiteral("us-ascii").toLocal8Bit()); QCOMPARE(contentList[1]->encryptions().size(), 1); QCOMPARE(contentList[1]->signatures().size(), 0); auto contentAttachmentList = parser.collectAttachmentParts(); -- cgit v1.2.3 From c6bca32d393e7bd32574c88ea574be78cec01bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Mon, 17 Oct 2016 16:33:52 +0200 Subject: add a test for a attachment --- framework/domain/mimetreeparser/tests/interfacetest.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index 0259471e..ab6316ac 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -241,6 +241,17 @@ private slots: QCOMPARE(contentAttachmentList.size(), 0); } + void testAttachmentPart() + { + Parser parser(readMailFromFile("cid-links.mbox")); + const auto relatedImage = parser.d->mTree->subParts().at(1); + QCOMPARE(relatedImage->availableContents(), QVector() << "image/jpeg"); + auto contentList = relatedImage->content(); + QCOMPARE(contentList.size(), 1); + contentList = relatedImage->content("image/jpeg"); + QCOMPARE(contentList.size(), 1); + } + void testCidLink() { Parser parser(readMailFromFile("cid-links.mbox")); -- cgit v1.2.3 From d15a02d3c26c24530e8d9360629212e419c81c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Mon, 17 Oct 2016 19:06:12 +0200 Subject: fill Encryption and Signatures with content --- .../domain/mimetreeparser/tests/interfacetest.cpp | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'framework/domain/mimetreeparser/tests/interfacetest.cpp') diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index ab6316ac..3ae32a4a 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp @@ -224,6 +224,50 @@ private slots: QCOMPARE(contentAttachmentList.size(), 0); } + void testEncryptionBlock() + { + Parser parser(readMailFromFile("openpgp-encrypted-attachment-and-non-encrypted-attachment.mbox")); + auto contentPartList = parser.collectContentParts(); + auto contentPart = contentPartList[0]; + auto contentList = contentPart->content("plaintext"); + QCOMPARE(contentList.size(), 1); + QCOMPARE(contentList[0]->encryptions().size(), 1); + auto enc = contentList[0]->encryptions()[0]; + QCOMPARE((int) enc->recipients().size(), 2); + + auto r = enc->recipients()[0]; + QCOMPARE(r->keyid(),QStringLiteral("14B79E26050467AA")); + QCOMPARE(r->name(),QStringLiteral("kdetest")); + QCOMPARE(r->email(),QStringLiteral("you@you.com")); + QCOMPARE(r->comment(),QStringLiteral("")); + + r = enc->recipients()[1]; + QCOMPARE(r->keyid(),QStringLiteral("8D9860C58F246DE6")); + QCOMPARE(r->name(),QStringLiteral("unittest key")); + QCOMPARE(r->email(),QStringLiteral("test@kolab.org")); + QCOMPARE(r->comment(),QStringLiteral("no password")); + } + + void testSignatureBlock() + { + Parser parser(readMailFromFile("openpgp-encrypted-attachment-and-non-encrypted-attachment.mbox")); + auto contentPartList = parser.collectContentParts(); + auto contentPart = contentPartList[0]; + auto contentList = contentPart->content("plaintext"); + QCOMPARE(contentList.size(), 1); + QCOMPARE(contentList[0]->signatures().size(), 1); + auto sig = contentList[0]->signatures()[0]; + QCOMPARE(sig->creationDateTime(), QDateTime(QDate(2015,05,01),QTime(15,12,47))); + QCOMPARE(sig->expirationDateTime(), QDateTime()); + QCOMPARE(sig->neverExpires(), true); + + auto key = sig->key(); + QCOMPARE(key->keyid(),QStringLiteral("8D9860C58F246DE6")); + QCOMPARE(key->name(),QStringLiteral("unittest key")); + QCOMPARE(key->email(),QStringLiteral("test@kolab.org")); + QCOMPARE(key->comment(),QStringLiteral("no password")); + } + void testRelatedAlternative() { Parser parser(readMailFromFile("cid-links.mbox")); -- cgit v1.2.3