manage cloud links

This commit is contained in:
François 2024-12-09 17:28:39 +01:00
parent 761ba99de1
commit f03c0ec95b
5 changed files with 62 additions and 4 deletions

View File

@ -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}"

View File

@ -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}"

View File

@ -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 ("<head>");
static const string HEAD_END ("</head>");
@ -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&egrave;ces jointes sont &agrave; t&eacute;l&eacute;charger individuellement ici :");
static const string KAZ_HTML_DOWLOAD_OTHER ("(Contenu dans des messages pr&eacute;c&eacute;dents)");
static const string KAZ_HTML_DOWLOAD_ALL ("Vous pouvez t&eacute;l&eacute;charger l'ensemble dans une archive l&agrave; :");
static const string KAZ_HTML_DOWLOAD_CLOUD ("Vous pouvez classer les pi&egrave;ces jointes dans votre cloud l&agrave; :");
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+"<p style=\"clear: left; padding: 1pc 0 0 0; font-size:10px; color:#969696;\">"+KAZ_PLAIN_START+"</p><hr>\n"
"<div class=\"kaz\">"
@ -122,6 +125,7 @@ const string MainAttachment::templateHtmlHeader (KAZ_HTML_START+"<p style=\"cle
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::templateHtmlCloudLink ("</ul><ul>"+LI_ALL+KAZ_HTML_DOWLOAD_CLOUD+" <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\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";
// & => &amp; 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);

View File

@ -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 <iostream>

View File

@ -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 */