X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=gma.sh;h=d914893960534fbae5ebe290dca5e70dcf4d4ee2;hb=0c7aaabde9bf206dd017f468bf5af86e2efb22dd;hp=640c7f3cb4c16955526b0ed771903a96b3d70dff;hpb=c33caf969cac88b0b60cbec899ff1f3f24e39a31;p=scripts.git diff --git a/gma.sh b/gma.sh index 640c7f3..d914893 100755 --- a/gma.sh +++ b/gma.sh @@ -20,16 +20,23 @@ set -e function usage () { - echo "gma.sh [--body] [--from|--to|--fromto] []" + echo "gma.sh [--body] [--nospam] [--subject|--from|--to|--fromto|--sender] []" } RESULT_MBOX="/tmp/gma" +KEEP_SPAM=1 if [[ -z "${MAIL_ARCHIVE_DIR}" ]]; then echo "Undefined \$MAIL_ARCHIVE_DIR" >&2 exit 1 fi +if [[ $(which ionice) ]]; then + IONICE="ionice -c3" +else + IONICE="" +fi + HEADER_ONLY="-H" while [[ $1 ]]; do @@ -45,8 +52,12 @@ while [[ $1 ]]; do HEADER_ONLY="" ;; - "--keepspam") - KEEP_SPAM=1 + "--intense") + IONICE="" + ;; + + "--nospam") + KEEP_SPAM=0 ;; "--from") @@ -61,8 +72,19 @@ while [[ $1 ]]; do RE_PREFIX="^(From|To):.*" ;; + "--sender") + RE_PREFIX="^Sender:.*" + ;; + + "--subject") + RE_PREFIX="^Subject:.*" + ;; + *) if [[ ${PATTERN} ]]; then + # If we already have the pattern to match in the + # message, get the new argument as a pattern for the + # filename if [[ ${FILE_PATTERN} ]]; then usage exit 1 @@ -84,7 +106,7 @@ if [[ -z "${PATTERN}" ]]; then fi [[ ${FILE_PATTERN} ]] || FILE_PATTERN="${MAIL_ARCHIVE_DIR}/*/*/*" -[[ ${SIZE_FILE_PATTERN} ]] || SIZE_FILE_PATTERN="${MAIL_ARCHIVE_DIR}/" +[[ ${SIZE_FILE_PATTERN} ]] || SIZE_FILE_PATTERN="${MAIL_ARCHIVE_DIR}" SIZE=$(\dus ${SIZE_FILE_PATTERN} | cut -f 1 -d" ") @@ -92,15 +114,15 @@ echo "Looking for ${RE_PREFIX}${PATTERN}" echo " in ${FILE_PATTERN}" echo " writing result in ${RESULT_MBOX}" -if [[ ${KEEP_SPAM} ]]; then +if [[ ${KEEP_SPAM} == "1" ]]; then - cat ${FILE_PATTERN} \ + ${IONICE} cat ${FILE_PATTERN} \ | pv -s ${SIZE} -p -t -e - \ | mboxgrep ${HEADER_ONLY} -i "${RE_PREFIX}${PATTERN}" > ${RESULT_MBOX} else - cat ${FILE_PATTERN} \ + ${IONICE} cat ${FILE_PATTERN} \ | pv -s ${SIZE} -p -t -e - \ | mboxgrep ${HEADER_ONLY} -i "${RE_PREFIX}${PATTERN}" \ | mboxgrep ${HEADER_ONLY} -v '^Subject:.*SPAM' > ${RESULT_MBOX}