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/interface.cpp | 13 ++++++++++++- framework/domain/mimetreeparser/tests/interfacetest.cpp | 12 ++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'framework') diff --git a/framework/domain/mimetreeparser/interface.cpp b/framework/domain/mimetreeparser/interface.cpp index b5e29e6b..ceb8caf3 100644 --- a/framework/domain/mimetreeparser/interface.cpp +++ b/framework/domain/mimetreeparser/interface.cpp @@ -64,6 +64,17 @@ QByteArray MailMime::cid() const return d->mNode->contentID()->identifier(); } +QByteArray MailMime::charset() const +{ + if(!d->mNode || !d->mNode->contentType(false)) { + return QByteArray(); + } + if (d->mNode->contentType(false)) { + return d->mNode->contentType(false)->charset(); + } + return d->mNode->defaultCharset(); +} + bool MailMime::isFirstTextPart() const { if (!d->mNode || !d->mNode->topLevel()) { @@ -559,7 +570,6 @@ void SinglePartPrivate::fillFrom(MimeTreeParser::TextMessagePart::Ptr part) auto d_ptr = new ContentPrivate; d_ptr->mContent = mp->text().toLocal8Bit(); d_ptr->mParent = q; - d_ptr->mCodec = "utf-8"; const auto enc = mp.dynamicCast(); auto sig = mp.dynamicCast(); if (enc) { @@ -574,6 +584,7 @@ void SinglePartPrivate::fillFrom(MimeTreeParser::TextMessagePart::Ptr part) } mContent.append(std::make_shared(d_ptr)); q->reachParentD()->createMailMime(part); + d_ptr->mCodec = q->mailMime()->charset(); } } 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