add MODE "none"

This commit is contained in:
2022-12-01 07:47:25 +01:00
parent b31762ea43
commit 51865cfce2
8 changed files with 117 additions and 70 deletions

View File

@ -64,8 +64,8 @@ const string Attachment::ALTERNATIVE ("alternative");
const string Attachment::KAZ_ATTACH_NAME (".---KazAttachment---.html");
const regex Attachment::nameCharsetRegEx (".*name\\*=(.*)");
const regex Attachment::nameRegEx (".*name=\\s*\"?(.*)\"?\\s*;?\\s*");
const regex Attachment::nameCharsetRegEx (".*name\\*=[ \t]*(.*)");
const regex Attachment::nameRegEx (".*name=[ \t]*((\"(\\\\.|[^\\\\\r])*\")|[^\r; ]*);?.*");
// boundary="----=_Part_796779_1154936629.1668080348646"
// boundary="------------040709000505010508040808"
// boundary="----------=_1668606031-941125-91"
@ -73,7 +73,7 @@ const regex Attachment::nameRegEx (".*name=\\s*\"?(.*)\"?\\s*;?\\s*");
// boundary="_000_PAVPR10MB6792713B313048E3A259B215B2079PAVPR10MB6792EURP_"
// boundary=--boundary_1351_64006126-2b0e-4a3b-98ac-4797d1634188
// boundary=--boundary_1352_7e294c9a-cfab-44a0-bfb3-7310380ac7cb;
const regex Attachment::boundaryRegEx (".*boundary=\"?([^\"; ]*)\"?;?.*");
const regex Attachment::boundaryRegEx (".*boundary=[ \t]*((\"(\\\\.|[^\\\\\r])*\")|[^\r; ]*);?.*");
const regex Attachment::cidDefRegEx (".*<([^>]*)>.*");
const regex Attachment::textRegEx (".*text/("+PLAIN+"|"+HTML+").*");
const regex Attachment::multiRegEx ("\\s*multipart/(mixed|"+RELATED+"|"+ALTERNATIVE+").*");
@ -184,12 +184,14 @@ const string
Attachment::getAttachName () const {
DEF_LOG ("Attachment::getAttachName", "");
string result = getProp (contentTypeToken, nameRegEx);
removeQuote (result);
if (result.length ()) {
LOG ("name=: " << result);
encodedWord (result);
return result;
}
result = getProp (contentTypeToken, nameCharsetRegEx);
removeQuote (result);
if (result.length ()) {
LOG ("name*=: " << result);
charsetValue (result);
@ -197,13 +199,15 @@ Attachment::getAttachName () const {
}
// XXX il faut composer s'il y a plusieurs ligne filename*x=
result = getProp (contentDispositionToken, nameRegEx);
removeQuote (result);
if (result.length ()) {
LOG ("filename=: " << result);
encodedWord (result);
return result;
}
// XXX il faut composer s'il y a plusieurs ligne filename*x*=
result = getProp (contentDispositionToken, nameRegEx);
result = getProp (contentDispositionToken, nameCharsetRegEx);
removeQuote (result);
if (result.length ()) {
LOG ("filename*=: " << result);
charsetValue (result);
@ -282,6 +286,13 @@ Attachment::Attachment (ifstream &mbox, const int &level, const streamoff beginI
}
// ================================================================================
inline string
cleanString (const string &line) {
if (!line.empty () && line[line.size() - 1] == '\r')
return line.substr (0, line.size () - 1);
return line;
}
void
Attachment::readMime (ifstream &mbox, streamoff &curPos) {
DEF_LOG ("Attachment::readMime", "curPos: " << curPos);
@ -290,7 +301,7 @@ Attachment::readMime (ifstream &mbox, streamoff &curPos) {
for (; getline (mbox, line); ) {
LOG ("pos: " << curPos << " line: " << line);
curPos += line.length () + 1;
if (line.empty ())
if (line.empty () || "\r" == line)
break;
if (line[0] == ' ' || line[0] == '\t') {
if (lastVar.empty ()) {
@ -298,8 +309,8 @@ Attachment::readMime (ifstream &mbox, streamoff &curPos) {
LOG_BUG (true, /**/, "eMailShrinker: bug A5: not compliant MIME. pos: " << (curPos - (line.length () + 1)) << " line: " << line);
} else {
LOG ("add line to var: " << line);
env.find (lastVar)->second += line;
LOG ("new val: " << env.find (lastVar)->second);
env.find (lastVar)->second += cleanString (line);
LOG ("new val: <" << lastVar << " <=> " << env.find (lastVar)->second << ">");
}
continue;
}
@ -308,8 +319,8 @@ Attachment::readMime (ifstream &mbox, streamoff &curPos) {
lastVar = line.substr (0, colonPos);
toLower (lastVar);
LOG ("find var: " << lastVar);
string val (line.length () >= colonPos+2 ? line.substr (colonPos+2) : ""); // XXX check RFC " " after ": "
LOG ("new var: " << lastVar << " <=> " << val);
string val (cleanString (line.length () >= colonPos+2 ? line.substr (colonPos+2) : "")); // XXX check RFC " " after ": "
LOG ("new var: <" << lastVar << " <=> " << val << ">");
env [lastVar] = val;
}
}
@ -318,6 +329,7 @@ Attachment::readMime (ifstream &mbox, streamoff &curPos) {
contentPos = curPos;
cid = getProp (contentIDToken, cidDefRegEx);
boundary = getProp (contentTypeToken, boundaryRegEx);
removeQuote (boundary);
LOG ("boundary: " << boundary);
if (boundary.length ()) {
boundary = "--"+boundary+"--";