|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|