|
|
@ -1,4 +1,37 @@ |
|
|
|
#!/bin/bash |
|
|
|
########################################################################## |
|
|
|
# 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. # |
|
|
|
########################################################################## |
|
|
|
|
|
|
|
PRG=$(basename $0) |
|
|
|
|
|
|
@ -16,21 +49,16 @@ NL=' |
|
|
|
' |
|
|
|
|
|
|
|
TTY=$(tty) |
|
|
|
|
|
|
|
|
|
|
|
######################################## |
|
|
|
LOG () { |
|
|
|
echo "$1" >> "${TTY}" |
|
|
|
} |
|
|
|
|
|
|
|
usage () { |
|
|
|
echo "Usage: ${PRG} mbox" |
|
|
|
echo "Usage: ${PRG} [-h|-v|-g] [-m {NONE|FOOTER|ATTACHMENT|BOTH}] mbox" |
|
|
|
exit 1 |
|
|
|
} |
|
|
|
|
|
|
|
[ "$#" -eq 1 ] || usage |
|
|
|
|
|
|
|
|
|
|
|
######################################## |
|
|
|
mbox=$(realpath $1) |
|
|
|
dos2unix "${mbox}" |
|
|
@ -41,23 +69,48 @@ JIRAFEAU_LOCAL="${JIRAFEAU_URL}" |
|
|
|
|
|
|
|
TMP_DIR="$(mktemp)" |
|
|
|
|
|
|
|
######################################## |
|
|
|
# recherche des binaires |
|
|
|
eMailShrinker="$(realpath "./eMailShrinker")" |
|
|
|
[ -x "${eMailShrinker}" ] || eMailShrinker="$(realpath "../../build/out/eMailShrinker")" |
|
|
|
[ -x "${eMailShrinker}" ] || ( echo "${RED}eMailShrinker not found${NC}" ; exit) |
|
|
|
|
|
|
|
jirafeauAPI="$(realpath "./jirafeauAPI")" |
|
|
|
[ -x "${jirafeauAPI}" ] || jirafeauAPI="$(realpath "../../build/out/jirafeauAPI")" |
|
|
|
[ -x "${jirafeauAPI}" ] || ( echo "${RED}jirafeauAPI not found${NC}" ; exit) |
|
|
|
|
|
|
|
for ARG in $*; do |
|
|
|
case "$1" in |
|
|
|
-h*) usage;; |
|
|
|
-v*) "${eMailShrinker}" -v; exit;; |
|
|
|
-g) DEBUG="-g"; shift;; |
|
|
|
-m) shift; ATTACH_MODE="-m $1"; shift;; # XXX test option |
|
|
|
*) break;; |
|
|
|
esac |
|
|
|
done |
|
|
|
case "${ATTACH_MODE}" in |
|
|
|
NONE|FOOTER|ATTACHMENT|BOTH);; |
|
|
|
*) usage;; |
|
|
|
esac |
|
|
|
|
|
|
|
[ "$#" -eq 1 ] || usage |
|
|
|
|
|
|
|
######################################## |
|
|
|
# nettoyage |
|
|
|
rm -f "${TMP_DIR}" ; mkdir -p "${TMP_DIR}" |
|
|
|
rm -fr "${TMP_DIR}/PJ-name.txt" "${TMP_DIR}/PJ-Keys.txt" "${TMP_DIR}/PJ" "${TMP_DIR}/archive-content.txt" "${TMP_DIR}/url-to-refresh.txt" "${TMP_DIR}/new-mbox" |
|
|
|
|
|
|
|
echo -e "time: $(date "+%Y-%m-%d-%H:%M:%S")\nid: $(date +%s)" > "${TMP_DIR}/archive-content.txt" |
|
|
|
|
|
|
|
######################################## |
|
|
|
# affichage de la structure de départ |
|
|
|
LOG " - ${BLUE}mbox: ${mbox}${NC}" |
|
|
|
"${eMailShrinker}" -l "${mbox}" |
|
|
|
LOG |
|
|
|
|
|
|
|
######################################## |
|
|
|
# recherche des prolongations des délais de grace |
|
|
|
"${eMailShrinker}" -u "${mbox}" > "${TMP_DIR}/url-to-refresh.txt" 2>> "${TTY}" |
|
|
|
|
|
|
|
|
|
|
|
cat "${TMP_DIR}/url-to-refresh.txt" | grep "${JIRAFEAU_URL}" | while read REMOTE_LINK; do |
|
|
|
REMOTE_REF=$(echo "${REMOTE_LINK}" | sed -e 's/.*h=\([^&]*\).*/\1/' -e 's/.*http.*//') |
|
|
|
[ -z "${REMOTE_REF}" ] && continue |
|
|
@ -67,12 +120,16 @@ cat "${TMP_DIR}/url-to-refresh.txt" | grep "${JIRAFEAU_URL}" | while read REMOTE |
|
|
|
echo "old: ${REMOTE_REF} ${REMOTE_KEY}" >> "${TMP_DIR}/archive-content.txt" |
|
|
|
done |
|
|
|
|
|
|
|
######################################## |
|
|
|
# extraction des pièces jointes |
|
|
|
"${eMailShrinker}" -s "5ki" -d "${TMP_DIR}/PJ" "${mbox}" > "${TMP_DIR}/PJ-name.txt" |
|
|
|
|
|
|
|
LOG " - ${BLUE}PJ-name: ${NC}" |
|
|
|
cat "${TMP_DIR}/PJ-name.txt" |
|
|
|
LOG |
|
|
|
|
|
|
|
######################################## |
|
|
|
# dépot des extractions dans jirafeau et récupération des codes |
|
|
|
cat "${TMP_DIR}/PJ-name.txt" | { |
|
|
|
while read ATTACH_TMP_NAME; do |
|
|
|
LOG " - ${BLUE}find ATTACH_TMP_NAME: (${ATTACH_TMP_NAME}) ${NC}" |
|
|
@ -138,13 +195,13 @@ LOG |
|
|
|
|
|
|
|
LOG " - ${GREEN}ATTACH_MODE: ${ATTACH_MODE}${NC}" |
|
|
|
|
|
|
|
######################################## |
|
|
|
# substitution des pièces jointes par les codes fournis par jirafeau |
|
|
|
cat "${TMP_DIR}/PJ-Keys.txt" | "${eMailShrinker}" ${ATTACH_MODE} -s "5ki" "${mbox}" "${TMP_DIR}/new-mbox" 2>> "${TTY}" |
|
|
|
|
|
|
|
|
|
|
|
######################################## |
|
|
|
# affichage de la structure à la fin |
|
|
|
LOG " - ${BLUE}new-mbox:${NC}" |
|
|
|
"${eMailShrinker}" -l "${TMP_DIR}/new-mbox" 2>> "${TTY}" |
|
|
|
|
|
|
|
#echo "${TMP_DIR}" |
|
|
|
#find "${TMP_DIR}" -type f -print |
|
|
|
|
|
|
|
echo -e "\nresul in ${TMP_DIR}/new-mbox" |
|
|
|