diff --git a/ctl.go b/ctl.go index 8598394..2e320a2 100644 --- a/ctl.go +++ b/ctl.go @@ -15,6 +15,7 @@ import ( "os" "path/filepath" "runtime/debug" + "slices" "strconv" "strings" "time" @@ -33,7 +34,6 @@ import ( "github.com/mjl-/mox/smtp" "github.com/mjl-/mox/store" "github.com/mjl-/mox/webapi" - "slices" ) // 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.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": /* protocol: > "accountdisabled" diff --git a/ctl_test.go b/ctl_test.go index 971ad51..5fd2857 100644 --- a/ctl_test.go +++ b/ctl_test.go @@ -305,6 +305,12 @@ func TestCtl(t *testing.T) { testctl(func(xctl *ctl) { ctlcmdConfigAccountDisabled(xctl, "mjl2", "testing") }) + + // "accountlist" + testctl(func(xctl *ctl) { + ctlcmdConfigAccountList(xctl) + }) + testctl(func(xctl *ctl) { ctlcmdConfigAccountDisabled(xctl, "mjl2", "") }) diff --git a/doc.go b/doc.go index 22772c1..59e1c61 100644 --- a/doc.go +++ b/doc.go @@ -63,6 +63,7 @@ any parameters. Followed by the help and usage information for each command. mox config dnsrecords domain mox config describe-domains >domains.conf mox config describe-static >mox.conf + mox config account list mox config account add account address mox config account rm account mox config account disable account message @@ -953,6 +954,15 @@ may contain unfinished list items. 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 Add an account with an email address and reload the configuration. diff --git a/main.go b/main.go index 25e1a0f..073993a 100644 --- a/main.go +++ b/main.go @@ -145,6 +145,7 @@ var commands = []struct { {"config dnsrecords", cmdConfigDNSRecords}, {"config describe-domains", cmdConfigDescribeDomains}, {"config describe-static", cmdConfigDescribeStatic}, + {"config account list", cmdConfigAccountList}, {"config account add", cmdConfigAccountAdd}, {"config account rm", cmdConfigAccountRemove}, {"config account disable", cmdConfigAccountDisable}, @@ -996,6 +997,27 @@ func ctlcmdConfigAccountRemove(ctl *ctl, account string) { 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) { c.params = "account message" c.help = `Disable login for an account, showing message to users when they try to login.