summaryrefslogtreecommitdiffstats
path: root/framework/domain/mimetreeparser
diff options
context:
space:
mode:
Diffstat (limited to 'framework/domain/mimetreeparser')
-rw-r--r--framework/domain/mimetreeparser/CMakeLists.txt5
-rw-r--r--framework/domain/mimetreeparser/interface.cpp14
-rw-r--r--framework/domain/mimetreeparser/interface.h2
-rw-r--r--framework/domain/mimetreeparser/tests/data/openpgp-inline-encrypted+nonenc.mbox31
-rw-r--r--framework/domain/mimetreeparser/tests/interfacetest.cpp27
5 files changed, 75 insertions, 4 deletions
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})
9qt5_use_modules(mimetreeparser Core Gui) 9qt5_use_modules(mimetreeparser Core Gui)
10target_link_libraries(mimetreeparser KF5::Mime KF5::MimeTreeParser) 10target_link_libraries(mimetreeparser KF5::Mime KF5::MimeTreeParser)
11 11
12add_subdirectory(tests) \ No newline at end of file 12install(TARGETS mimetreeparser
13 DESTINATION ${LIB_INSTALL_DIR})
14
15add_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 @@
30 30
31#include <QMimeDatabase> 31#include <QMimeDatabase>
32#include <QMimeType> 32#include <QMimeType>
33#include <QTextCodec>
33#include <QDebug> 34#include <QDebug>
34 35
35class MailMimePrivate 36class MailMimePrivate
@@ -356,6 +357,17 @@ QByteArray Content::charset() const
356 return d->mCodec; 357 return d->mCodec;
357} 358}
358 359
360QString Content::encodedContent() const
361{
362 return encodedContent(charset());
363}
364
365QString Content::encodedContent(const QByteArray &charset) const
366{
367 QTextCodec *codec = QTextCodec::codecForName(charset);
368 return codec->toUnicode(content());
369}
370
359QByteArray Content::type() const 371QByteArray Content::type() const
360{ 372{
361 return "Content"; 373 return "Content";
@@ -496,7 +508,7 @@ void SinglePartPrivate::fillFrom(MimeTreeParser::TextMessagePart::Ptr part)
496 mContent.clear(); 508 mContent.clear();
497 foreach (const auto &mp, part->subParts()) { 509 foreach (const auto &mp, part->subParts()) {
498 auto d_ptr = new ContentPrivate; 510 auto d_ptr = new ContentPrivate;
499 d_ptr->mContent = part->text().toLocal8Bit(); 511 d_ptr->mContent = mp->text().toLocal8Bit();
500 d_ptr->mParent = q; 512 d_ptr->mParent = q;
501 d_ptr->mCodec = "utf-8"; 513 d_ptr->mCodec = "utf-8";
502 const auto enc = mp.dynamicCast<MimeTreeParser::EncryptedMessagePart>(); 514 const auto enc = mp.dynamicCast<MimeTreeParser::EncryptedMessagePart>();
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:
125 QString encodedContent() const; 125 QString encodedContent() const;
126 126
127 // overwrite default charset with given charset 127 // overwrite default charset with given charset
128 QString encodedContent(QByteArray charset) const; 128 QString encodedContent(const QByteArray &charset) const;
129 129
130 QVector<SignaturePtr> signatures() const; 130 QVector<SignaturePtr> signatures() const;
131 QVector<EncryptionPtr> encryptions() const; 131 QVector<EncryptionPtr> 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 @@
1From test@kolab.org Wed, 25 May 2011 23:49:40 +0100
2From: OpenPGP Test <test@kolab.org>
3To: test@kolab.org
4Subject: inlinepgpencrypted + non enc text
5Date: Wed, 25 May 2011 23:49:40 +0100
6Message-ID: <1786696.yKXrOjjflF@herrwackelpudding.localhost>
7X-KMail-Transport: GMX
8X-KMail-Fcc: 28
9X-KMail-Drafts: 7
10X-KMail-Templates: 9
11User-Agent: KMail/4.6 beta5 (Linux/2.6.34.7-0.7-desktop; KDE/4.6.41; x86_64; git-0269848; 2011-04-19)
12MIME-Version: 1.0
13Content-Transfer-Encoding: 7Bit
14Content-Type: text/plain; charset="us-ascii"
15
16Not encrypted not signed :(
17
18-----BEGIN PGP MESSAGE-----
19Version: GnuPG v2.0.15 (GNU/Linux)
20
21hQEMAwzOQ1qnzNo7AQf/a3aNTLpQBfcUr+4AKsZQLj4h6z7e7a5AaCW8AG0wrbxN
22kBYB7E5jdZh45DX/99gvoZslthWryUCX2kKZ3LtIllxKVjqNuK5hSt+SAuKkwiMR
23Xcbf1KFKENKupgGSO9B2NJRbjoExdJ+fC3mGXnO3dT7xJJAo3oLE8Nivu+Bj1peY
24E1wCf+vcTwVHFrA7SV8eMRb9Z9wBXmU8Q8e9ekJ7ZsRX3tMeBs6jvscVvfMf6DYY
25N14snZBZuGNKT9a3DPny7IC1S0lHcaam34ogWwMi3FxPGJt/Lg52kARlkF5TDhcP
26N6H0EB/iqDRjOOUoEVm8um5XOSR1FpEiAdD0DON3y9JPATnrYq7sgYZz3BVImYY+
27N/jV8fEiN0a34pcOq8NQedMuOsJHNBS5MtbQH/kJLq0MXBpXekGlHo4MKw0trISc
28Rw3pW6/BFfhPJLni29g9tw==
29=fRFW
30-----END PGP MESSAGE-----
31
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:
198 auto contentAttachmentList = parser.collectAttachmentParts(); 198 auto contentAttachmentList = parser.collectAttachmentParts();
199 QCOMPARE(contentAttachmentList.size(), 0); 199 QCOMPARE(contentAttachmentList.size(), 0);
200 } 200 }
201
202 void testOpenPPGInlineWithNonEncText()
203 {
204 Parser parser(readMailFromFile("openpgp-inline-encrypted+nonenc.mbox"));
205 printTree(parser.d->mTree,QString());
206 auto contentPartList = parser.collectContentParts();
207 QCOMPARE(contentPartList.size(), 1);
208 auto contentPart = contentPartList[0];
209 QVERIFY((bool)contentPart);
210 QCOMPARE(contentPart->availableContents(), QVector<QByteArray>() << "plaintext");
211 QCOMPARE(contentPart->encryptions().size(), 0);
212 QCOMPARE(contentPart->signatures().size(), 0);
213 auto contentList = contentPart->content("plaintext");
214 QCOMPARE(contentList.size(), 2);
215 QCOMPARE(contentList[0]->content(), QStringLiteral("Not encrypted not signed :(\n\n").toLocal8Bit());
216 QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit());
217 QCOMPARE(contentList[0]->encryptions().size(), 0);
218 QCOMPARE(contentList[0]->signatures().size(), 0);
219 QCOMPARE(contentList[1]->content(), QStringLiteral("some random text").toLocal8Bit());
220 QCOMPARE(contentList[1]->charset(), QStringLiteral("utf-8").toLocal8Bit());
221 QCOMPARE(contentList[1]->encryptions().size(), 1);
222 QCOMPARE(contentList[1]->signatures().size(), 0);
223 auto contentAttachmentList = parser.collectAttachmentParts();
224 QCOMPARE(contentAttachmentList.size(), 0);
225 }
201}; 226};
202 227
203QTEST_GUILESS_MAIN(InterfaceTest) 228QTEST_GUILESS_MAIN(InterfaceTest)
204#include "interfacetest.moc" \ No newline at end of file 229#include "interfacetest.moc"