From df7a25d331efa2a14b32261c89512561f2460c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Fri, 9 Dec 2022 08:54:02 +0100 Subject: [PATCH] double remove & / display version --- src/bash/filter.sh | 0 src/bash/filterTest.sh | 0 src/cpp/Attachment.cpp | 2 +- src/cpp/MainAttachment.cpp | 22 ++++++++--------- src/cpp/eMailShrinker.cpp | 7 ++++-- src/cpp/kazMisc.cpp | 11 ++++++--- src/include/version.hpp | 48 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 73 insertions(+), 17 deletions(-) mode change 100644 => 100755 src/bash/filter.sh mode change 100644 => 100755 src/bash/filterTest.sh create mode 100644 src/include/version.hpp diff --git a/src/bash/filter.sh b/src/bash/filter.sh old mode 100644 new mode 100755 diff --git a/src/bash/filterTest.sh b/src/bash/filterTest.sh old mode 100644 new mode 100755 diff --git a/src/cpp/Attachment.cpp b/src/cpp/Attachment.cpp index dba811e..9d2c11f 100644 --- a/src/cpp/Attachment.cpp +++ b/src/cpp/Attachment.cpp @@ -142,7 +142,7 @@ Attachment::getSection (const string &content, const string &beginTag, const str for (const string &s : list) result += s; LOG ("result: " << result); - return result; + return result; } // ================================================================================ diff --git a/src/cpp/MainAttachment.cpp b/src/cpp/MainAttachment.cpp index 38823ea..878bd2b 100644 --- a/src/cpp/MainAttachment.cpp +++ b/src/cpp/MainAttachment.cpp @@ -45,6 +45,7 @@ #include #include +#include "version.hpp" #include "kazDebug.hpp" #include "kazMisc.hpp" #include "SizeArg.hpp" @@ -62,11 +63,10 @@ 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+" ~~\n\n"); -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_DONT_TOUCH ("(conservez cette partie intacte dans votre réponse si vous voulez transmettre les documents précédents (version "+LAST_VERSION_NUM+"))"); 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. " @@ -94,7 +94,7 @@ static const string KAZ_HTML_TAG (""); 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_DONT_TOUCH ("(conservez cette partie intacte dans votre réponse si vous voulez transmettre les documents précédents (version "+LAST_VERSION_NUM+"))"); 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à :"); @@ -112,8 +112,8 @@ vector 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::templatePlainAddLink (" * "+TMPL_FILENAME+" <"+TMPL_DOWNLOAD+">\n"); +const string MainAttachment::templatePlainAllLink ("\n * "+KAZ_PLAIN_DOWLOAD_ALL+" <"+TMPL_DOWNLOAD+">\n"); const string MainAttachment::templateHtmlHeader (KAZ_HTML_START+"

"+KAZ_PLAIN_START+"


