mox retrain: make the parameter, for account, optional and retrain all accounts when absent

for more easily retraining all accounts. users should be retraining their
accounts with the next release, due to the fix in the previous commit.
This commit is contained in:
Mechiel Lukkien 2024-12-07 17:00:00 +01:00
parent 17baf9a883
commit 94fb48c2dc
No known key found for this signature in database
3 changed files with 74 additions and 59 deletions

15
ctl.go
View file

@ -1335,11 +1335,13 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
case "retrain":
/* protocol:
> "retrain"
> account
> account or empty
< "ok" or error
*/
account := ctl.xread()
acc, err := store.OpenAccount(log, account)
xretrain := func(name string) {
acc, err := store.OpenAccount(log, name)
ctl.xcheck(err, "open account")
defer func() {
if acc != nil {
@ -1396,6 +1398,15 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
jf = nil
ctl.xcheck(err, "closing junk filter")
})
}
if account == "" {
for _, name := range mox.Conf.Accounts() {
xretrain(name)
}
} else {
xretrain(account)
}
ctl.xwriteok()
case "recalculatemailboxcounts":

6
doc.go
View file

@ -105,7 +105,7 @@ any parameters. Followed by the help and usage information for each command.
mox dnsbl check zone ip
mox dnsbl checkhealth zone
mox mtasts lookup domain
mox retrain accountname
mox retrain [accountname]
mox sendmail [-Fname] [ignoredflags] [-t] [<message]
mox spf check domain ip
mox spf lookup domain
@ -1390,12 +1390,12 @@ should be used, and how long the policy can be cached.
# mox retrain
Recreate and retrain the junk filter for the account.
Recreate and retrain the junk filter for the account or all accounts.
Useful after having made changes to the junk filter configuration, or if the
implementation has changed.
usage: mox retrain accountname
usage: mox retrain [accountname]
# mox sendmail

12
main.go
View file

@ -2874,19 +2874,23 @@ should be used, and how long the policy can be cached.
}
func cmdRetrain(c *cmd) {
c.params = "accountname"
c.help = `Recreate and retrain the junk filter for the account.
c.params = "[accountname]"
c.help = `Recreate and retrain the junk filter for the account or all accounts.
Useful after having made changes to the junk filter configuration, or if the
implementation has changed.
`
args := c.Parse()
if len(args) != 1 {
if len(args) > 1 {
c.Usage()
}
var account string
if len(args) == 1 {
account = args[0]
}
mustLoadConfig()
ctlcmdRetrain(xctl(), args[0])
ctlcmdRetrain(xctl(), account)
}
func ctlcmdRetrain(ctl *ctl, account string) {