add "mox config account list", printing all accounts and whether they are disabled

based on question from wisse on slack
This commit is contained in:
Mechiel Lukkien 2025-04-16 19:59:20 +02:00
parent 31c22618f5
commit 1b2b152cb5
No known key found for this signature in database
4 changed files with 58 additions and 1 deletions

21
ctl.go
View File

@ -15,6 +15,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"runtime/debug" "runtime/debug"
"slices"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -33,7 +34,6 @@ import (
"github.com/mjl-/mox/smtp" "github.com/mjl-/mox/smtp"
"github.com/mjl-/mox/store" "github.com/mjl-/mox/store"
"github.com/mjl-/mox/webapi" "github.com/mjl-/mox/webapi"
"slices"
) )
// ctl represents a connection to the ctl unix domain socket of a running mox instance. // ctl represents a connection to the ctl unix domain socket of a running mox instance.
@ -1056,6 +1056,25 @@ func servectlcmd(ctx context.Context, xctl *ctl, cid int64, shutdown func()) {
xctl.xcheck(err, "removing account") xctl.xcheck(err, "removing account")
xctl.xwriteok() xctl.xwriteok()
case "accountlist":
/* protocol:
> "accountlist"
< "ok" or error
< stream
*/
xctl.xwriteok()
xw := xctl.writer()
all, disabled := mox.Conf.AccountsDisabled()
slices.Sort(all)
for _, account := range all {
var extra string
if slices.Contains(disabled, account) {
extra += "\t(disabled)"
}
fmt.Fprintf(xw, "%s%s\n", account, extra)
}
xw.xclose()
case "accountdisabled": case "accountdisabled":
/* protocol: /* protocol:
> "accountdisabled" > "accountdisabled"

View File

@ -305,6 +305,12 @@ func TestCtl(t *testing.T) {
testctl(func(xctl *ctl) { testctl(func(xctl *ctl) {
ctlcmdConfigAccountDisabled(xctl, "mjl2", "testing") ctlcmdConfigAccountDisabled(xctl, "mjl2", "testing")
}) })
// "accountlist"
testctl(func(xctl *ctl) {
ctlcmdConfigAccountList(xctl)
})
testctl(func(xctl *ctl) { testctl(func(xctl *ctl) {
ctlcmdConfigAccountDisabled(xctl, "mjl2", "") ctlcmdConfigAccountDisabled(xctl, "mjl2", "")
}) })

10
doc.go
View File

@ -63,6 +63,7 @@ any parameters. Followed by the help and usage information for each command.
mox config dnsrecords domain mox config dnsrecords domain
mox config describe-domains >domains.conf mox config describe-domains >domains.conf
mox config describe-static >mox.conf mox config describe-static >mox.conf
mox config account list
mox config account add account address mox config account add account address
mox config account rm account mox config account rm account
mox config account disable account message mox config account disable account message
@ -953,6 +954,15 @@ may contain unfinished list items.
usage: mox config describe-static >mox.conf usage: mox config describe-static >mox.conf
# mox config account list
List all accounts.
Each account is printed on a line, with optional additional tab-separated
information, such as "(disabled)".
usage: mox config account list
# mox config account add # mox config account add
Add an account with an email address and reload the configuration. Add an account with an email address and reload the configuration.

22
main.go
View File

@ -145,6 +145,7 @@ var commands = []struct {
{"config dnsrecords", cmdConfigDNSRecords}, {"config dnsrecords", cmdConfigDNSRecords},
{"config describe-domains", cmdConfigDescribeDomains}, {"config describe-domains", cmdConfigDescribeDomains},
{"config describe-static", cmdConfigDescribeStatic}, {"config describe-static", cmdConfigDescribeStatic},
{"config account list", cmdConfigAccountList},
{"config account add", cmdConfigAccountAdd}, {"config account add", cmdConfigAccountAdd},
{"config account rm", cmdConfigAccountRemove}, {"config account rm", cmdConfigAccountRemove},
{"config account disable", cmdConfigAccountDisable}, {"config account disable", cmdConfigAccountDisable},
@ -996,6 +997,27 @@ func ctlcmdConfigAccountRemove(ctl *ctl, account string) {
fmt.Println("account removed") fmt.Println("account removed")
} }
func cmdConfigAccountList(c *cmd) {
c.help = `List all accounts.
Each account is printed on a line, with optional additional tab-separated
information, such as "(disabled)".
`
args := c.Parse()
if len(args) != 0 {
c.Usage()
}
mustLoadConfig()
ctlcmdConfigAccountList(xctl())
}
func ctlcmdConfigAccountList(ctl *ctl) {
ctl.xwrite("accountlist")
ctl.xreadok()
ctl.xstreamto(os.Stdout)
}
func cmdConfigAccountDisable(c *cmd) { func cmdConfigAccountDisable(c *cmd) {
c.params = "account message" c.params = "account message"
c.help = `Disable login for an account, showing message to users when they try to login. c.help = `Disable login for an account, showing message to users when they try to login.