Skip to content

Commit 1b2b152

Browse files
committed
add "mox config account list", printing all accounts and whether they are disabled
based on question from wisse on slack
1 parent 31c2261 commit 1b2b152

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

ctl.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"os"
1616
"path/filepath"
1717
"runtime/debug"
18+
"slices"
1819
"strconv"
1920
"strings"
2021
"time"
@@ -33,7 +34,6 @@ import (
3334
"github.com/mjl-/mox/smtp"
3435
"github.com/mjl-/mox/store"
3536
"github.com/mjl-/mox/webapi"
36-
"slices"
3737
)
3838

3939
// 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()) {
10561056
xctl.xcheck(err, "removing account")
10571057
xctl.xwriteok()
10581058

1059+
case "accountlist":
1060+
/* protocol:
1061+
> "accountlist"
1062+
< "ok" or error
1063+
< stream
1064+
*/
1065+
xctl.xwriteok()
1066+
xw := xctl.writer()
1067+
all, disabled := mox.Conf.AccountsDisabled()
1068+
slices.Sort(all)
1069+
for _, account := range all {
1070+
var extra string
1071+
if slices.Contains(disabled, account) {
1072+
extra += "\t(disabled)"
1073+
}
1074+
fmt.Fprintf(xw, "%s%s\n", account, extra)
1075+
}
1076+
xw.xclose()
1077+
10591078
case "accountdisabled":
10601079
/* protocol:
10611080
> "accountdisabled"

ctl_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@ func TestCtl(t *testing.T) {
305305
testctl(func(xctl *ctl) {
306306
ctlcmdConfigAccountDisabled(xctl, "mjl2", "testing")
307307
})
308+
309+
// "accountlist"
310+
testctl(func(xctl *ctl) {
311+
ctlcmdConfigAccountList(xctl)
312+
})
313+
308314
testctl(func(xctl *ctl) {
309315
ctlcmdConfigAccountDisabled(xctl, "mjl2", "")
310316
})

doc.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ any parameters. Followed by the help and usage information for each command.
6363
mox config dnsrecords domain
6464
mox config describe-domains >domains.conf
6565
mox config describe-static >mox.conf
66+
mox config account list
6667
mox config account add account address
6768
mox config account rm account
6869
mox config account disable account message
@@ -953,6 +954,15 @@ may contain unfinished list items.
953954
954955
usage: mox config describe-static >mox.conf
955956
957+
# mox config account list
958+
959+
List all accounts.
960+
961+
Each account is printed on a line, with optional additional tab-separated
962+
information, such as "(disabled)".
963+
964+
usage: mox config account list
965+
956966
# mox config account add
957967
958968
Add an account with an email address and reload the configuration.

main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ var commands = []struct {
145145
{"config dnsrecords", cmdConfigDNSRecords},
146146
{"config describe-domains", cmdConfigDescribeDomains},
147147
{"config describe-static", cmdConfigDescribeStatic},
148+
{"config account list", cmdConfigAccountList},
148149
{"config account add", cmdConfigAccountAdd},
149150
{"config account rm", cmdConfigAccountRemove},
150151
{"config account disable", cmdConfigAccountDisable},
@@ -996,6 +997,27 @@ func ctlcmdConfigAccountRemove(ctl *ctl, account string) {
996997
fmt.Println("account removed")
997998
}
998999

1000+
func cmdConfigAccountList(c *cmd) {
1001+
c.help = `List all accounts.
1002+
1003+
Each account is printed on a line, with optional additional tab-separated
1004+
information, such as "(disabled)".
1005+
`
1006+
args := c.Parse()
1007+
if len(args) != 0 {
1008+
c.Usage()
1009+
}
1010+
1011+
mustLoadConfig()
1012+
ctlcmdConfigAccountList(xctl())
1013+
}
1014+
1015+
func ctlcmdConfigAccountList(ctl *ctl) {
1016+
ctl.xwrite("accountlist")
1017+
ctl.xreadok()
1018+
ctl.xstreamto(os.Stdout)
1019+
}
1020+
9991021
func cmdConfigAccountDisable(c *cmd) {
10001022
c.params = "account message"
10011023
c.help = `Disable login for an account, showing message to users when they try to login.

0 commit comments

Comments
 (0)