From f03c0ec95b3991bf16dbc46a1bcae2ca171e2f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Mon, 9 Dec 2024 17:28:39 +0100 Subject: [PATCH] manage cloud links --- src/bash/filter.sh | 15 +++++++++++++++ src/bash/filterTest.sh | 13 +++++++++++++ src/cpp/MainAttachment.cpp | 27 +++++++++++++++++++++++++++ src/cpp/eMailShrinker.cpp | 4 ++-- src/include/MainAttachment.hpp | 7 +++++-- 5 files changed, 62 insertions(+), 4 deletions(-) diff --git a/src/bash/filter.sh b/src/bash/filter.sh index d5d89bd..0ac6979 100755 --- a/src/bash/filter.sh +++ b/src/bash/filter.sh @@ -241,6 +241,10 @@ if [ "$(check_skip_domains "${SKIP_DOMAINS}" "${LIST_EMAILS}")" = "yes" ]; then quitFilter 0 fi +######################################## +# Préparation pour le cloud +rm -f "${TMP_DIR}/last.txt" + # Etape de rafraichissement des anciens fichiers inclus echo "time: ${DATE_TEMPS}${NL}id: $(date +%s)" > "${ARCHIVE_CONTENT}" [ -n "${TRACK}" ] && echo "sender: ${MAIL_SOURCE}" >> "${ARCHIVE_CONTENT}" @@ -255,6 +259,7 @@ cat "${OLD_LINKS}" | grep "${JIRAFEAU_URL}" | while read REMOTE_LINK; do # update periode for download curlJirafeauUpdate "${PERIOD}" "${REMOTE_REF}" 2>&1 >> "${TMP_LOG}" echo "old: ${REMOTE_REF} ${REMOTE_KEY}" >> "${ARCHIVE_CONTENT}" + echo "f=${REMOTE_REF}~${REMOTE_KEY}" > "${TMP_DIR}/last.txt" done LOG_FIC " - archive starts with: ${NL}${YELLOW}$(cat ${ARCHIVE_CONTENT})${NC}" @@ -271,6 +276,7 @@ LOG_FIC "${CYAN}${SHRINK_CMD} -s \"${MAX_KEEP_IN_MAIL}\" -d \"${REP_PIECE_JOINTE # XXX error continue fi + # Etape de televersement des pieces jointes PASSWORD=$(apg -n 1 -m 12 -M cln) PASSWORD_MD5=$(echo -n ${PASSWORD} | ${MD5_CMD} | cut -d \ -f 1) @@ -290,10 +296,12 @@ LOG_FIC "${CYAN}${SHRINK_CMD} -s \"${MAX_KEEP_IN_MAIL}\" -d \"${REP_PIECE_JOINTE LOG_FIC " - change by link ${YELLOW}${JIRAFEAU_URL}/f.php?d=0&h=${JIR_TOKEN}&k=${PASSWORD_MD5}${NC}" echo "url: ${JIRAFEAU_URL}/f.php?d=0&h=${JIR_TOKEN}&k=${PASSWORD_MD5}" echo "new: ${JIR_TOKEN} ${PASSWORD_MD5}" >> "${ARCHIVE_CONTENT}" + echo "f=${JIR_TOKEN}~${PASSWORD_MD5}" > "${TMP_DIR}/last.txt" ;; esac } done + # Création de l'archive NB_ATTACH=$(grep -e "^old: " -e "^new: " "${ARCHIVE_CONTENT}" | wc -l) if [ \( -n "${TRACK}" -a "${NB_ATTACH}" -gt 0 \) -o "${NB_ATTACH}" -gt 1 ]; then @@ -319,6 +327,7 @@ LOG_FIC "${CYAN}${SHRINK_CMD} -s \"${MAX_KEEP_IN_MAIL}\" -d \"${REP_PIECE_JOINTE * ) LOG_FIC " - add archive ${YELLOW}${JIRAFEAU_URL}/a.php?g=${JIR_TOKEN}~${PASSWORD_MD5}${NC}" echo "arch: ${JIRAFEAU_URL}/a.php?g=${JIR_TOKEN}~${PASSWORD_MD5}" + echo "a=${JIR_TOKEN}~${PASSWORD_MD5}" > "${TMP_DIR}/last.txt" ;; esac } @@ -326,6 +335,12 @@ LOG_FIC "${CYAN}${SHRINK_CMD} -s \"${MAX_KEEP_IN_MAIL}\" -d \"${REP_PIECE_JOINTE LOG_FIC " - no archive (less than 2 attach file)" echo "arch: none" fi + if [ -s "${TMP_DIR}/last.txt" ]; then + echo "cloud: ${JIRAFEAU_URL}/c.php?$(cat "${TMP_DIR}/last.txt")" + else + echo "cloud: none" + fi + # Etape de substitution LOG_FIC "${CYAN}${SHRINK_CMD} -m \"${MODE}\" -s \"${MAX_KEEP_IN_MAIL}\" \"${INSPECT_DIR}/in.$$\" \"${INSPECT_DIR}/in.$$.altered\" 2>> \"${TMP_LOG}\"${NC}" } | "${SHRINK_CMD}" -m "${MODE}" -s "${MAX_KEEP_IN_MAIL}" "${INSPECT_DIR}/in.$$" "${INSPECT_DIR}/in.$$.altered" 2>> "${TMP_LOG}" diff --git a/src/bash/filterTest.sh b/src/bash/filterTest.sh index fc6d10b..1ec7470 100755 --- a/src/bash/filterTest.sh +++ b/src/bash/filterTest.sh @@ -136,6 +136,10 @@ LOG " - ${BLUE}mbox: ${mbox}${NC}${YELLOW}" "${eMailShrinker}" -l "${mbox}" LOG "${NC}" +######################################## +# Préparation pour le cloud +rm -f "${TMP_DIR}/last.txt" + ######################################## # recherche des prolongations des délais de grace "${eMailShrinker}" ${DEBUG} -u "${mbox}" > "${TMP_DIR}/url-to-refresh.txt" @@ -145,6 +149,7 @@ cat "${TMP_DIR}/url-to-refresh.txt" | grep "${JIRAFEAU_URL}" | while read REMOTE LOG " - ${BLUE}update ${REMOTE_REF}${NC}" curlJirafeauUpdate "${PERIODE}" "${REMOTE_REF}" echo "old: ${REMOTE_REF} ${REMOTE_KEY}" >> "${TMP_DIR}/archive-content.txt" + echo "f=${REMOTE_REF}~${REMOTE_KEY}" > "${TMP_DIR}/last.txt" done ######################################## @@ -188,6 +193,7 @@ cat "${TMP_DIR}/PJ-name.txt" | { LOG " - ${GREEN} upload ${ATTACH_MEDIA}${NC}" echo "url: ${JIRAFEAU_URL}/f.php?d=1&h=${JIR_TOKEN}&k=${PASSWORD_MD5}" echo "new: ${JIR_TOKEN} ${PASSWORD_MD5}" >> "${TMP_DIR}/archive-content.txt" + echo "f=${JIR_TOKEN}~${PASSWORD_MD5}" > "${TMP_DIR}/last.txt" ;; esac } @@ -209,6 +215,7 @@ cat "${TMP_DIR}/PJ-name.txt" | { * ) LOG " - ${GREEN} upload archive-content.txt${NC}" echo "arch: ${JIRAFEAU_URL}/a.php?g=${JIR_TOKEN}~${PASSWORD_MD5}" + echo "a=${JIR_TOKEN}~${PASSWORD_MD5}" > "${TMP_DIR}/last.txt" ;; esac } @@ -216,6 +223,12 @@ cat "${TMP_DIR}/PJ-name.txt" | { LOG " - ${GREEN}no archive${NC}" echo "arch: none" fi + if [ -s "${TMP_DIR}/last.txt" ]; then + echo "cloud: ${JIRAFEAU_URL}/c.php?$(cat "${TMP_DIR}/last.txt")" + else + echo "cloud: none" + fi + } > "${TMP_DIR}/PJ-Keys.txt" LOG " - ${BLUE}PJ-Keys: ${NC}" diff --git a/src/cpp/MainAttachment.cpp b/src/cpp/MainAttachment.cpp index d8278e7..fca0e4c 100644 --- a/src/cpp/MainAttachment.cpp +++ b/src/cpp/MainAttachment.cpp @@ -74,6 +74,7 @@ static const string KAZ_PLAIN_WARNING ("Attention : Kaz a dépollué ce 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 KAZ_PLAIN_DOWLOAD_CLOUD ("Vous pouvez classer les pièces jointes dans votre cloud là :"); static const string HEAD (""); static const string HEAD_END (""); @@ -98,6 +99,7 @@ static const string KAZ_HTML_DONT_TOUCH ("(conservez cette partie intacte dans 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_DOWLOAD_CLOUD ("Vous pouvez classer les pièces jointes dans votre cloud là :"); static const string KAZ_HTML_ARCHIVE ("archive"); static const string KAZ_EMPTY_TEXT_PLAIN ("Content-Type: text/plain; charset=utf-8\n" @@ -114,6 +116,7 @@ Attachment::stringsToUpdate ({KAZ_PLAIN_START, "\""+CID}); // ================================================================================ const string MainAttachment::templatePlainAddLink (" * "+TMPL_FILENAME+" < "+TMPL_DOWNLOAD+" >\n"); const string MainAttachment::templatePlainAllLink ("\n * "+KAZ_PLAIN_DOWLOAD_ALL+" < "+TMPL_DOWNLOAD+" >\n"); +const string MainAttachment::templatePlainCloudLink ("\n * "+KAZ_PLAIN_DOWLOAD_CLOUD+" < "+TMPL_DOWNLOAD+" >\n"); const string MainAttachment::templateHtmlHeader (KAZ_HTML_START+"

