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 --- framework/domain/mimetreeparser/CMakeLists.txt | 5 +++- framework/domain/mimetreeparser/interface.cpp | 14 +++++++++- framework/domain/mimetreeparser/interface.h | 2 +- .../data/openpgp-inline-encrypted+nonenc.mbox | 31 ++++++++++++++++++++++ .../domain/mimetreeparser/tests/interfacetest.cpp | 27 ++++++++++++++++++- 5 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 framework/domain/mimetreeparser/tests/data/openpgp-inline-encrypted+nonenc.mbox (limited to 'framework/domain/mimetreeparser') diff --git a/framework/domain/mimetreeparser/CMakeLists.txt b/framework/domain/mimetreeparser/CMakeLists.txt index e1c04893..64da2656 100644 --- a/framework/domain/mimetreeparser/CMakeLists.txt +++ b/framework/domain/mimetreeparser/CMakeLists.txt @@ -9,4 +9,7 @@ add_library(mimetreeparser SHARED ${mimetreeparser_SRCS}) qt5_use_modules(mimetreeparser Core Gui) target_link_libraries(mimetreeparser KF5::Mime KF5::MimeTreeParser) -add_subdirectory(tests) \ No newline at end of file +install(TARGETS mimetreeparser + DESTINATION ${LIB_INSTALL_DIR}) + +add_subdirectory(tests) diff --git a/framework/domain/mimetreeparser/interface.cpp b/framework/domain/mimetreeparser/interface.cpp index c3ecf79c..efa0fd40 100644 --- a/framework/domain/mimetreeparser/interface.cpp +++ b/framework/domain/mimetreeparser/interface.cpp @@ -30,6 +30,7 @@ #include #include +#include #include class MailMimePrivate @@ -356,6 +357,17 @@ QByteArray Content::charset() const return d->mCodec; } +QString Content::encodedContent() const +{ + return encodedContent(charset()); +} + +QString Content::encodedContent(const QByteArray &charset) const +{ + QTextCodec *codec = QTextCodec::codecForName(charset); + return codec->toUnicode(content()); +} + QByteArray Content::type() const { return "Content"; @@ -496,7 +508,7 @@ void SinglePartPrivate::fillFrom(MimeTreeParser::TextMessagePart::Ptr part) mContent.clear(); foreach (const auto &mp, part->subParts()) { auto d_ptr = new ContentPrivate; - d_ptr->mContent = part->text().toLocal8Bit(); + d_ptr->mContent = mp->text().toLocal8Bit(); d_ptr->mParent = q; d_ptr->mCodec = "utf-8"; const auto enc = mp.dynamicCast(); diff --git a/framework/domain/mimetreeparser/interface.h b/framework/domain/mimetreeparser/interface.h index 7eadc311..67246f37 100644 --- a/framework/domain/mimetreeparser/interface.h +++ b/framework/domain/mimetreeparser/interface.h @@ -125,7 +125,7 @@ public: QString encodedContent() const; // overwrite default charset with given charset - QString encodedContent(QByteArray charset) const; + QString encodedContent(const QByteArray &charset) const; QVector signatures() const; QVector encryptions() const; diff --git a/framework/domain/mimetreeparser/tests/data/openpgp-inline-encrypted+nonenc.mbox b/framework/domain/mimetreeparser/tests/data/openpgp-inline-encrypted+nonenc.mbox new file mode 100644 index 00000000..b98dc336 --- /dev/null +++ b/framework/domain/mimetreeparser/tests/data/openpgp-inline-encrypted+nonenc.mbox @@ -0,0 +1,31 @@ +From test@kolab.org Wed, 25 May 2011 23:49:40 +0100 +From: OpenPGP Test +To: test@kolab.org +Subject: inlinepgpencrypted + non enc text +Date: Wed, 25 May 2011 23:49:40 +0100 +Message-ID: <1786696.yKXrOjjflF@herrwackelpudding.localhost> +X-KMail-Transport: GMX +X-KMail-Fcc: 28 +X-KMail-Drafts: 7 +X-KMail-Templates: 9 +User-Agent: KMail/4.6 beta5 (Linux/2.6.34.7-0.7-desktop; KDE/4.6.41; x86_64; git-0269848; 2011-04-19) +MIME-Version: 1.0 +Content-Transfer-Encoding: 7Bit +Content-Type: text/plain; charset="us-ascii" + +Not encrypted not signed :( + +-----BEGIN PGP MESSAGE----- +Version: GnuPG v2.0.15 (GNU/Linux) + +hQEMAwzOQ1qnzNo7AQf/a3aNTLpQBfcUr+4AKsZQLj4h6z7e7a5AaCW8AG0wrbxN +kBYB7E5jdZh45DX/99gvoZslthWryUCX2kKZ3LtIllxKVjqNuK5hSt+SAuKkwiMR +Xcbf1KFKENKupgGSO9B2NJRbjoExdJ+fC3mGXnO3dT7xJJAo3oLE8Nivu+Bj1peY +E1wCf+vcTwVHFrA7SV8eMRb9Z9wBXmU8Q8e9ekJ7ZsRX3tMeBs6jvscVvfMf6DYY +N14snZBZuGNKT9a3DPny7IC1S0lHcaam34ogWwMi3FxPGJt/Lg52kARlkF5TDhcP +N6H0EB/iqDRjOOUoEVm8um5XOSR1FpEiAdD0DON3y9JPATnrYq7sgYZz3BVImYY+ +N/jV8fEiN0a34pcOq8NQedMuOsJHNBS5MtbQH/kJLq0MXBpXekGlHo4MKw0trISc +Rw3pW6/BFfhPJLni29g9tw== +=fRFW +-----END PGP MESSAGE----- + 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