improve training of junk filter

before, we used heuristics to decide when to train/untrain a message as junk or
nonjunk: the message had to be seen, be in certain mailboxes. then if a message
was marked as junk, it was junk. and otherwise it was nonjunk. this wasn't good
enough: you may want to keep some messages around as neither junk or nonjunk.
and that wasn't possible.

ideally, we would just look at the imap $Junk and $NotJunk flags. the problem
is that mail clients don't set these flags, or don't make it easy. thunderbird
can set the flags based on its own bayesian filter. it has a shortcut for
marking Junk and moving it to the junk folder (good), but the counterpart of
notjunk only marks a message as notjunk without showing in the UI that it was
marked as notjunk. there is also no "move and mark as notjunk" mechanism. e.g.
"archive" does not mark a message as notjunk. ios mail and mutt don't appear to
have any way to see or change the $Junk and $NotJunk flags.

what email clients do have is the ability to move messages to other
mailboxes/folders. so mox now has a mechanism that allows you to configure
mailboxes that automatically set $Junk or $NotJunk (or clear both) when a
message is moved/copied/delivered to that folder. e.g. a mailbox called junk or
spam or rejects marks its messags as junk. inbox, postmaster, dmarc, tlsrpt,
neutral* mark their messages as neither junk or notjunk. other folders mark
their messages as notjunk. e.g. list/*, archive. this functionality is
optional, but enabled with the quickstart and for new accounts.

also, mox now keeps track of the previous training of a message and will only
untrain/train if needed. before, there probably have been duplicate or missing
(un)trainings.

this also includes a new subcommand "retrain" to recreate the junkfilter for an
account. you should run it after updating to this version. and you should
probably also modify your account config to include the AutomaticJunkFlags.
This commit is contained in:
Mechiel Lukkien
2023-02-11 23:00:12 +01:00
parent a4306ef783
commit bf04fb8a1a
26 changed files with 410 additions and 157 deletions

View File

@ -424,9 +424,32 @@ describe-static" and "mox config describe-domains":
# in a mailbox, e.g. Rejects. If mail isn't coming in when you expect, you can
# look there. The mail still isn't accepted, so the remote mail server may retry
# (hopefully, if legitimate), or give up (hopefully, if indeed a spammer).
# (optional)
# Messages are automatically removed from this mailbox, so do not set it to a
# mailbox that has messages you want to keep. (optional)
RejectsMailbox:
# Automatically set $Junk and $NotJunk flags based on mailbox messages are
# delivered/moved/copied to. Email clients typically have too limited
# functionality to conveniently set these flags, especially $NonJunk, but they can
# all move messages to a different mailbox, so this helps them. (optional)
AutomaticJunkFlags:
# If enabled, flags will be set automatically if they match a regular expression
# below. When two lists are set, the empty list will match all remaining messages.
# Messages are matched in the order specified and the search stops on the first
# match. Mailboxes are lowercased before matching.
Enabled: false
# Example: ^(junk|spam|rejects). (optional)
JunkMailboxRegexp:
# Example: ^(inbox|neutral|postmaster|dmarc|tlsrpt), and you may wish to add trash
# depending on how you use it, or leave this empty. (optional)
NeutralMailboxRegexp:
# Example: .* or an empty string. (optional)
NotJunkMailboxRegexp:
# Content-based filtering, using the junk-status of individual messages to rank
# words in such messages as spam or ham. It is recommended you always set the
# applicable (non)-junk status on messages, and that you do not empty your Trash