Initial commit.
authorFrancois Fleuret <francois@fleuret.org>
Sun, 21 Mar 2010 17:24:20 +0000 (18:24 +0100)
committerFrancois Fleuret <francois@fleuret.org>
Sun, 21 Mar 2010 17:24:20 +0000 (18:24 +0100)
gma.sh [new file with mode: 0755]

diff --git a/gma.sh b/gma.sh
new file mode 100755 (executable)
index 0000000..5625025
--- /dev/null
+++ b/gma.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+##################################################################
+# START_IP_HEADER                                                #
+#                                                                #
+# Written by Francois Fleuret                                    #
+# Contact <francois.fleuret@idiap.ch> 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