Learn Ham
As i was bothered by the Spam-Handling on some Mails from an Mailinglist which always landed in my Junk-Folder i finally got around to create this little Function.
The Function as is will search for a Folder named "Non-Junk" and then try to "learn" all containing Messages. Don't know if it would be possible to mark those messages as Unread or something like it to make the User aware that those Messages are now for all intents and purposes scanned by rspamc and could be moved away to wherever you want it.
# Learn Ham from a specific Folder
_grom_learn_ham() {
local FLD MBX QRY USR ID MID
_grom_users="${_grom_users:=$(grom_users)}"
if [[ "$#" -eq 0 ]]; then
for USR in $_grom_users; do
_grom_learn_ham "${USR}"
done
elif [[ "$#" -eq 1 ]]; then
if [[ "$_grom_users" =~ "${1}" ]]; then
USR="${1}"
FLD="$(_exmdb_folders_long ${USR} |awk -F';' '/;Non-Junk/ {print $1}')"
if ! test -z $FLD; then
printf 'Folder Non-Junk found for User: %s with Folder-ID: %s\n' "${USR}" "${FLD}" |systemd-cat -t grom_learn_ham
MBX="$(_grom_query_maildir ${USR})"
QRY="select message_id,mid_string from messages where parent_fid=${FLD};"
sqlite3 -tabs -noheader "${MBX}/exmdb/exchange.sqlite3" "${QRY}"| while read -r ID MID; do
if ! test -z $MID; then
rspamc learn_ham "${MBX}/eml/${MID}" | systemd-cat -t grom_learn_ham
else
gromox-exm2eml -u "${USR}" "${ID}" 2>/dev/null| rspamc learn_ham | systemd-cat -t grom_learn_ham
fi
done
else
printf 'No Non-Junk Folder found for User: %s\n' "${USR}" |systemd-cat -t grom_learn_ham
fi
fi
fi
}
This will require a few of the other of my Functions as you may see.
https://github.com/crpb/grommunio/blob/main/env/.gromenv#L238-L266
You can watch the progress by invoking journalctl -f |awk 'BEGIN{IGNORECASE=1} $5 ~ /grom/'
in another shell before you run it.
PS: HowTo Moving mails automatically to Junk-Folder via Inbox-Rule https://community.grommunio.com/d/572-spam-handling/12