From 694570a454b33ff9c02fb13cf7221aa7718b95b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 21 Dec 2022 19:54:44 +0100 Subject: [PATCH] update filterTest.sh --- src/bash/filter.sh | 2 +- src/bash/filterTest.sh | 67 +++++++++++++++++++++++++----------------- src/cpp/Attachment.cpp | 1 + 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/bash/filter.sh b/src/bash/filter.sh index 80d2dc7..de62fe7 100755 --- a/src/bash/filter.sh +++ b/src/bash/filter.sh @@ -146,7 +146,7 @@ if ! cat > "${INSPECT_DIR}/in.$$"; then LOG_FIC "${RED}Cannot save mail to file${NC}" quitFilter "${EX_TEMPFAIL}" fi -dos2unix "${INSPECT_DIR}/in.$$" +dos2unix "${INSPECT_DIR}/in.$$" 2> /dev/null LOG_FIC "${NL}" \ " size: ${YELLOW}$(wc -c < "${INSPECT_DIR}/in.$$")${NC}" diff --git a/src/bash/filterTest.sh b/src/bash/filterTest.sh index 933b24e..d7560e0 100755 --- a/src/bash/filterTest.sh +++ b/src/bash/filterTest.sh @@ -2,7 +2,7 @@ PRG=$(basename $0) -ATTACH_MODE="-m BOTH" +ATTACH_MODE="-m FOOTER" BOLD='' RED='' @@ -17,6 +17,8 @@ NL=' TTY=$(tty) + +######################################## LOG () { echo "$1" >> "${TTY}" } @@ -28,43 +30,49 @@ usage () { [ "$#" -eq 1 ] || usage + +######################################## mbox=$(realpath $1) - - cd $(dirname $0) DOMAINNAME="$(cat domainname)" JIRAFEAU_URL="https://depot.${DOMAINNAME}" JIRAFEAU_LOCAL="${JIRAFEAU_URL}" -cd ../.. +TMP_DIR="$(mktemp)" -mkdir -p tmp -rm -fr tmp/PJ-name.txt tmp/PJ-Keys.txt tmp/PJ tmp/archive-content.txt tmp/url-to-refresh.txt tmp/new-mbox -echo -e "time: $(date "+%Y-%m-%d-%H:%M:%S")\nid: $(date +%s)" > "tmp/archive-content.txt" +eMailShrinker="$(realpath "./eMailShrinker")" +[ -x "${eMailShrinker}" ] || eMailShrinker="$(realpath "../../build/out/eMailShrinker")" + +jirafeauAPI="$(realpath "./jirafeauAPI")" +[ -x "${jirafeauAPI}" ] || jirafeauAPI="$(realpath "../../build/out/jirafeauAPI")" + +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" LOG " - ${BLUE}mbox: ${mbox}${NC}" -build/out/eMailShrinker -l "${mbox}" +"${eMailShrinker}" -l "${mbox}" LOG -build/out/eMailShrinker -u "${mbox}" > "tmp/url-to-refresh.txt" 2>> "${TTY}" +"${eMailShrinker}" -u "${mbox}" > "${TMP_DIR}/url-to-refresh.txt" 2>> "${TTY}" -cat "tmp/url-to-refresh.txt" | grep "${JIRAFEAU_URL}" | while read REMOTE_LINK; do +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 LOG " - ${BLUE}update ${REMOTE_REF}${NC}" - build/out/jirafeauAPI -f "${JIRAFEAU_LOCAL}" -t "month" update "${REMOTE_REF}" 2>> "${TTY}" + "${jirafeauAPI}" -f "${JIRAFEAU_LOCAL}" -t "month" update "${REMOTE_REF}" 2>> "${TTY}" LOG - echo "old: ${REMOTE_REF} ${REMOTE_KEY}" >> "tmp/archive-content.txt" + echo "old: ${REMOTE_REF} ${REMOTE_KEY}" >> "${TMP_DIR}/archive-content.txt" done -build/out/eMailShrinker -s "5ki" -d tmp/PJ "${mbox}" > "tmp/PJ-name.txt" +"${eMailShrinker}" -s "5ki" -d "${TMP_DIR}/PJ" "${mbox}" > "${TMP_DIR}/PJ-name.txt" LOG " - ${BLUE}PJ-name: ${NC}" -cat tmp/PJ-name.txt +cat "${TMP_DIR}/PJ-name.txt" LOG -cat "tmp/PJ-name.txt" | { +cat "${TMP_DIR}/PJ-name.txt" | { while read ATTACH_TMP_NAME; do LOG " - ${BLUE}find ATTACH_TMP_NAME: (${ATTACH_TMP_NAME}) ${NC}" if [ -d "${ATTACH_TMP_NAME}" ]; then @@ -79,36 +87,36 @@ cat "tmp/PJ-name.txt" | { LOG " - ${BLUE}find ${ATTACH_NAME} / (${ATTACH_CONTENT_TYPE}) / ${ATTACH_MEDIA} ${NC}" PASSWORD=$(apg -n 1 -m 12) PASSWORD_MD5=$(echo -n ${PASSWORD} | ${MD5_CMD} | cut -d \ -f 1) - build/out/jirafeauAPI -f "${JIRAFEAU_LOCAL}" -t "month" -s "1Gi" -c "${ATTACH_CONTENT_TYPE}" -n "${ATTACH_NAME}" send "${ATTACH_MEDIA}" "${PASSWORD}" 2>> "${TTY}" > "tmp/one.txt" + "${jirafeauAPI}" -f "${JIRAFEAU_LOCAL}" -t "month" -s "1Gi" -c "${ATTACH_CONTENT_TYPE}" -n "${ATTACH_NAME}" send "${ATTACH_MEDIA}" "${PASSWORD}" 2>> "${TTY}" > "${TMP_DIR}/one.txt" - cat "tmp/one.txt" | { + cat "${TMP_DIR}/one.txt" | { read JIR_TOKEN read JIR_CODE case "${JIR_TOKEN}" in "" | no | *Error* | \<* ) LOG " - ${RED}can't upload ${ATTACH_MEDIA} <${JIR_TOKEN}> <${JIR_CODE}>${NC}" - cat "tmp/one.txt" >> "${TTY}" + cat "${TMP_DIR}/one.txt" >> "${TTY}" echo "url:" ;; * ) 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/archive-content.txt" + echo "new: ${JIR_TOKEN} ${PASSWORD_MD5}" >> "${TMP_DIR}/archive-content.txt" ;; esac } done - NB_ATTACH=$(grep -e "^old: " -e "^new: " "tmp/archive-content.txt" | wc -l) + NB_ATTACH=$(grep -e "^old: " -e "^new: " "${TMP_DIR}/archive-content.txt" | wc -l) if [ "${NB_ATTACH}" -gt 1 ]; then PASSWORD=$(apg -n 1 -m 12) PASSWORD_MD5=$(echo -n ${PASSWORD} | ${MD5_CMD} | cut -d \ -f 1) - build/out/jirafeauAPI -f "${JIRAFEAU_LOCAL}" -t "month" -s "1Gi" -c "text/kaz_email_archive" -n "archive_content" send "tmp/archive-content.txt" "${PASSWORD}" > "tmp/one.txt" 2>> "${TTY}" - cat "tmp/one.txt" | { + "${jirafeauAPI}" -f "${JIRAFEAU_LOCAL}" -t "month" -s "1Gi" -c "text/kaz_email_archive" -n "archive_content" send "${TMP_DIR}/archive-content.txt" "${PASSWORD}" > "${TMP_DIR}/one.txt" 2>> "${TTY}" + cat "${TMP_DIR}/one.txt" | { read JIR_TOKEN read JIR_CODE case "${JIR_TOKEN}" in "" | no | *Error* | \<* ) - LOG " - ${RED}can't upload tmp/archive-content.txt${NC}" + LOG " - ${RED}can't upload ${TMP_DIR}/archive-content.txt${NC}" echo "arch: bad" ;; * ) @@ -121,16 +129,21 @@ cat "tmp/PJ-name.txt" | { LOG " - ${GREEN} no archive${NC}" echo "arch: none" fi -} > "tmp/PJ-Keys.txt" +} > "${TMP_DIR}/PJ-Keys.txt" LOG " - ${BLUE}PJ-Keys: ${NC}" -cat tmp/PJ-Keys.txt +cat "${TMP_DIR}/PJ-Keys.txt" LOG LOG " - ${GREEN}ATTACH_MODE: ${ATTACH_MODE}${NC}" -cat "tmp/PJ-Keys.txt" | build/out/eMailShrinker ${ATTACH_MODE} -s "5ki" "${mbox}" "tmp/new-mbox" 2>> "${TTY}" +cat "${TMP_DIR}/PJ-Keys.txt" | "${eMailShrinker}" ${ATTACH_MODE} -s "5ki" "${mbox}" "${TMP_DIR}/new-mbox" 2>> "${TTY}" LOG " - ${BLUE}new-mbox:${NC}" -build/out/eMailShrinker -l "tmp/new-mbox" 2>> "${TTY}" +"${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" diff --git a/src/cpp/Attachment.cpp b/src/cpp/Attachment.cpp index 069ac81..1a2c755 100644 --- a/src/cpp/Attachment.cpp +++ b/src/cpp/Attachment.cpp @@ -157,6 +157,7 @@ Attachment::getSection (const string &content, const string &beginTag, const str string::size_type stopPos = caseInsensitiveFind (content, endTag, startPos); LOG_BUG (stopPos == string::npos, break, "eMailShrinker: bug A3: " << endTag << " not found! at: " << startPos); + // LOG_BUG (stopPos == string::npos, break, "eMailShrinker: bug A3: " << endTag << " not found! at: " << startPos << endl << content); LOG ("start: " << startPos << " stop: " << stopPos); LOG_BUG (startPos == stopPos, /**/, "eMailShrinker: bug A4: " << endTag << " without " << beginTag << " at: " << startPos);