3 #########################################################################
4 # This program is free software: you can redistribute it and/or modify #
5 # it under the terms of the version 3 of the GNU General Public License #
6 # as published by the Free Software Foundation. #
8 # This program is distributed in the hope that it will be useful, but #
9 # WITHOUT ANY WARRANTY; without even the implied warranty of #
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
11 # General Public License for more details. #
13 # You should have received a copy of the GNU General Public License #
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
16 # Written by and Copyright (C) Francois Fleuret #
17 # Contact <francois.fleuret@idiap.ch> for comments & bug reports #
18 #########################################################################
23 echo "gma.sh [--body] [--keepspam] [--subject|--from|--to|--fromto] <pattern> [<year>]"
26 RESULT_MBOX="/tmp/gma"
28 if [[ -z "${MAIL_ARCHIVE_DIR}" ]]; then
29 echo "Undefined \$MAIL_ARCHIVE_DIR" >&2
33 if [[ $(which ionice) ]]; then
71 RE_PREFIX="^(From|To):.*"
75 RE_PREFIX="^Subject:.*"
79 if [[ ${PATTERN} ]]; then
80 # If we already have the pattern to match in the
81 # message, get the new argument as a pattern for the
83 if [[ ${FILE_PATTERN} ]]; then
87 FILE_PATTERN="${MAIL_ARCHIVE_DIR}/${1}/*/*"
88 SIZE_FILE_PATTERN="${MAIL_ARCHIVE_DIR}/${1}"
98 if [[ -z "${PATTERN}" ]]; then
103 [[ ${FILE_PATTERN} ]] || FILE_PATTERN="${MAIL_ARCHIVE_DIR}/*/*/*"
104 [[ ${SIZE_FILE_PATTERN} ]] || SIZE_FILE_PATTERN="${MAIL_ARCHIVE_DIR}"
106 SIZE=$(\dus ${SIZE_FILE_PATTERN} | cut -f 1 -d" ")
108 echo "Looking for ${RE_PREFIX}${PATTERN}"
109 echo " in ${FILE_PATTERN}"
110 echo " writing result in ${RESULT_MBOX}"
112 if [[ ${KEEP_SPAM} ]]; then
114 ${IONICE} cat ${FILE_PATTERN} \
115 | pv -s ${SIZE} -p -t -e - \
116 | mboxgrep ${HEADER_ONLY} -i "${RE_PREFIX}${PATTERN}" > ${RESULT_MBOX}
120 ${IONICE} cat ${FILE_PATTERN} \
121 | pv -s ${SIZE} -p -t -e - \
122 | mboxgrep ${HEADER_ONLY} -i "${RE_PREFIX}${PATTERN}" \
123 | mboxgrep ${HEADER_ONLY} -v '^Subject:.*SPAM' > ${RESULT_MBOX}
127 echo "Found "$(grep ^"From " ${RESULT_MBOX} | wc -l)" messages."