From: Francois Fleuret Date: Sun, 21 Mar 2010 17:24:20 +0000 (+0100) Subject: Initial commit. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=3bf7eb477418b4f21788204c083fdcb6927ce3d4;p=scripts.git Initial commit. --- diff --git a/gma.sh b/gma.sh new file mode 100755 index 0000000..5625025 --- /dev/null +++ b/gma.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +################################################################## +# START_IP_HEADER # +# # +# Written by Francois Fleuret # +# Contact for comments & bug reports # +# # +# END_IP_HEADER # +################################################################## + +set -e + +RESULT_MBOX="/tmp/gma" + +if [[ -z "${MAIL_ARCHIVE_DIR}" ]]; then + echo "Undefined \$MAIL_ARCHIVE_DIR" >&2 + exit 1 +fi + +if [[ $1 ]]; then + + PATTERN=$1 + + if [[ -z "${PATTERN}" ]]; then + echo "No pattern." >&2 + exit 1 + fi + + if [[ $2 ]]; then + FILE_PATTERN="${MAIL_ARCHIVE_DIR}/${2}/*/*gz" + SIZE=$(\dus ${MAIL_ARCHIVE_DIR}/${2} | cut -f 1 -d" ") + else + FILE_PATTERN="${MAIL_ARCHIVE_DIR}/*/*/*gz" + SIZE=$(\dus ${MAIL_ARCHIVE_DIR}/ | cut -f 1 -d" ") + fi + + echo "Looking for ${PATTERN}" + echo " in ${FILE_PATTERN}" + echo " writing result in ${RESULT_MBOX}" + + cat ${FILE_PATTERN} \ + | pv -s ${SIZE} -p -t -e - \ + | zcat \ + | mboxgrep -i "$1" \ + | mboxgrep -v '^Subject:.*SPAM' > ${RESULT_MBOX} + echo "Found "$(grep ^"From " ${RESULT_MBOX} | wc -l)" messages." + +else + + rm -i ${RESULT_MBOX} + +fi