fix rfc2047 / filter log / filterTest options

This commit is contained in:
2022-12-25 06:57:44 +01:00
parent 596ae82fe4
commit 61bdc3a4ba
9 changed files with 193 additions and 101 deletions

View File

@ -61,7 +61,7 @@ static const string TMPL_FILENAME ("{{FILENAME}}");
static const string CID ("cid:");
// "l=/" => v1 compatibility
static const regex archiveURLSignature (".*(([&?]g=)|([&?]l=/)).*");
static const regex archiveURLRegex (".*(([&?]g=)|([&?]l=/)).*");
static const string KAZ_PLAIN_HR ("______________________________________________________________________________");
static const string KAZ_PLAIN_START ("~~ PJ-KAZ !"); // don't end whith space
@ -423,7 +423,7 @@ MainAttachment::removePreviousArchive () {
vector<string> toRemove;
for (map <string, string>::const_iterator it = previousLinks.begin (); it != previousLinks.end (); ++it) {
const string key (it->first);
if (regex_match (key, archiveURLSignature))
if (regex_match (key, archiveURLRegex))
toRemove.push_back (key);
}
for (string old : toRemove)
@ -567,7 +567,7 @@ MainAttachment::extract (ifstream &mbox, const SizeArg &minSize) const {
// ================================================================================
void
MainAttachment::substitute (ifstream &mbox, ofstream &outbox, const SizeArg &minSize, const AttachMode &attachMode) {
MainAttachment::substitute (ifstream &mbox, ofstream &outbox, const SizeArg &minSize, AttachMode attachMode) {
DEF_LOG ("MainAttachment::substitute", "minSize: " << minSize << " AttachMode: " << attachMode);
// preparation
@ -601,30 +601,34 @@ MainAttachment::substitute (ifstream &mbox, ofstream &outbox, const SizeArg &min
getDisclaim (plainDisclaim, htmlDisclaim);
// copy email
if (plainDisclaim.size () && emptyEMail && boundary.empty ()) {
// only one attachment must be replace
cerr << "eMailShrinker: force one attachment" << endl;
string mime (getMime (mbox));
string::size_type startPos = (0);
for (string token : {string ("Content-Transfer-Encoding"), Attachment::contentTypeToken}) {
startPos = caseInsensitiveFind (mime, "Content-Transfer-Encoding");
for (string::size_type stopPos (startPos);
(stopPos = mime.find ("\n", stopPos)) != string::npos;
) {
if (string (" \t").find (mime [stopPos+1]) == string::npos) {
mime.erase (startPos, stopPos-startPos);
break;
if (!boundary.size () && plainDisclaim.size ()) {
if (attachMode & ATTACHMENT)
attachMode = FOOTER;
if (emptyEMail) {
// only one attachment must be replace
cerr << "eMailShrinker: force one attachment" << endl;
string mime (getMime (mbox));
string::size_type startPos = (0);
for (string token : {string ("Content-Transfer-Encoding"), Attachment::contentTypeToken}) {
startPos = caseInsensitiveFind (mime, "Content-Transfer-Encoding");
for (string::size_type stopPos (startPos);
(stopPos = mime.find ("\n", stopPos)) != string::npos;
) {
if (string (" \t").find (mime [stopPos+1]) == string::npos) {
mime.erase (startPos, stopPos-startPos);
break;
}
}
}
mime.insert (startPos, KAZ_EMPTY_TEXT_PLAIN);
string content (plainDisclaim);
base64Encode (content);
outbox << mime
<< content << endl;
outbox.flush ();
outbox.close ();
return;
}
mime.insert (startPos, KAZ_EMPTY_TEXT_PLAIN);
string content (plainDisclaim);
base64Encode (content);
outbox << mime
<< content << endl;
outbox.flush ();
outbox.close ();
return;
}
streamoff curPos = 0;
copy (mbox, outbox, curPos, contentPos);
@ -694,8 +698,7 @@ MainAttachment::substitute (ifstream &mbox, ofstream &outbox, const SizeArg &min
}
removeSection (content, KAZ_HTML_START, KAZ_HTML_STOP);
removeSection (content, KAZ_PLAIN_START, KAZ_PLAIN_STOP);
// XXX case insensitive ??
if (content.find (CID) != string::npos)
if (caseInsensitiveFind (content, CID) != string::npos)
replaceAll (content, translateHtml);
attachP->replaceEmbedded (content);
}
@ -733,12 +736,9 @@ MainAttachment::substitute (ifstream &mbox, ofstream &outbox, const SizeArg &min
string content (KAZ_HTML_CONTENT+htmlDisclaim+BODY_END+HTML_END);
base64Encode (content);
if (boundary.size ())
outbox << boundary.substr (0, boundary.length () -2) << endl
<< KAZ_ATTACHMENT_TEXT_HTML << endl
<< content << endl;
else
outbox << "coucou No multipart" << endl;
outbox << boundary.substr (0, boundary.length () -2) << endl
<< KAZ_ATTACHMENT_TEXT_HTML << endl
<< content << endl;
outbox.flush ();
}
copy (mbox, outbox, curPos, endPos);