#!/usr/bin/bash # Useful directories. readonly MAILDIR="${HOME}/Maildir" readonly SPAMDIR="${MAILDIR}/Spam" readonly HAMDIR="${MAILDIR}/Ham" # The spam/ham found are saved for future reference. readonly SAVE_SPAM_DIR="${HOME}/spamassassin/spam" readonly SAVE_HAM_DIR="${HOME}/spamassassin/ham" # The minimum age (in days) of spam to be processed. readonly SPAM_MIN_AGE=3 # "--force" flag. FORCE="false" learn_spam() { local tmpfile=$(mktemp) local findargs="" if [ "${FORCE}" = "false" ]; then findargs=" -ctime +${SPAM_MIN_AGE} " fi find "${SPAMDIR}/cur" "${SPAMDIR}/new" -type f "${findargs}" | while read -r msg; do printf "%s\n" "${msg}" >> "${tmpfile}" done /usr/bin/sa-learn -f "${tmpfile}" } learn_ham() { } while [ -n "${1}" ]; do case "${1}" in -f|--force) FORCE="true" ;; esac shift done learn_spam learn_ham