mirror of
https://github.com/mjl-/mox.git
synced 2024-12-27 08:53:48 +03:00
when removing account, remove its data directory instead of leaving it around
recreating the account would resurface the old messages, certainly not what you'ld expect. it's about time to just remove the files. we do ask admins to confirm that when removing through admin interface. it's also in the "mox config account rm" help output now. for issue #162 by RobSlgm with feedback from x8x, thanks!
This commit is contained in:
parent
a2c9cfc55b
commit
30ac690c8f
5 changed files with 18 additions and 2 deletions
2
doc.go
2
doc.go
|
@ -937,6 +937,8 @@ Remove an account and reload the configuration.
|
||||||
Email addresses for this account will also be removed, and incoming email for
|
Email addresses for this account will also be removed, and incoming email for
|
||||||
these addresses will be rejected.
|
these addresses will be rejected.
|
||||||
|
|
||||||
|
All data for the account will be removed.
|
||||||
|
|
||||||
usage: mox config account rm account
|
usage: mox config account rm account
|
||||||
|
|
||||||
# mox config address add
|
# mox config address add
|
||||||
|
|
2
main.go
2
main.go
|
@ -890,6 +890,8 @@ func cmdConfigAccountRemove(c *cmd) {
|
||||||
|
|
||||||
Email addresses for this account will also be removed, and incoming email for
|
Email addresses for this account will also be removed, and incoming email for
|
||||||
these addresses will be rejected.
|
these addresses will be rejected.
|
||||||
|
|
||||||
|
All data for the account will be removed.
|
||||||
`
|
`
|
||||||
args := c.Parse()
|
args := c.Parse()
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
|
|
|
@ -1024,6 +1024,18 @@ func AccountRemove(ctx context.Context, account string) (rerr error) {
|
||||||
if err := writeDynamic(ctx, log, nc); err != nil {
|
if err := writeDynamic(ctx, log, nc); err != nil {
|
||||||
return fmt.Errorf("writing domains.conf: %w", err)
|
return fmt.Errorf("writing domains.conf: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
odir := filepath.Join(DataDirPath("accounts"), account)
|
||||||
|
tmpdir := filepath.Join(DataDirPath("tmp"), "oldaccount-"+account)
|
||||||
|
if err := os.Rename(odir, tmpdir); err != nil {
|
||||||
|
log.Errorx("moving old account data directory out of the way", err, slog.String("account", account))
|
||||||
|
return fmt.Errorf("account removed, but account data directory %q could not be moved out of the way: %v", odir, err)
|
||||||
|
}
|
||||||
|
if err := os.RemoveAll(tmpdir); err != nil {
|
||||||
|
log.Errorx("removing old account data directory", err, slog.String("account", account))
|
||||||
|
return fmt.Errorf("account removed, its data directory moved to %q, but removing failed: %v", odir, err)
|
||||||
|
}
|
||||||
|
|
||||||
log.Info("account removed", slog.String("account", account))
|
log.Info("account removed", slog.String("account", account))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2194,7 +2194,7 @@ const account = async (name) => {
|
||||||
formPassword.reset();
|
formPassword.reset();
|
||||||
}), dom.br(), RoutesEditor('account-specific', transports, config.Routes || [], async (routes) => await client.AccountRoutesSave(name, routes)), dom.br(), dom.h2('Danger'), dom.clickbutton('Remove account', async function click(e) {
|
}), dom.br(), RoutesEditor('account-specific', transports, config.Routes || [], async (routes) => await client.AccountRoutesSave(name, routes)), dom.br(), dom.h2('Danger'), dom.clickbutton('Remove account', async function click(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!window.confirm('Are you sure you want to remove this account?')) {
|
if (!window.confirm('Are you sure you want to remove this account? All account data, including messages will be removed.')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await check(e.target, client.AccountRemove(name));
|
await check(e.target, client.AccountRemove(name));
|
||||||
|
|
|
@ -999,7 +999,7 @@ const account = async (name: string) => {
|
||||||
dom.h2('Danger'),
|
dom.h2('Danger'),
|
||||||
dom.clickbutton('Remove account', async function click(e: MouseEvent) {
|
dom.clickbutton('Remove account', async function click(e: MouseEvent) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (!window.confirm('Are you sure you want to remove this account?')) {
|
if (!window.confirm('Are you sure you want to remove this account? All account data, including messages will be removed.')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await check(e.target! as HTMLButtonElement, client.AccountRemove(name))
|
await check(e.target! as HTMLButtonElement, client.AccountRemove(name))
|
||||||
|
|
Loading…
Reference in a new issue