\n" "
" @@ -257,10 +257,10 @@ MainAttachment::getDisclaim (string &plain, string &html) const { return; } - plain = "\r\n"+KAZ_PLAIN_START+"\r\n"+KAZ_PLAIN_HR+"\r\n"+KAZ_PLAIN_DONT_TOUCH+"\r\n\r\n"+KAZ_PLAIN_DOWLOAD_ONE+"\r\n"+plainNewLinks; + plain = "\n"+KAZ_PLAIN_START+"\n\n"+KAZ_PLAIN_HR+"\n"+KAZ_PLAIN_DONT_TOUCH+"\n\n"+KAZ_PLAIN_DOWLOAD_ONE+"\n"+plainNewLinks; html = templateHtmlHeader+htmlNewLinks; if (previousLinks.size ()) { - plain += "\r\n"+KAZ_PLAIN_DOWLOAD_OTHER+"\r\n"+plainOldLinks; + plain += "\n"+KAZ_PLAIN_DOWLOAD_OTHER+"\n"+plainOldLinks; html += templateHtmlOtherLink+htmlOldLinks; } if (linkCount > 1 && archiveDownloadURL.length ()) { @@ -271,8 +271,8 @@ MainAttachment::getDisclaim (string &plain, string &html) const { replaceAll (allHtmlLinks, TMPL_DOWNLOAD, archiveDownloadURL); html += allHtmlLinks; } - html += templateHtmlFooter+"\r\n"; - plain += "\r\n\r\n"+KAZ_WEB_SITE+"\r\n\r\n"+KAZ_PLAIN_WARNING+"\r\n"+KAZ_PLAIN_HR+"\r\n"+KAZ_PLAIN_STOP+"\r\n"; + html += templateHtmlFooter+"\n"; + plain += "\n\n"+KAZ_WEB_SITE+"\n\n"+KAZ_PLAIN_WARNING+"\n"+KAZ_PLAIN_HR+"\n"+KAZ_PLAIN_STOP+"\n"; // & => & done LOG ("plain: " << plain); LOG ("html: " << html); @@ -288,7 +288,7 @@ MainAttachment::addPrevious (const string &href, const string &name, const bool if (oldVal.length () && name.length () && !trust) return; previousLinks.erase (href); - previousLinks [href] = regex_replace (name, regex (R"([\t\r\n\"]+|(\\\")|(>\s*))"), ""); + previousLinks [href] = regex_replace (name, regex (R"([\t\n\"]+|(\\\")|(>\s*))"), ""); LOG ("inserted: " << href << ": " << previousLinks[href]); } @@ -380,6 +380,7 @@ MainAttachment::extractPreviousKAZ (string &extractedPlainKAZ, string &extracted if (textProp.empty ()) return; string content (attach.getContent (mbox)); + replaceAll (content, "&", "&"); if (textProp == PLAIN) { LOG (PLAIN); extractedPlainKAZ += attach.getSection (content, KAZ_PLAIN_START, KAZ_PLAIN_STOP); @@ -389,7 +390,6 @@ MainAttachment::extractPreviousKAZ (string &extractedPlainKAZ, string &extracted 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; } } diff --git a/src/cpp/eMailShrinker.cpp b/src/cpp/eMailShrinker.cpp index bb2ece8..bec687c 100644 --- a/src/cpp/eMailShrinker.cpp +++ b/src/cpp/eMailShrinker.cpp @@ -32,7 +32,10 @@ // knowledge of the CeCILL-B license and that you accept its terms. // //////////////////////////////////////////////////////////////////////////// -#define LAST_VERSION "2.5 2022-12-08 eMailShrinker" +#include "version.hpp" +const std::string kaz::LAST_VERSION_NUM ("2.6"); +const std::string kaz::LAST_VERSION_DATE ("2022-12-09"); +const std::string kaz::LAST_VERSION (LAST_VERSION+" "+LAST_VERSION_DATE+" eMailShrinker"); #include #include @@ -232,4 +235,4 @@ main (int argc, char** argv) { return 0; } - // ================================================================================ +// ================================================================================ diff --git a/src/cpp/kazMisc.cpp b/src/cpp/kazMisc.cpp index a15598f..9982afa 100644 --- a/src/cpp/kazMisc.cpp +++ b/src/cpp/kazMisc.cpp @@ -439,9 +439,14 @@ void kaz::removeQuote (string &content) { if (content.empty () || content [0] != '"') return; - - string::size_type stop = content.find ('"', 1); - content = stop ? + string::size_type stop = (1); + for (;;) { + stop = content.find ('"', stop); + if (stop == string::npos || content [stop-1] != '\\') + break; + ++stop; + } + content = (stop != string::npos) ? content.substr (1, stop-1) : content.substr (1); } diff --git a/src/include/version.hpp b/src/include/version.hpp new file mode 100644 index 0000000..3cad29a --- /dev/null +++ b/src/include/version.hpp @@ -0,0 +1,48 @@ +//////////////////////////////////////////////////////////////////////////// +// Copyright KAZ 2021 // +// // +// contact (at) kaz.bzh // +// // +// This software is a filter to shrink email by attachment extraction. // +// // +// This software is governed by the CeCILL-B license under French law and // +// abiding by the rules of distribution of free software. You can use, // +// modify and/or redistribute the software under the terms of the // +// CeCILL-B license as circulated by CEA, CNRS and INRIA at the following // +// URL "http://www.cecill.info". // +// // +// As a counterpart to the access to the source code and rights to copy, // +// modify and redistribute granted by the license, users are provided // +// only with a limited warranty and the software's author, the holder of // +// the economic rights, and the successive licensors have only limited // +// liability. // +// // +// In this respect, the user's attention is drawn to the risks associated // +// with loading, using, modifying and/or developing or reproducing the // +// software by the user in light of its specific status of free software, // +// that may mean that it is complicated to manipulate, and that also // +// therefore means that it is reserved for developers and experienced // +// professionals having in-depth computer knowledge. Users are therefore // +// encouraged to load and test the software's suitability as regards // +// their requirements in conditions enabling the security of their // +// systems and/or data to be ensured and, more generally, to use and // +// operate it in the same conditions as regards security. // +// // +// The fact that you are presently reading this means that you have had // +// knowledge of the CeCILL-B license and that you accept its terms. // +//////////////////////////////////////////////////////////////////////////// + +#ifndef _kaz_version_hpp +#define _kaz_version_hpp + +#include + +namespace kaz { + // ================================================================================ + + extern const std::string LAST_VERSION_NUM, LAST_VERSION_DATE, LAST_VERSION; + + // ================================================================================ +} + +#endif // _kaz_version_hpp