From 3bf7eb477418b4f21788204c083fdcb6927ce3d4 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sun, 21 Mar 2010 18:24:20 +0100 Subject: [PATCH] Initial commit. --- gma.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 gma.sh 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 -- 2.39.5