Commit 40b292a1 authored by Christian Schoenebeck's avatar Christian Schoenebeck Committed by Sandro Knauß
Browse files

Account for already inserted FWS

Application might have already inserted folding white space (FWS) into
header. Don't remove those already inserted FWSs, but account for them
accordingly by resetting line length count at those occurrences to fix
subsequent folding to happen if required and at expected position.

Note: we are assuming the already inserted LFs to be correct FWS
(i.e. LF SP), we don't care about broken ones.
parent 7fba7b8e
Pipeline #238521 passed with stage
in 7 minutes and 14 seconds
......@@ -106,6 +106,18 @@ void UtilTest::testFoldHeader()
// escaped backslashes, followed by escaped double quote within quoted string
QCOMPARE(KMime::foldHeader("To: \"Body\\\\\\\\\\\", Some\\\\\\\\\" <some@where>, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@bbbbb"),
QByteArray("To: \"Body\\\\\\\\\\\", Some\\\\\\\\\" <some@where>,\n aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@bbbbb"));
// don't remove already inserted folding
QCOMPARE(KMime::foldHeader("To: some@where,\n some@else"),
QByteArray("To: some@where,\n some@else"));
// honor already inserted folding: no additional folding required
QCOMPARE(KMime::foldHeader("To: some@where,\n some@else, fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo@baaaaar"),
QByteArray("To: some@where,\n some@else, fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo@baaaaar"));
// honor already inserted folding: fold at correct position
QCOMPARE(KMime::foldHeader("To: some@where,\n some@else, fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo@baaaaaar"),
QByteArray("To: some@where,\n some@else,\n fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo@baaaaaar"));
void UtilTest::testExtractHeader()
......@@ -295,6 +295,13 @@ QByteArray foldHeader(const QByteArray &header)
// account for already inserted FWS
// (NOTE: we are not caring about broken ones here)
if (hdr[pos] == '\n') {
recommended = eligible = 0;
start = pos + 1/* LF */;
// Any white space character position is eligible for folding, except of
// escape pair (i.e. BSP WSP must not be folded).
if (hdr[pos] == ' ' && !ctx.isEscapePair && hdr[pos - 1] != '\n') {
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment