#!/bin/sh
set -eux

# shellcheck disable=SC2044
for user in $(find /var/mail -maxdepth 1 -mindepth 1 -type d)
do
    sa-learn --spam --mbox --forget "$user/Junk" || true
    find "$user" \
        -maxdepth 1 \
        -type f \
        -mtime -2 \
        \! -name Junk \
        \! -name Inbox \
        \! -name Sent \
        -execdir sa-learn --ham --mbox --forget "{}" \;
done

sa-learn --sync
sa-learn --backup > /var/backups/sa-learn/backup.txt
