From 4202fbe108708f3a58938af3774cbc37606b8e5a Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Mon, 6 Feb 2023 11:31:46 +0100 Subject: [PATCH] make the setaccountpassword talk through ctl otherwise, setting a password will block if something has the account open, e.g. any imap connection. so in practice it only worked when mox isn't running. --- ctl.go | 26 ++++++++++++++++++++++++++ main.go | 12 +++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/ctl.go b/ctl.go index d5a6a65..3ac146f 100644 --- a/ctl.go +++ b/ctl.go @@ -403,6 +403,32 @@ func servectlcmd(ctx context.Context, log *mlog.Log, ctl *ctl, xcmd *string, shu ctl.xcheck(err, "closing account") ctl.xwriteok() + case "setaccountpassword": + /* protocol: + > "setaccountpassword" + > address + > password + < "ok" or error + */ + + addr := ctl.xread() + pw := ctl.xread() + + acc, _, err := store.OpenEmail(addr) + ctl.xcheck(err, "open account") + defer func() { + if acc != nil { + acc.Close() + } + }() + + err = acc.SetPassword(pw) + ctl.xcheck(err, "setting password") + err = acc.Close() + ctl.xcheck(err, "closing account") + acc = nil + ctl.xwriteok() + case "queue": /* protocol: > "queue" diff --git a/main.go b/main.go index 221cfd0..57cb6e8 100644 --- a/main.go +++ b/main.go @@ -889,15 +889,13 @@ Any email address configured for the account can be used. } mustLoadConfig() - acc, _, err := store.OpenEmail(args[0]) - xcheckf(err, "open account") - pw := xreadpassword() - err = acc.SetPassword(pw) - xcheckf(err, "setting password") - err = acc.Close() - xcheckf(err, "closing account") + ctl := xctl() + ctl.xwrite("setaccountpassword") + ctl.xwrite(args[0]) + ctl.xwrite(pw) + ctl.xreadok() } func cmdDeliver(c *cmd) {