summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libraries/qmfclient/qmailcodec.cpp40
-rw-r--r--tests/tst_qmailmessagebody/tst_qmailmessagebody.cpp11
2 files changed, 31 insertions, 20 deletions
diff --git a/src/libraries/qmfclient/qmailcodec.cpp b/src/libraries/qmfclient/qmailcodec.cpp
index f34492a3..d5f168ea 100644
--- a/src/libraries/qmfclient/qmailcodec.cpp
+++ b/src/libraries/qmfclient/qmailcodec.cpp
@@ -160,32 +160,32 @@ void QMailCodec::encode(QDataStream& out, QTextStream& in, const QString& charse
*/
void QMailCodec::decode(QTextStream& out, QDataStream& in, const QString& icharset)
{
- if (QTextCodec* codec = codecForName(icharset.toLatin1()))
+ QByteArray decoded;
{
- QByteArray decoded;
+ QDataStream decodedStream(&decoded, QIODevice::WriteOnly);
+
+ char* buffer = new char[MaxCharacters];
+ while (!in.atEnd())
{
- QDataStream decodedStream(&decoded, QIODevice::WriteOnly);
-
- char* buffer = new char[MaxCharacters];
- while (!in.atEnd())
- {
- int length = in.readRawData(buffer, MaxCharacters);
+ int length = in.readRawData(buffer, MaxCharacters);
- // Allow for decoded data to be twice the size without reallocation
- decoded.reserve(decoded.size() + (MaxCharacters * 2));
+ // Allow for decoded data to be twice the size without reallocation
+ decoded.reserve(decoded.size() + (MaxCharacters * 2));
- decodeChunk(decodedStream, buffer, length, in.atEnd());
- }
- delete [] buffer;
+ decodeChunk(decodedStream, buffer, length, in.atEnd());
}
-
- // This is an unfortunately-necessary copy operation; we should investigate
- // using QTextCodec::makeDecoder, and adding a factory method to
- // QMailMessagePartContainer that returns a readable QIODevice*
- QString unicode = codec->toUnicode(decoded);
- out << unicode;
- out.flush();
+ delete [] buffer;
}
+ QTextCodec* codec = codecForName(icharset.toLatin1());
+ if (!codec)
+ codec = QTextCodec::codecForUtfText(decoded, codecForName("UTF-8"));
+
+ // This is an unfortunately-necessary copy operation; we should investigate
+ // using QTextCodec::makeDecoder, and adding a factory method to
+ // QMailMessagePartContainer that returns a readable QIODevice*
+ QString unicode = codec->toUnicode(decoded);
+ out << unicode;
+ out.flush();
}
/*!
diff --git a/tests/tst_qmailmessagebody/tst_qmailmessagebody.cpp b/tests/tst_qmailmessagebody/tst_qmailmessagebody.cpp
index b2c6602e..1591e556 100644
--- a/tests/tst_qmailmessagebody/tst_qmailmessagebody.cpp
+++ b/tests/tst_qmailmessagebody/tst_qmailmessagebody.cpp
@@ -505,6 +505,17 @@ void tst_QMailMessageBody::fromFile_data()
<< QByteArray()
<< string_source
<< ( QStringList() << "text" << "plain" << "UTF-8" );
+
+ QTest::newRow("unknown charset")
+ << QString::fromLatin1(encode(string_source.toUtf8(), QMailMessageBody::Base64))
+ << QByteArray()
+ << QByteArray("text/plain; charset=this-is-not-a-valid-charset")
+ << QMailMessageBody::Base64
+ << QMailMessageBody::AlreadyEncoded
+ << encode(string_source.toUtf8(), QMailMessageBody::Base64)
+ << QByteArray()
+ << string_source
+ << ( QStringList() << "text" << "plain" << "this-is-not-a-valid-charset" );
}
void tst_QMailMessageBody::fromFile()