From 331db8370d20c07e01a6d5e06f1c75a3f436f1cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 6 Apr 2024 16:43:01 +0200 Subject: [PATCH] fix bug tolowercase in base64 headers --- src/cpp/Attachment.cpp | 36 ++++++++++++++++++++++++------------ src/cpp/kazMisc.cpp | 6 +++--- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/cpp/Attachment.cpp b/src/cpp/Attachment.cpp index 42ae956..427eb4a 100644 --- a/src/cpp/Attachment.cpp +++ b/src/cpp/Attachment.cpp @@ -296,23 +296,35 @@ Attachment::Attachment (ifstream &mbox, const int &level, const streamoff beginI } // ================================================================================ +/*! lower case "var in string " VAR=val; ..." */ inline string cleanString (string line) { - static const regex findVarVal ("(\\s*[a-zA-Z_*-]+=)((\"(\\\\.|[^\\\\])*\")|[^; \t]*;?)"); + DEF_LOG ("Attachment::cleanString", "line: " << line.substr (0, 100) << "..."); + + static const regex findPart ("(((\"(\\\\.|[^\\\\])*\")|\\s|[^;\\\"])+;?)"); + static const regex findVarVal ("(\\s*[a-zA-Z_*-]+=)(.*;?)"); string result; - smatch m; - - while (regex_search (line, m, findVarVal)) { - result += m.prefix (); - string id (m[1]); - toLower (id); - result += id; - result += m[2]; - line = m.suffix (); + smatch m1, m2; + + while (regex_search (line, m1, findPart)) { + if (m1.prefix ().length ()) + result += m1.prefix (); // XXX when \" on multi-lines + string part (m1[1]); + LOG ("part: " << part); + if (regex_search (part, m2, findVarVal) && !m2.prefix ().length ()) { + string id (m2[1]); + LOG ("id: " << id); + toLower (id); + result += id; + result += m2[2]; + } else + result += part; + line = m1.suffix (); } if (!line.empty () && line[line.size() - 1] == '\r') line = line.substr (0, line.size () - 1); result += line; + LOG ("result: " << result); return result; } @@ -333,7 +345,7 @@ Attachment::readMime (ifstream &mbox, streamoff &curPos) { } else { LOG ("add line to var: " << line); env.find (lastVar)->second += cleanString (line); - LOG ("new val: <" << lastVar << " <=> " << env.find (lastVar)->second << ">"); + LOG ("new val(a): <" << lastVar << " <=> " << env.find (lastVar)->second << ">"); } continue; } @@ -346,7 +358,7 @@ Attachment::readMime (ifstream &mbox, streamoff &curPos) { if (line.length () >= colonPos && line [colonPos] == ' ') ++colonPos; string val (cleanString (line.length () >= colonPos ? line.substr (colonPos) : "")); - LOG ("new var: <" << lastVar << " <=> " << val << ">"); + LOG ("new var(b): <" << lastVar << " <=> " << val << ">"); env [lastVar] = val; } } diff --git a/src/cpp/kazMisc.cpp b/src/cpp/kazMisc.cpp index 1e09ba5..39baf42 100644 --- a/src/cpp/kazMisc.cpp +++ b/src/cpp/kazMisc.cpp @@ -128,7 +128,7 @@ kaz::toLower (string &content) { static locale loc; for (string::size_type i = 0; i < content.length (); ++i) content [i] = tolower (content[i], loc); - LOG ("content: " << content.substr (0, 100) << "..."); + LOG ("content: " << content.substr (0, 100) << "..."); } const string & @@ -199,8 +199,8 @@ kaz::quotedDecode (string &content) { LOG ("len: " << len); string::iterator p (content.begin ()), q (p); for ( ; - p < content.end (); - ++p, ++q) { + p < content.end (); + ++p, ++q) { if (*p != delim) { *q = *p; continue;