Compare commits

...

6 Commits

Author SHA1 Message Date
fab
94659482cf Mise à jour de 'src/bash/filter.sh' 2023-10-23 12:22:39 +02:00
fab
3ac1bec5d9 Mise à jour de 'src/bash/filter.sh' 2023-10-21 02:07:06 +02:00
fab
4c61cf5c81 Mise à jour de 'src/bash/filter.sh' 2023-10-21 01:21:25 +02:00
fab
aea24bbe89 Mise à jour de 'src/bash/filter.sh' 2023-10-20 22:51:11 +02:00
bd3a2bc0c8 update var name 2023-10-20 19:29:20 +02:00
b0e3c5b390 test skip 2023-10-20 19:25:26 +02:00

View File

@ -72,18 +72,22 @@ MAX_FINAL_SIZE=2097152 # 2Mi
ARCHIVE_TITLE="archive_content"
ARCHIVE_MIME="text/kaz_email_archive"
FILE_SKIP_DOMAINS="/tmp/docker-mailserver/file_domaines_non_depollues.txt"
#on enlève les commentaires et les lignes vides
SKIP_DOMAINS=`grep -Ev '^#|^[[:space:]]*$' $FILE_SKIP_DOMAINS`
KEEP_FAILED=true
DEBUG=
DEBUG=true
#################### FONCTIONS ############################################
BOLD=''
RED=''
GREEN=''
YELLOW=''
BLUE=''
MAGENTA=''
CYAN=''
NC='' # No Color
BOLD='[1m'
RED='[0;31m'
GREEN='[0;32m'
YELLOW='[0;33m'
BLUE='[0;34m'
MAGENTA='[0;35m'
CYAN='[0;36m'
NC='[0m' # No Color
NL='
'
@ -137,6 +141,26 @@ curlJirafeauSend () {
echo "${OUTPUT}"
}
# Définir une fonction pour vérifier si le domaine d'un email est dans la liste SKIP_DOMAINS
function check_skip_domains() {
local SKIP_DOMAINS="$1"
local LIST_EMAILS="$2"
for email in $LIST_EMAILS; do
# Extraire le domaine de l'email (partie après le "@")
local domain="${email##*@}"
# Utiliser grep pour vérifier si le domaine est dans la liste des domaines à sauter
if echo "$SKIP_DOMAINS" | grep -q -w "$domain"; then
echo "yes"
return
fi
done
# Si aucun domaine n'a été trouvé, retourner "no"
echo "no"
}
#################### MAIN #################################################
echo "${NL}${BLUE}$(date +%d-%m-%Y-%H-%M-%S)${NC} : ${GREEN}######################################## filter start (log in ${TMP_LOG})${NC}" >> "${FIC_LOG}"
LOG_FIC "${GREEN}######################################## ${TMP_LOG} ${NC}"
@ -145,6 +169,14 @@ if ! mkdir -p "${MAILS}"; then
LOG_FIC "${RED}Can't mkdir ${MAILS} ${NC}"
quitFilter "${EX_UNAVAILABLE}"
fi
#$@ contient le sender et les destinataires
#format "-f sender -- dest1 [...dest(i)] "
LIST_EMAILS=$(echo $@)
#on nettoie
LIST_EMAILS=$(sed 's/-f//g' <<< $LIST_EMAILS)
LIST_EMAILS=$(sed 's/--//g' <<< $LIST_EMAILS)
MAIL_SOURCE=$(echo $@ | awk 'BEGIN{FS=" "} {print $2}')
DATE_TEMPS=$(date "+%Y-%m-%d-%H:%M:%S")
REP_PIECE_JOINTE="${MAILS}/${DATE_TEMPS}_${MAIL_SOURCE}_$$"
@ -157,11 +189,11 @@ PERIOD=$(curl "${JIRAFEAU_LOCAL}/a.php?p=${MAIL_SOURCE}" 2>/dev/null )
[[ "${PERIOD}" =~ ^(minute|hour|day|week|month|quarter)$ ]] || PERIOD="${DEFAULT_PERIOD}"
LOG_FIC "${NL}" \
" MAIL_SOURCE : ${YELLOW}${MAIL_SOURCE}${NC}${NL}" \
" DATE_TEMPS : ${YELLOW}${DATE_TEMPS=}${NC}${NL}" \
" MODE : ${YELLOW}${MODE}${NC}${NL}" \
" TRACK : ${YELLOW}${TRACK}${NC}${NL}" \
" PERIOD : ${YELLOW}${PERIOD}${NC}${NL}"
" MAIL_SOURCE : ${YELLOW}${MAIL_SOURCE}${NC}${NL}" \
" DATE_TEMPS : ${YELLOW}${DATE_TEMPS=}${NC}${NL}" \
" MODE : ${YELLOW}${MODE}${NC}${NL}" \
" TRACK : ${YELLOW}${TRACK}${NC}${NL}" \
" PERIOD : ${YELLOW}${PERIOD}${NC}${NL}"
if ! cd "${INSPECT_DIR}"; then
echo "${INSPECT_DIR} does not exist"
@ -194,12 +226,19 @@ mkdir -p "${REP_PIECE_JOINTE}/"
>"${OLD_LINKS}"
>"${ARCHIVE_CONTENT}"
if [ "${MODE}" = "none" ]; then
if [ "${MODE}" = "none"]; then
LOG_FIC " - ${GREEN}send without change (MODE=none)${NC}"
${SENDMAIL} "$@" < "${INSPECT_DIR}/in.$$"
quitFilter 0
fi
if [ "$(check_skip_domains "$SKIP_DOMAINS" "$LIST_EMAILS")" = "yes" ]; then
LOG_FIC " - ${GREEN}send without change (skip domain)${NC}"
${SENDMAIL} "$@" < "${INSPECT_DIR}/in.$$"
quitFilter 0
fi
# 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}"
@ -322,3 +361,4 @@ fi
quitFilter 0
##########################################################################