Guest User

sa-learn-cronjob

a guest
Feb 22nd, 2014
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.58 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ########################################################################
  4. #    Author: Henning Hollermann, laclaro@mail.com                      #
  5. #                                                                      #
  6. #    This program is free software: you can redistribute it and/or     #
  7. #    modify it under the terms of the GNU General Public License       #
  8. #    as published by the Free Software Foundation, either version 3    #
  9. #    of the License, or (at your option) any later version             #
  10. #                                                                      #
  11. #    This program is distributed in the hope that it will be useful,   #
  12. #    but WITHOUT ANY WARRANTY; without even the implied warranty of    #
  13. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the      #
  14. #    GNU General Public License for more details.                      #
  15. #                                                                      #
  16. #    You should have received a copy of the GNU General Public License #
  17. #    along with this program. If not, see <http://gnu.org/licenses/>.  #
  18. #                                                                      #
  19. #    This is a bash-script to regularly learn new tokens from mail     #
  20. #    using spamassassins sa-learn on specified folders.                #
  21. #                                                                      #
  22. ########################################################################
  23.  
  24. # mail spool
  25. MAILSPOOL=/var/spool/imap/domain/d/domain.com
  26. SPAM=$(find $MAILSPOOL/ -name "*Junk*" -o -name "*Spam*" |grep -v DELETED)
  27. HAM="$(find $MAILSPOOL/ -name *Ham* |grep -v DELETED)"
  28. MOREHAM="$(find $MAILSPOOL/ -name "*Family*" -o -name "*Archive*" |grep -v DELETED)"
  29. MORESPAM=""
  30.  
  31. # function sa_learn to learn about ham or spam from given directories
  32. # $1    keywords "spam" or "ham"
  33. # $2-$X directories to examine
  34. sa_learn() {
  35.   case $1 in
  36.       ham)  TYPE="ham";;
  37.       spam) TYPE="spam";;
  38.       *)    exit 1;;
  39.   esac;
  40.   # drop ham or spam option
  41.   shift;
  42.   # use linebreak, not whitespace as for-loop-separator
  43.   IFS=$'\012';
  44.   # learn from given directories
  45.   for dir in $*; do
  46.       if [ -d "$dir" ]; then
  47.           echo "Learning from $dir what $TYPE looks like"
  48.           sa-learn --$TYPE "$dir"/[0-9]*;
  49.       fi
  50.   done
  51.   # restore separator
  52.   IFS=$' ';
  53. }
  54.  
  55. # learn about spam
  56. sa_learn "spam" "$SPAM"
  57. # learn about ham
  58. sa_learn "ham" "$HAM"
  59.  
  60. # monthly on the 16th learn about more ham and spam
  61. if [ "$(date +%d)" = 16 ]; then
  62.     sa_learn "spam" "$MORESPAM"
  63.     sa_learn "ham"  "$MOREHAM"
  64. fi
Add Comment
Please, Sign In to add comment