add MODE "none"
This commit is contained in:
@ -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+"--";
|
||||
|
@ -177,8 +177,8 @@ MainAttachment::readArchiveUrl () {
|
||||
archiveDownloadURL.clear ();
|
||||
string line;
|
||||
getline (cin, line);
|
||||
LOG_BUG (line.rfind ("arch: ", 0) != 0, return, "eMailShrinker: bug ZZ: no archive link. (line: " << line << ")");
|
||||
LOG_BUG (line.rfind ("arch: bad", 0) == 0, return, "eMailShrinker: bug ZZ: bad archive link. (line: " << line << ")");
|
||||
LOG_BUG (line.rfind ("arch: ", 0) != 0, return, "eMailShrinker: bug 9: no archive link. (line: " << line << ")");
|
||||
LOG_BUG (line.rfind ("arch: bad", 0) == 0, return, "eMailShrinker: bug 10: bad archive link. (line: " << line << ")");
|
||||
if (line.rfind ("arch: none", 0) == 0)
|
||||
return;
|
||||
archiveDownloadURL = line.substr (6);
|
||||
@ -192,7 +192,7 @@ MainAttachment::readDownloadUrl (string &url) {
|
||||
string line;
|
||||
getline (cin, line);
|
||||
LOG ("get URL: " << line);
|
||||
LOG_BUG (line.rfind ("url: ", 0) != 0, return, "eMailShrinker: bug ZZ: no download link. (line: " << line << ")");
|
||||
LOG_BUG (line.rfind ("url: ", 0) != 0, return, "eMailShrinker: bug 11: no download link. (line: " << line << ")");
|
||||
url = line.substr (5);
|
||||
}
|
||||
|
||||
@ -371,30 +371,39 @@ MainAttachment::extractLinks (const vector<string> &liOne) {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MainAttachment::extractPreviousKAZ (string &extractedPlainKAZ, string &extractedHtmlKAZ, ifstream &mbox, const Attachment &attach) {
|
||||
DEF_LOG ("MainAttachment::extractPreviousKAZ", "attach:" << attach);
|
||||
if (!(attach.toUpdate || attach.isKazAttachment)) // isKazAttachment => toUpdate
|
||||
return;
|
||||
string textProp = attach.getProp (contentTypeToken, textRegEx);
|
||||
if (textProp.empty ())
|
||||
return;
|
||||
string content (attach.getContent (mbox));
|
||||
if (textProp == PLAIN) {
|
||||
LOG (PLAIN);
|
||||
extractedPlainKAZ += attach.getSection (content, KAZ_PLAIN_START, KAZ_PLAIN_STOP);
|
||||
}
|
||||
if (textProp == HTML) {
|
||||
LOG (HTML);
|
||||
string section = attach.getSection (content, KAZ_HTML_START, KAZ_HTML_STOP);
|
||||
section += attach.getSection (content, KAZ_PLAIN_START, KAZ_PLAIN_STOP);
|
||||
// update href from HTML attachments
|
||||
replaceAll (section, "&", "&");
|
||||
extractedHtmlKAZ += section;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MainAttachment::extractPreviousKAZ (ifstream &mbox) {
|
||||
DEF_LOG ("MainAttachment::extractPreviousKAZ", "");
|
||||
string extractedPlainKAZ, extractedHtmlKAZ;
|
||||
for (const Attachment *attachP : allMarkedPtrs) {
|
||||
if (!(attachP->toUpdate || attachP->isKazAttachment)) // isKazAttachment => toUpdate
|
||||
continue;
|
||||
string textProp = attachP->getProp (contentTypeToken, textRegEx);
|
||||
if (textProp.empty ())
|
||||
continue;
|
||||
string content (attachP->getContent (mbox));
|
||||
if (textProp == PLAIN) {
|
||||
LOG (PLAIN);
|
||||
extractedPlainKAZ += attachP->getSection (content, KAZ_PLAIN_START, KAZ_PLAIN_STOP);
|
||||
}
|
||||
if (textProp == HTML) {
|
||||
LOG (HTML);
|
||||
string section = attachP->getSection (content, KAZ_HTML_START, KAZ_HTML_STOP);
|
||||
section += attachP->getSection (content, KAZ_PLAIN_START, KAZ_PLAIN_STOP);
|
||||
// update href from HTML attachments
|
||||
replaceAll (section, "&", "&");
|
||||
extractedHtmlKAZ += section;
|
||||
}
|
||||
}
|
||||
if (boundary.empty ())
|
||||
extractPreviousKAZ (extractedPlainKAZ, extractedHtmlKAZ, mbox, *this);
|
||||
else
|
||||
for (const Attachment *attachP : allMarkedPtrs)
|
||||
extractPreviousKAZ (extractedPlainKAZ, extractedHtmlKAZ, mbox, *attachP);
|
||||
|
||||
LOG ("extractedPlainKAZ: "<< extractedPlainKAZ);
|
||||
extractLinks (extractedPlainKAZ);
|
||||
|
||||
@ -590,8 +599,13 @@ MainAttachment::substitute (ifstream &mbox, ofstream &outbox, const SizeArg &min
|
||||
removePreviousArchive ();
|
||||
string plainDisclaim, htmlDisclaim;
|
||||
getDisclaim (plainDisclaim, htmlDisclaim);
|
||||
|
||||
// copy email
|
||||
streamoff curPos = 0;
|
||||
if (boundary.empty () && plainDisclaim.size () && (attachMode & ATTACHMENT)) {
|
||||
// XXX if no multipart ?
|
||||
LOG_BUG (true, /* */, "eMailShrinker: bug 12: not multipart.");
|
||||
}
|
||||
copy (mbox, outbox, curPos, contentPos);
|
||||
curPos = contentPos;
|
||||
|
||||
@ -599,7 +613,7 @@ MainAttachment::substitute (ifstream &mbox, ofstream &outbox, const SizeArg &min
|
||||
if (emptyEMail && (attachMode & FOOTER)) {
|
||||
// check no main text
|
||||
LOG ("Force main text");
|
||||
LOG_BUG (boundary.empty () || ! subAttachements.size (), /**/, "eMailShrinker: can't force add footer M9: : " << *this);
|
||||
cerr << "eMailShrinker: force footer" << endl;
|
||||
string content (plainDisclaim);
|
||||
base64Encode (content);
|
||||
outbox << boundary.substr (0, boundary.length () -2) << endl
|
||||
@ -614,6 +628,7 @@ MainAttachment::substitute (ifstream &mbox, ofstream &outbox, const SizeArg &min
|
||||
|
||||
if (attachP->toExtract || attachP->isKazAttachment) {
|
||||
LOG ("skip Extracted or previous attachments");
|
||||
|
||||
|
||||
} else if (attachP->toUpdate) {
|
||||
string textProp = attachP->getProp (contentTypeToken, textRegEx);
|
||||
@ -685,20 +700,24 @@ MainAttachment::substitute (ifstream &mbox, ofstream &outbox, const SizeArg &min
|
||||
curPos = attachP->endPos;
|
||||
}
|
||||
if (plainDisclaim.size () && (attachMode & ATTACHMENT)) {
|
||||
// XXX si pas de multipart
|
||||
LOG ("Add kaz attachment");
|
||||
LOG_BUG (boundary.empty () || ! subAttachements.size (), /**/, "eMailShrinker: can't add Kaz attachment M10: : " << *this);
|
||||
cerr << "eMailShrinker: force attachment" << endl;
|
||||
streamoff lastPos = subAttachements.back ().endPos;
|
||||
copy (mbox, outbox, curPos, lastPos);
|
||||
curPos = lastPos;
|
||||
string content (KAZ_HTML_CONTENT+htmlDisclaim+BODY_END+HTML_END);
|
||||
base64Encode (content);
|
||||
outbox << boundary.substr (0, boundary.length () -2) << endl
|
||||
<< KAZ_ATTACHMENT_TEXT_HTML << endl
|
||||
<< content << endl;
|
||||
|
||||
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.flush ();
|
||||
}
|
||||
copy (mbox, outbox, curPos, endPos);
|
||||
outbox << endl;
|
||||
outbox.close ();
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
// knowledge of the CeCILL-B license and that you accept its terms. //
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define LAST_VERSION "2.3 2022-11-25 eMailShrinker"
|
||||
#define LAST_VERSION "2.4 2022-11-30 eMailShrinker"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
@ -435,3 +435,14 @@ kaz::charsetValue (string &content) {
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
void
|
||||
kaz::removeQuote (string &content) {
|
||||
if (content.empty () || content [0] !='"')
|
||||
return;
|
||||
string::size_type stop = content.rfind ('"');
|
||||
content = stop ?
|
||||
content.substr (1, stop-1) :
|
||||
content.substr (1);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
|
Reference in New Issue
Block a user