Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ########################################################################
- # Author: Henning Hollermann, laclaro@mail.com #
- # #
- # This program is free software: you can redistribute it and/or #
- # modify it under the terms of the GNU General Public License #
- # as published by the Free Software Foundation, either version 3 #
- # of the License, or (at your option) any later version #
- # #
- # 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://gnu.org/licenses/>. #
- # #
- # This is a bash-script to regularly learn new tokens from mail #
- # using spamassassins sa-learn on specified folders. #
- # #
- ########################################################################
- # mail spool
- MAILSPOOL=/var/spool/imap/domain/d/domain.com
- SPAM=$(find $MAILSPOOL/ -name "*Junk*" -o -name "*Spam*" |grep -v DELETED)
- HAM="$(find $MAILSPOOL/ -name *Ham* |grep -v DELETED)"
- MOREHAM="$(find $MAILSPOOL/ -name "*Family*" -o -name "*Archive*" |grep -v DELETED)"
- MORESPAM=""
- # function sa_learn to learn about ham or spam from given directories
- # $1 keywords "spam" or "ham"
- # $2-$X directories to examine
- sa_learn() {
- case $1 in
- ham) TYPE="ham";;
- spam) TYPE="spam";;
- *) exit 1;;
- esac;
- # drop ham or spam option
- shift;
- # use linebreak, not whitespace as for-loop-separator
- IFS=$'\012';
- # learn from given directories
- for dir in $*; do
- if [ -d "$dir" ]; then
- echo "Learning from $dir what $TYPE looks like"
- sa-learn --$TYPE "$dir"/[0-9]*;
- fi
- done
- # restore separator
- IFS=$' ';
- }
- # learn about spam
- sa_learn "spam" "$SPAM"
- # learn about ham
- sa_learn "ham" "$HAM"
- # monthly on the 16th learn about more ham and spam
- if [ "$(date +%d)" = 16 ]; then
- sa_learn "spam" "$MORESPAM"
- sa_learn "ham" "$MOREHAM"
- fi
Add Comment
Please, Sign In to add comment