From efd12c62b5dca94a26b10f1160c99ab370cdeda8 Mon Sep 17 00:00:00 2001 From: Sergio Durigan Junior Date: Sun, 29 Dec 2024 20:09:00 -0500 Subject: [PATCH] Initial commit --- spam-ham-learn | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 spam-ham-learn 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