@ -51,68 +51,75 @@
using namespace std ;
using namespace kaz ;
static const string KAZ_WEB_SITE = " https://kaz.bzh/ " ;
static const string TMPL_DOWNLOAD = " {{DOWNLOAD}} " ;
static const string TMPL_FILENAME = " {{FILENAME}} " ;
static const string CID = " cid: " ;
static const string KAZ_WEB_SITE ( " https://kaz.bzh/ " ) ;
static const string TMPL_DOWNLOAD ( " {{DOWNLOAD}} " ) ;
static const string TMPL_FILENAME ( " {{FILENAME}} " ) ;
static const string CID ( " cid: " ) ;
// "l=/" => v1 compatibility
static const regex archiveURLSignature ( " .*(([&?]g=) | ( [ & ? ] l = / ) ) . * " ) ;
static const string KAZ_PLAIN_HR = " ______________________________________________________________________________ " ;
static const string KAZ_PLAIN_START = " ~~ PJ-KAZ ! " ; // don't end whith space
static const string KAZ_PLAIN_STOP = KAZ_PLAIN_START + " ~~ " ;
static const string KAZ_PLAIN_DONT_TOUCH = " (conservez cette partie intacte dans votre réponse si vous voulez transmettre les documents précédents) " ;
static const string KAZ_PLAIN_WARNING = " Attention : Kaz a dépollué ce message. Les pièces jointes ont été retirées et placées dans un dépôt provisoire. Elles seront automatiquement supprimées dans 1 mois. Si elles sont importantes et que vous souhaitez les conserver, vous devez utiliser les liens ci-dessous. Pour mieux comprendre la politique de nos services visitez kaz.bzh " ;
static const string KAZ_PLAIN_DOWLOAD_ONE = " Vos pièces jointes sont à télécharger individuellement ici : " ;
static const string KAZ_PLAIN_DOWLOAD_OTHER = " (Contenu dans des messages précédents) " ;
static const string KAZ_PLAIN_DOWLOAD_ALL = " Vous pouvez télécharger l'ensemble dans une archive là : " ;
static const string HEAD = " <head> " ;
static const string HEAD_END = " </head> " ;
static const string KAZ_CSS_URL = " https://kaz.bzh/m/email.css " ;
static const string KAZ_CSS = " <link rel= \" stylesheet \" type= \" text/css \" charset= \" utf-8 \" href= \" " + KAZ_CSS_URL + " \" /> " ;
static const string A_END = " </a> " ;
static const string LI_BEGIN = " <li " ;
static const string CLASS_ONE = " class= \" one \" " ;
static const string LI_ONE = LI_BEGIN + " " + CLASS_ONE + " > " ;
static const string LI_ALL = LI_BEGIN + " class= \" all \" > " ;
static const string LI_END = " </li> " ;
static const string HREF_ONE = " href= \" " ;
static const string BODY_END = " </body> " ;
static const string HTML_END = " </html> " ;
static const string KAZ_HTML_TAG = " <!--KAZ " ; // don't end whith space
static const string KAZ_HTML_START = KAZ_HTML_TAG + " START--> " ;
static const string KAZ_HTML_STOP = KAZ_HTML_TAG + " STOP--> " ;
static const string KAZ_PLAIN_HR ( " ______________________________________________________________________________ " ) ;
static const string KAZ_PLAIN_START ( " ~~ PJ-KAZ ! " ) ; // don't end whith space
static const string KAZ_PLAIN_STOP ( KAZ_PLAIN_START + " ~~ " ) ;
static const string KAZ_PLAIN_DONT_TOUCH ( " (conservez cette partie intacte dans votre réponse si vous voulez transmettre les documents précédents) " ) ;
static const string KAZ_PLAIN_WARNING ( " Attention : Kaz a dépollué ce message. Les pièces jointes ont été retirées et placées dans un dépôt provisoire. "
" Elles seront automatiquement supprimées dans 1 mois. "
" Si elles sont importantes et que vous souhaitez les conserver, vous devez utiliser les liens ci-dessous. "
" Pour mieux comprendre la politique de nos services visitez kaz.bzh " ) ;
static const string KAZ_PLAIN_DOWLOAD_ONE ( " Vos pièces jointes sont à télécharger individuellement ici : " ) ;
static const string KAZ_PLAIN_DOWLOAD_OTHER ( " (Contenu dans des messages précédents) " ) ;
static const string KAZ_PLAIN_DOWLOAD_ALL ( " Vous pouvez télécharger l'ensemble dans une archive là : " ) ;
static const string HEAD ( " <head> " ) ;
static const string HEAD_END ( " </head> " ) ;
static const string KAZ_CSS_URL ( " https://kaz.bzh/m/email.css " ) ;
static const string KAZ_CSS ( " <link rel= \" stylesheet \" type= \" text/css \" charset= \" utf-8 \" href= \" " + KAZ_CSS_URL + " \" /> " ) ;
static const string A_END ( " </a> " ) ;
static const string LI_BEGIN ( " <li " ) ;
static const string CLASS_ONE ( " class= \" one \" " ) ;
static const string LI_ONE ( LI_BEGIN + " " + CLASS_ONE + " > " ) ;
static const string LI_ALL ( LI_BEGIN + " class= \" all \" > " ) ;
static const string LI_END ( " </li> " ) ;
static const string HREF_ONE ( " href= \" " ) ;
static const string BODY_END ( " </body> " ) ;
static const string HTML_END ( " </html> " ) ;
static const string KAZ_HTML_TAG ( " <!--KAZ " ) ; // don't end whith space
static const string KAZ_HTML_START ( KAZ_HTML_TAG + " START--> " ) ;
static const string KAZ_HTML_STOP ( KAZ_HTML_TAG + " STOP--> " ) ;
// Textes précédents encodés en SGML
static const string KAZ_HTML_DONT_TOUCH = " (conservez cette partie intacte dans votre réponse si vous voulez transmettre les documents précédents) " ;
static const string KAZ_HTML_DOWLOAD_ONE = " Vos pièces jointes sont à télécharger individuellement ici : " ;
static const string KAZ_HTML_DOWLOAD_OTHER = " (Contenu dans des messages précédents) " ;
static const string KAZ_HTML_DOWLOAD_ALL = " Vous pouvez télécharger l'ensemble dans une archive là : " ;
static const string KAZ_HTML_ARCHIVE = " archive " ;
static const string KAZ_HTML_DONT_TOUCH ( " (conservez cette partie intacte dans votre réponse si vous voulez transmettre les documents précédents) " ) ;
static const string KAZ_HTML_DOWLOAD_ONE ( " Vos pièces jointes sont à télécharger individuellement ici : " ) ;
static const string KAZ_HTML_DOWLOAD_OTHER ( " (Contenu dans des messages précédents) " ) ;
static const string KAZ_HTML_DOWLOAD_ALL ( " Vous pouvez télécharger l'ensemble dans une archive là : " ) ;
static const string KAZ_HTML_ARCHIVE ( " archive " ) ;
static const string KAZ_EMPTY_TEXT_PLAIN ( " Content-Type: text/plain; charset=utf-8 \n "
" Content-Transfer-Encoding: base64 \n " ) ;
// ================================================================================
vector < string >
Attachment : : stringsToUpdate ( { KAZ_PLAIN_START , " \" " + CID } ) ;
// ================================================================================
const string MainAttachment : : templatePlainAddLink ( " * " + TMPL_FILENAME + " < " + TMPL_DOWNLOAD + " > \r \n " ) ;
const string MainAttachment : : templatePlainAllLink ( " \r \n * " + KAZ_PLAIN_DOWLOAD_ALL + " < " + TMPL_DOWNLOAD + " > \r \n " ) ;
const string MainAttachment : : templateHtmlHeader ( KAZ_HTML_START + " <p style= \" clear: left; padding: 1pc 0 0 0; font-size:10px; color:#969696; \" > " + KAZ_PLAIN_START + " </p><hr> \n "
" <div class= \" kaz \" > "
" <p style= \" font-size:10px; color:#969696; \" > " + KAZ_HTML_DONT_TOUCH + " </p> \n "
" <p> " + KAZ_HTML_DOWLOAD_ONE + " <ul> \n " ) ;
const string MainAttachment : : templateHtmlAddLink ( LI_ONE + " <a " + HREF_ONE + TMPL_DOWNLOAD + " \" > " + TMPL_FILENAME + " </a> " + LI_END + " \n " ) ;
const string MainAttachment : : templateHtmlOtherLink ( " </ul> " + KAZ_HTML_DOWLOAD_OTHER + " <ul> \n " ) ;
const string MainAttachment : : templateHtmlAllLink ( " </ul><ul> " + LI_ALL + KAZ_HTML_DOWLOAD_ALL + " <a href= \" " + TMPL_DOWNLOAD + " \" > " + KAZ_HTML_ARCHIVE + " </a> " + LI_END + " \n " ) ;
const string MainAttachment : : templateHtmlFooter ( " </ul></p> \n "
" <p class= \" msg \" ><a class= \" kaz \" href= \" " + KAZ_WEB_SITE + " \" > " + KAZ_WEB_SITE + " </a></p></div> \n "
" <hr><p style= \" font-size:10px; color:#969696; \" > " + KAZ_PLAIN_STOP + " </p> " + KAZ_HTML_STOP + " \n " ) ;
const regex MainAttachment : : whiteSpaceRegEx ( " \\ s+ " ) ;
const string MainAttachment : : templatePlainAddLink ( " * " + TMPL_FILENAME + " < " + TMPL_DOWNLOAD + " > \r \n " ) ;
const string MainAttachment : : templatePlainAllLink ( " \r \n * " + KAZ_PLAIN_DOWLOAD_ALL + " < " + TMPL_DOWNLOAD + " > \r \n " ) ;
const string MainAttachment : : templateHtmlHeader ( KAZ_HTML_START + " <p style= \" clear: left; padding: 1pc 0 0 0; font-size:10px; color:#969696; \" > " + KAZ_PLAIN_START + " </p><hr> \n "
" <div class= \" kaz \" > "
" <p style= \" font-size:10px; color:#969696; \" > " + KAZ_HTML_DONT_TOUCH + " </p> \n "
" <p> " + KAZ_HTML_DOWLOAD_ONE + " <ul> \n " ) ;
const string MainAttachment : : templateHtmlAddLink ( LI_ONE + " <a " + HREF_ONE + TMPL_DOWNLOAD + " \" > " + TMPL_FILENAME + " </a> " + LI_END + " \n " ) ;
const string MainAttachment : : templateHtmlOtherLink ( " </ul> " + KAZ_HTML_DOWLOAD_OTHER + " <ul> \n " ) ;
const string MainAttachment : : templateHtmlAllLink ( " </ul><ul> " + LI_ALL + KAZ_HTML_DOWLOAD_ALL + " <a href= \" " + TMPL_DOWNLOAD + " \" > " + KAZ_HTML_ARCHIVE + " </a> " + LI_END + " \n " ) ;
const string MainAttachment : : templateHtmlFooter ( " </ul></p> \n "
" <p class= \" msg \" ><a class= \" kaz \" href= \" " + KAZ_WEB_SITE + " \" > " + KAZ_WEB_SITE + " </a></p></div> \n "
" <hr><p style= \" font-size:10px; color:#969696; \" > " + KAZ_PLAIN_STOP + " </p> " + KAZ_HTML_STOP + " \n " ) ;
const regex MainAttachment : : whiteSpaceRegEx ( " \\ s+ " ) ;
// ================================================================================
void
@ -173,7 +180,7 @@ MainAttachment::addLink (string &plain, string &html, const string &url, const s
string htmlNewOneLink ( templateHtmlAddLink ) ;
string codedUrl ( url ) ;
// XXX amp ?
replaceAll ( codedUrl , " & " , " & " ) ;
//replaceAll (codedUrl, "&", "&");
replaceAll ( htmlNewOneLink , TMPL_DOWNLOAD , codedUrl ) ;
replaceAll ( htmlNewOneLink , TMPL_FILENAME , name ) ;
html + = htmlNewOneLink ;
@ -228,7 +235,7 @@ MainAttachment::getDisclaim (string &plain, string &html) const {
replaceAll ( allHtmlLinks , TMPL_DOWNLOAD , archiveDownloadURL ) ;
html + = allHtmlLinks ;
}
html + = templateHtmlFooter ;
html + = templateHtmlFooter + " \r \n " ;
plain + = " \r \n \r \n " + KAZ_WEB_SITE + " \r \n " + KAZ_PLAIN_HR + " \r \n " + KAZ_PLAIN_STOP + " \r \n " ;
// & => & done
LOG ( " plain: " < < plain ) ;
@ -380,7 +387,8 @@ MainAttachment::removePreviousArchive () {
// ================================================================================
MainAttachment : : MainAttachment ( ifstream & mbox )
: Attachment ( mbox , initTmpLevel ( ) , 0 , initTmpPos ( ) ) {
: Attachment ( mbox , initTmpLevel ( ) , 0 , initTmpPos ( ) ) ,
forceMainText ( false ) {
DEF_LOG ( " MainAttachment::MainAttachment " , " " ) ;
string line ;
for ( ; getline ( mbox , line ) ; )
@ -394,6 +402,7 @@ MainAttachment::markSignificant (const streamoff &minAttachSize, ifstream &mbox)
DEF_LOG ( " MainAttachment::markSignificant " , " minAttachSize: " < < minAttachSize ) ;
bool plainMarked ( false ) , htmlMarked ( false ) ;
markDisclaim ( plainMarked , htmlMarked ) ;
forceMainText = ! ( plainMarked | | htmlMarked ) ;
Attachment : : markSignificant ( " " , minAttachSize , mbox , allMarkedPtrs ) ;
}
@ -529,7 +538,7 @@ MainAttachment::substitute (ifstream &mbox, ofstream &outbox, const SizeArg &min
}
if ( attachP - > cid . length ( ) ) {
string tmp ( attachP - > downloadUrl ) ;
replaceAll ( tmp , " & " , " & " ) ;
//replaceAll (tmp, "&", "&");
translateHtml . insert ( pair < const string , const string > ( CID + attachP - > cid , tmp ) ) ;
}
}
@ -546,9 +555,23 @@ MainAttachment::substitute (ifstream &mbox, ofstream &outbox, const SizeArg &min
getDisclaim ( plainDisclaim , htmlDisclaim ) ;
// copy email
streamoff curPos = 0 ;
if ( forceMainText ) {
cerr < < endl < < endl < < " #################### coucou " < < forceMainText < < " " < < contentPos < < " " < < * this < < endl ;
// check no main text
LOG ( " Force main text " ) ;
LOG_BUG ( boundary . empty ( ) | | ! subAttachements . size ( ) , /**/ , " eMailShrinker: can't force add footer M9: : " < < * this ) ;
copy ( mbox , outbox , curPos , contentPos ) ;
curPos = contentPos ;
cerr < < " #################### coucou " < < curPos < < endl < < endl ;
string content ( plainDisclaim ) ;
base64Encode ( content ) ;
outbox < < boundary . substr ( 0 , boundary . length ( ) - 2 ) < < endl
< < KAZ_EMPTY_TEXT_PLAIN < < endl
< < content < < endl ;
outbox . flush ( ) ;
}
for ( Attachment * attachP : allMarkedPtrs ) {
copy ( mbox , outbox , curPos , attachP - > beginInParent ) ;
LOG_BUG ( attachP - > toUpdate & & attachP - > toExtract , /**/ , " eMailShrinker: bug M5: update and extract. pos: " < < attachP - > beginPos ) ;
if ( attachP - > toExtract ) {