"+KAZ_PLAIN_START+"


\n" "
" @@ -122,6 +125,7 @@ const string MainAttachment::templateHtmlHeader (KAZ_HTML_START+"

"+TMPL_FILENAME+""+LI_END+"\n"); const string MainAttachment::templateHtmlOtherLink (""+KAZ_HTML_DOWLOAD_OTHER+"

\n" "

"+KAZ_WEB_SITE+"

\n" "

"+KAZ_PLAIN_STOP+"

"+KAZ_HTML_STOP+"\n\n"); @@ -212,6 +216,20 @@ MainAttachment::readArchiveUrl () { archiveDownloadURL = line.substr (6); } +// ================================================================================ +void +MainAttachment::readCloudUrl () { + cloudDownloadURL.clear (); + DEF_LOG ("MainAttachment::readCloudUrl", ""); + string line; + getline (cin, line); + LOG_BUG (line.rfind ("cloud: ", 0) != 0, return, "eMailShrinker: bug M13: no cloud link. (line: " << line << ")"); + LOG_BUG (line.rfind ("cloud: bad", 0) == 0, return, "eMailShrinker: bug M14: bad cloud link. (line: " << line << ")"); + if (line.rfind ("cloud: none", 0) == 0) + return; + cloudDownloadURL = line.substr (7); +} + // ================================================================================ void MainAttachment::readDownloadUrl (string &url) { @@ -299,6 +317,14 @@ MainAttachment::getDisclaim (string &plain, string &html) const { replaceAll (allHtmlLinks, TMPL_DOWNLOAD, archiveDownloadURL); html += allHtmlLinks; } + if (linkCount && cloudDownloadURL.length ()) { + string cloudPlainLinks (templatePlainCloudLink); + replaceAll (cloudPlainLinks, TMPL_DOWNLOAD, cloudDownloadURL); + plain += cloudPlainLinks; + string cloudHtmlLinks (templateHtmlCloudLink); + replaceAll (cloudHtmlLinks, TMPL_DOWNLOAD, cloudDownloadURL); + html += cloudHtmlLinks; + } html += templateHtmlFooter+"\n"; plain += "\n\n"+KAZ_WEB_SITE+"\n\n"+KAZ_PLAIN_WARNING+"\n"+KAZ_PLAIN_HR+"\n"+KAZ_PLAIN_STOP+"\n\n\n"; // & => & done @@ -693,6 +719,7 @@ MainAttachment::substitute (ifstream &mbox, ofstream &outbox, const SizeArg &min // XXX test empty ? } readArchiveUrl (); + readCloudUrl (); removePreviousArchive (); string plainDisclaim, htmlDisclaim; getDisclaim (plainDisclaim, htmlDisclaim); diff --git a/src/cpp/eMailShrinker.cpp b/src/cpp/eMailShrinker.cpp index 592ec91..3a3f198 100644 --- a/src/cpp/eMailShrinker.cpp +++ b/src/cpp/eMailShrinker.cpp @@ -33,8 +33,8 @@ //////////////////////////////////////////////////////////////////////////// #include "version.hpp" -const std::string kaz::LAST_VERSION_NUM ("2.21"); -const std::string kaz::LAST_VERSION_DATE ("2024-06-04"); +const std::string kaz::LAST_VERSION_NUM ("2.22"); +const std::string kaz::LAST_VERSION_DATE ("2024-12-09"); const std::string kaz::LAST_VERSION (LAST_VERSION_NUM+" "+LAST_VERSION_DATE+" eMailShrinker"); #include diff --git a/src/include/MainAttachment.hpp b/src/include/MainAttachment.hpp index 74d4781..024119b 100644 --- a/src/include/MainAttachment.hpp +++ b/src/include/MainAttachment.hpp @@ -61,7 +61,7 @@ namespace kaz { class MainAttachment : public Attachment { public: /*! text to add in disclaim */ - static const string templatePlainAddLink, templatePlainAllLink, templateHtmlHeader, templateHtmlAddLink, templateHtmlOtherLink, templateHtmlAllLink, templateHtmlFooter; + static const string templatePlainAddLink, templatePlainAllLink, templatePlainCloudLink, templateHtmlHeader, templateHtmlAddLink, templateHtmlOtherLink, templateHtmlAllLink, templateHtmlCloudLink, templateHtmlFooter; /*! white space to split a text */ static const regex whiteSpaceRegEx; @@ -71,9 +71,10 @@ namespace kaz { /*! get url from stdin */ void readDownloadUrl (string &url); - /*! get archive url from stdin */ void readArchiveUrl (); + /*! get cloud url from stdin */ + void readCloudUrl (); /*! location of extracted files */ void setExtractDir (const bfs::path &extractDir); @@ -96,6 +97,8 @@ namespace kaz { bfs::path extractDir; /*! URL for download archives */ string archiveDownloadURL; + /*! URL for download cloud */ + string cloudDownloadURL; /*! if no main text in email can be used to add disclaim */ bool emptyEMail; /*! if contain previous kaz attachment */