fix(mailbox): reject invalid bot toggle values (#80)

Co-authored-by: rissrice2105-agent <rissrice2105-agent@users.noreply.github.com>
This commit is contained in:
RissRIce 2026-07-07 06:40:35 -06:00 committed by GitHub
parent ad76e7fa16
commit ee06082ce1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 43 additions and 1 deletions

View file

@ -137,7 +137,11 @@ func RunBot(ctx context.Context, c *Client, args []string, in io.Reader, out io.
}
on := true
if len(args) > 3 {
on = !strings.EqualFold(args[3], "off") && args[3] != "false" && args[3] != "0"
var ok bool
on, ok = parseBotBool(args[3])
if !ok {
return fail(fmt.Errorf("invalid %s value %q; use on/off", args[0], args[3]))
}
}
if strings.ToLower(args[0]) == "flag" {
err = c.Flag(ctx, mailbox, uid, on)
@ -175,3 +179,14 @@ func mailboxUID(args []string) (string, uint32, error) {
}
return args[1], uint32(uid), nil
}
func parseBotBool(value string) (bool, bool) {
switch strings.ToLower(strings.TrimSpace(value)) {
case "on", "true", "1":
return true, true
case "off", "false", "0":
return false, true
default:
return false, false
}
}