commit efd12c62b5dca94a26b10f1160c99ab370cdeda8 Author: Sergio Durigan Junior Date: Sun Dec 29 20:09:00 2024 -0500 Initial commit diff --git a/spam-ham-learn b/spam-ham-learn new file mode 100644 index 0000000..9ac6c9a --- /dev/null +++ b/spam-ham-learn @@ -0,0 +1,48 @@ +#!/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