This is not a spam filter. Rather, it’s an automation to quickly eliminate those frequently received and mostly unwanted emails, yet those we don’t wish to formally mark as spam.
Make sure you’ve sourced and defined an alias file in your
muttrc
:source $XDG_CONFIG_HOME/mutt/aliases.muttrc set alias_file = $XDG_CONFIG_HOME/mutt/aliases.muttrc
In the aliases file, define a ‘spam’ group as follows, with initially at least one address:
alias -group spam spam test@spam.com
Define a macro to delete all messages with from addresses in the spam group:
macro index ds '<delete-pattern> %f spam<enter>'
Create a script to automatically add the sender of the current email to the spam group. Place the script within your PATH. I named mine ‘mutt-add-spam’, also available in my scripts repository.
[ -z "$MUTT_ALIAS_FILE" ] && MUTT_ALIAS_FILE="$XDG_CONFIG_HOME/mutt/aliases.muttrc" ( from=$(sed -En '1,/^$/s/^From.*<([^>]+)>/\1/p') && sed -iE '/alias -group spam/{/'$from'/q;s/$/,'$from'/}' "$MUTT_ALIAS_FILE" && echo "$from added to spam group" )
The script
- Reads a piped-in email and extracts the from address.
- If not already present, adds the address to the ‘spam’ alias group.
Lastly, in
muttrc
define one more macro to pipe the selected message into the above script.macro index,pager <Esc>S "<pipe-message>mutt-add-spam; read s<enter>"
Upon typing Alt+S you’ll see a confirmation message of a successful operation.
Questions, comments? Connect.