From 59c603e58e9aa4c169b0dcc6a58fe806b5fddbab Mon Sep 17 00:00:00 2001 From: Damien Caliste Date: Mon, 10 Sep 2018 09:23:39 +0200 Subject: Escape last space on a line According to Rule#3 of http://www.ietf.org/rfc/rfc2045.txt page 19 last space on a line should be escaped to ensure that any trailing spaces are preserved. Change-Id: I68c885e5fef0dc98585caa9b235c51da94aa944f Reviewed-by: Christopher Adams Reviewed-by: Pekka Vuorela Reviewed-by: Matthew Vogt --- src/libraries/qmfclient/qmailcodec.cpp | 4 ++++ tests/tst_qmailcodec/tst_qmailcodec.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/libraries/qmfclient/qmailcodec.cpp b/src/libraries/qmfclient/qmailcodec.cpp index 5d06c441..f34492a3 100644 --- a/src/libraries/qmfclient/qmailcodec.cpp +++ b/src/libraries/qmfclient/qmailcodec.cpp @@ -868,6 +868,10 @@ void QMailQuotedPrintableCodec::encodeChunk(QDataStream& out, const unsigned cha } bool escape = requiresEscape(input, _conformance, _encodeLineCharsRemaining); + // Escape last space on a line, + // see Rule#3 of http://www.ietf.org/rfc/rfc2045.txt page 19. + if (input == Space && it != end && (*it == CarriageReturn || *it == LineFeed)) + escape = true; int charsRequired = (escape ? 3 : 1); // If we can't fit this character on the line, insert a line break diff --git a/tests/tst_qmailcodec/tst_qmailcodec.cpp b/tests/tst_qmailcodec/tst_qmailcodec.cpp index 5212f9e7..1c79f9f2 100644 --- a/tests/tst_qmailcodec/tst_qmailcodec.cpp +++ b/tests/tst_qmailcodec/tst_qmailcodec.cpp @@ -355,6 +355,15 @@ void tst_QMailCodec::line_lengths_data() << QByteArray("The =20=\r\n quick=\r\n\t\t brow=\r\nn\t =20=\r\n \tfox") << QByteArray("The__=20=\r\n_quick=\r\n=09=09=\r\n__brown=\r\n=09__=20=\r\n__=09fox"); + QTest::newRow("middle line trailing spaces") + << 8 + << 8 + << " \nPlop" + << "UTF-8" + << QByteArray("ICAKUGxv\r\ncA==") + << QByteArray(" =20\r\nPlop") + << QByteArray("_=20\r\nPlop"); + // Restore normality QTest::newRow("restore default line length") << Base64MaxLineLength -- cgit v1.2.3