fix TMPFAIL
This commit is contained in:
parent
0d5609501a
commit
8cd159aacb
@ -80,11 +80,19 @@ LOG_FIC() {
|
||||
echo "${BLUE}$(date +%d-%m-%Y-%H-%M-%S)${NC} : $*" >> "${FIC_LOG}"
|
||||
}
|
||||
|
||||
quitFilter () {
|
||||
LOG_FIC "${GREEN}######################################## filter stop${NC}"
|
||||
exit $1
|
||||
}
|
||||
|
||||
#################### MAIN #################################################
|
||||
echo "${NL}" >> "${FIC_LOG}"
|
||||
LOG_FIC "${GREEN}######################################## filter start${NC}"
|
||||
|
||||
mkdir -p "${MAILS}" || { LOG_FIC "${RED}impossible de creer ce dossier${NC}"; exit "${EX_UNAVAILABLE}"; }
|
||||
if ! mkdir -p "${MAILS}"; then
|
||||
LOG_FIC "${RED}Can't mkdir ${MAILS} ${NC}"
|
||||
quitFilter "${EX_UNAVAILABLE}"
|
||||
fi
|
||||
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}_$$"
|
||||
@ -101,7 +109,10 @@ LOG_FIC "\n" \
|
||||
" PERIOD : ${YELLOW}${PERIOD}${NC}\n" \
|
||||
" JIRAFEAU_TIME: ${YELLOW}${JIRAFEAU_TIME}${NC}"
|
||||
|
||||
cd "${INSPECT_DIR}" || { echo "${INSPECT_DIR} does not exist"; exit "${EX_TEMPFAIL}"; }
|
||||
if ! cd "${INSPECT_DIR}"; then
|
||||
echo "${INSPECT_DIR} does not exist"
|
||||
quitFilter "${EX_TEMPFAIL}"
|
||||
fi
|
||||
|
||||
# lien renvoyé par le téléverssement
|
||||
ONE_LINK="${REP_PIECE_JOINTE}/one.txt"
|
||||
@ -109,11 +120,18 @@ ONE_LINK="${REP_PIECE_JOINTE}/one.txt"
|
||||
OLD_LINKS="${REP_PIECE_JOINTE}/url-to-refresh.txt"
|
||||
# contenu de l'archive
|
||||
ARCHIVE_CONTENT="${REP_PIECE_JOINTE}/archive-content.txt"
|
||||
# create if error
|
||||
JIRAFEAU_ERROR="${REP_PIECE_JOINTE}/jirafeau-error.txt"
|
||||
|
||||
# Clean up when done or when aborting.
|
||||
trap "rm -rf in.$$ in.$$.altered ${REP_PIECE_JOINTE}" 0 1 2 3 15
|
||||
|
||||
cat > "in.$$" || { LOG_FIC "${RED}Cannot save mail to file${NC}"; exit "${EX_TEMPFAIL}"; }
|
||||
if ! cat > "in.$$"; then
|
||||
LOG_FIC "${RED}Cannot save mail to file${NC}"
|
||||
quitFilter "${EX_TEMPFAIL}"
|
||||
fi
|
||||
LOG_FIC "\n" \
|
||||
" size: ${YELLOW}$(wc -c < "${INSPECT_DIR}/in.$$")${NC}"
|
||||
# XXX trace
|
||||
# cp "${INSPECT_DIR}/in.$$" "${INSPECT_DIR}/in.$$.bak"
|
||||
|
||||
@ -151,6 +169,7 @@ LOG_FIC "${CYAN}${SHRINK_CMD} -s ${MAX_KEEP_IN_MAIL} -d ${REP_PIECE_JOINTE} ${IN
|
||||
ATTACH_NAME=$(grep "^Name: " "${ATTACH_TMP_NAME}/meta" | cut -c 7- )
|
||||
ATTACH_CONTENT_TYPE=$(grep "^Content-Type: " "${ATTACH_TMP_NAME}/meta" | cut -c 15- )
|
||||
else
|
||||
LOG_FIC " - ${RED}no ATTACH_TMP_NAME (${ATTACH_TMP_NAME}) ${NC}"
|
||||
# XXX error
|
||||
continue
|
||||
fi
|
||||
@ -164,9 +183,11 @@ LOG_FIC "${CYAN}${SHRINK_CMD} -s ${MAX_KEEP_IN_MAIL} -d ${REP_PIECE_JOINTE} ${IN
|
||||
read JIR_CODE
|
||||
LOG_FIC " - return code ${YELLOW}${JIR_TOKEN}${NC} / ${YELLOW}${JIR_CODE}${NC}"
|
||||
case "${JIR_TOKEN}" in
|
||||
"" | no | *Error* | \<* )
|
||||
LOG_FIC " - ${RED}impossible de televerser ${ATTACH_TMP_FILE} (${JIR_TOKEN}), il ne sera pas remplace dans le message${NC}"
|
||||
"" | no | *Error* | \<* )
|
||||
LOG_FIC " - ${RED}Can't upload <${ATTACH_NAME}> <${ATTACH_CONTENT_TYPE}> <$(wc -c < "${ATTACH_MEDIA}")> (${JIR_TOKEN}). It will be not change in e-mail.${NC}"
|
||||
echo "new:"
|
||||
cp "${INSPECT_DIR}/in.$$" "${INSPECT_DIR}/in.$$.bak"
|
||||
echo "UPLOAD_FAIL" >> "${JIRAFEAU_ERROR}"
|
||||
;;
|
||||
* )
|
||||
LOG_FIC " - change by link ${YELLOW}${JIRAFEAU_URL}/f.php?d=1&h=${JIR_TOKEN}&k=${PASSWORD_MD5}${NC}"
|
||||
@ -175,8 +196,6 @@ LOG_FIC "${CYAN}${SHRINK_CMD} -s ${MAX_KEEP_IN_MAIL} -d ${REP_PIECE_JOINTE} ${IN
|
||||
;;
|
||||
esac
|
||||
}
|
||||
LOG_FIC " - remove extraction file ${ATTACH_TMP_FILE}"
|
||||
rm -f "${ATTACH_TMP_FILE}"
|
||||
done
|
||||
# Création de l'archive
|
||||
NB_ATTACH=$(grep -e "^old: " -e "^new: " "${ARCHIVE_CONTENT}" | wc -l)
|
||||
@ -197,6 +216,7 @@ LOG_FIC "${CYAN}${SHRINK_CMD} -s ${MAX_KEEP_IN_MAIL} -d ${REP_PIECE_JOINTE} ${IN
|
||||
"" | no | *Error* | \<* )
|
||||
LOG_FIC " - ${RED}can't upload archive (${JIR_TOKEN}), substitution couldn't be done${NC}"
|
||||
echo "arch: bad"
|
||||
echo "ARCHIVE_FAIL" >> "${JIRAFEAU_ERROR}"
|
||||
;;
|
||||
* )
|
||||
LOG_FIC " - add archive ${YELLOW}${JIRAFEAU_URL}/a.php?g=${JIR_TOKEN}~${PASSWORD_MD5}${NC}"
|
||||
@ -215,13 +235,18 @@ LOG_FIC "${CYAN}${SHRINK_CMD} -s ${MAX_KEEP_IN_MAIL} -d ${REP_PIECE_JOINTE} ${IN
|
||||
# XXX trace
|
||||
# cp "${INSPECT_DIR}/in.$$" "${INSPECT_DIR}/in.$$.altered" /var/mail/tmp/
|
||||
|
||||
if [ -s "${JIRAFEAU_ERROR}" ]; then
|
||||
LOG_FIC " - ${RED}upload fail${NC}"
|
||||
quitFilter "${EX_TEMPFAIL}"
|
||||
fi
|
||||
|
||||
# Etape choix de modification du message d'origine
|
||||
if [ "$(wc -l < "${ARCHIVE_CONTENT}")" -ge 3 ]; then
|
||||
# verification de taille finale
|
||||
actualSize=$(wc -c < "${INSPECT_DIR}/in.$$.altered")
|
||||
if [ ${actualSize} -ge $MAX_FINAL_SIZE ]; then
|
||||
LOG_FIC " - ${RED}too big even after diet ${INSPECT_DIR}/in.$$.altered (${actualSize})${NC}"
|
||||
exit "${EX_TOO_LARGE}";
|
||||
quitFilter "${EX_TOO_LARGE}"
|
||||
fi
|
||||
LOG_FIC " - ${GREEN}send with : ${SENDMAIL} $@ ${INSPECT_DIR}/in.$$.altered ${NC}"
|
||||
${SENDMAIL} "$@" < "${INSPECT_DIR}/in.$$.altered"
|
||||
@ -230,13 +255,12 @@ else
|
||||
actualSize=$(wc -c < "${INSPECT_DIR}/in.$$")
|
||||
if [ ${actualSize} -ge $MAX_FINAL_SIZE ]; then
|
||||
LOG_FIC " - ${RED}too big without diet ${INSPECT_DIR}/in.$$ (${actualSize}) ${NC}"
|
||||
exit "${EX_TOO_LARGE}";
|
||||
quitFilter "${EX_TOO_LARGE}"
|
||||
fi
|
||||
LOG_FIC " - ${GREEN}send without attach file${NC}"
|
||||
${SENDMAIL} "$@" < "in.$$"
|
||||
fi
|
||||
|
||||
LOG_FIC "${GREEN}######################################## filter stop${NC}"
|
||||
exit 0
|
||||
quitFilter 0
|
||||
|
||||
##########################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user