#!/usr/bin/env bash BDIR="/var/spool/vmail_imapsieve_copy" SALEARN=$(which sa-learn) [[ -x ${SALEARN} ]] || exit 1 remove_files () { WHAT=$1 #echo "WHAT=${WHAT} EXIT=${2}" if [[ $2 -eq 0 ]]; then for file in $(ls ${BDIR}/${WHAT}/*.eml 2>/dev/null); do F=$(basename ${file}) rm ${BDIR}/${WHAT}/${F} done fi } learn () { WHAT=$1 ls ${WHAT}/*.eml 1>/dev/null 2>&1 if [[ $? -eq 0 ]]; then ${SALEARN} --${WHAT} $BDIR/${WHAT}/*.eml remove_files ${WHAT} $? fi } #We have stuff to download, put it in spool cd ${BDIR} learn spam learn ham