Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/mailbox/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func RunBot(ctx context.Context, c *Client, args []string, in io.Reader, out io.
return err
}

switch strings.ToLower(args[0]) {
cmd := strings.ToLower(args[0])
switch cmd {
case "mailboxes":
v, err := c.Mailboxes(ctx)
if err != nil {
Expand Down Expand Up @@ -135,7 +136,7 @@ func RunBot(ctx context.Context, c *Client, args []string, in io.Reader, out io.
if len(args) > 3 {
on = !strings.EqualFold(args[3], "off") && args[3] != "false" && args[3] != "0"
}
if args[0] == "flag" {
if cmd == "flag" {
err = c.Flag(ctx, mailbox, uid, on)
} else {
err = c.MarkSeen(ctx, mailbox, uid, on)
Expand Down
20 changes: 20 additions & 0 deletions internal/mailbox/mailbox_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package mailbox

import (
"bytes"
"context"
"errors"
"strings"
"testing"
"time"
)
Expand Down Expand Up @@ -142,3 +144,21 @@ func TestFlagAndDelete(t *testing.T) {
t.Fatal("uid 1 should be deleted")
}
}

func TestRunBotFlagCommandIsCaseInsensitive(t *testing.T) {
tr := seeded()
c := paidClient(tr)
var out bytes.Buffer

if err := RunBot(context.Background(), c, []string{"FLAG", Inbox, "1"}, strings.NewReader(""), &out); err != nil {
t.Fatal(err)
}

msg, _, _ := tr.ReadMessage(context.Background(), Inbox, 1)
if !msg.Flagged {
t.Fatal("uppercase FLAG should set the flagged flag")
}
if msg.Seen {
t.Fatal("uppercase FLAG should not mark the message seen")
}
}