Cosmetics.
[scripts.git] / gma.sh
diff --git a/gma.sh b/gma.sh
index 5625025..6d25f0f 100755 (executable)
--- a/gma.sh
+++ b/gma.sh
@@ -1,13 +1,21 @@
 #!/bin/bash
 
-##################################################################
-# START_IP_HEADER                                                #
-#                                                                #
-# Written by Francois Fleuret                                    #
-# Contact <francois.fleuret@idiap.ch> for comments & bug reports #
-#                                                                #
-# END_IP_HEADER                                                  #
-##################################################################
+#########################################################################
+# This program is free software: you can redistribute it and/or modify  #
+# it under the terms of the version 3 of the GNU General Public License #
+# as published by the Free Software Foundation.                         #
+#                                                                       #
+# This program is distributed in the hope that it will be useful, but   #
+# WITHOUT ANY WARRANTY; without even the implied warranty of            #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      #
+# General Public License for more details.                              #
+#                                                                       #
+# You should have received a copy of the GNU General Public License     #
+# along with this program. If not, see <http://www.gnu.org/licenses/>.  #
+#                                                                       #
+# Written by and Copyright (C) Francois Fleuret                         #
+# Contact <francois.fleuret@idiap.ch> for comments & bug reports        #
+#########################################################################
 
 set -e
 
@@ -27,11 +35,20 @@ if [[ $1 ]]; then
         exit 1
     fi
 
-    if [[ $2 ]]; then
-        FILE_PATTERN="${MAIL_ARCHIVE_DIR}/${2}/*/*gz"
-        SIZE=$(\dus ${MAIL_ARCHIVE_DIR}/${2} | cut -f 1 -d" ")
+    shift
+
+    HEADER_ONLY="-H"
+
+    if [[ $1 == "--body" ]]; then
+        HEADER_ONLY=""
+        shift
+    fi
+
+    if [[ $1 ]]; then
+        FILE_PATTERN="${MAIL_ARCHIVE_DIR}/${1}/*/*"
+        SIZE=$(\dus ${MAIL_ARCHIVE_DIR}/${1} | cut -f 1 -d" ")
     else
-        FILE_PATTERN="${MAIL_ARCHIVE_DIR}/*/*/*gz"
+        FILE_PATTERN="${MAIL_ARCHIVE_DIR}/*/*/*"
         SIZE=$(\dus ${MAIL_ARCHIVE_DIR}/ | cut -f 1 -d" ")
     fi
 
@@ -41,9 +58,8 @@ if [[ $1 ]]; then
 
     cat ${FILE_PATTERN} \
         | pv -s ${SIZE} -p -t -e - \
-        | zcat \
-        | mboxgrep -i "$1" \
-        | mboxgrep -v '^Subject:.*SPAM' > ${RESULT_MBOX}
+        | mboxgrep ${HEADER_ONLY} -i "${PATTERN}" \
+        | mboxgrep ${HEADER_ONLY} -v '^Subject:.*SPAM' > ${RESULT_MBOX}
     echo "Found "$(grep ^"From " ${RESULT_MBOX} | wc -l)" messages."
 
 else