From 148e3aaa5f0f9034760c4d073e5589f444fb0abd Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Mon, 9 Nov 2026 10:27:26 -0500 Subject: [PATCH 1/4] fix(gmail): leave send-as aliases out of gmail autoreply recipients gmail autoreply excluded only the account and the sending address, so a message sent from another of the user's send-as aliases was auto-replied to that alias even without --allow-self. Build the self list with selfEmailsForReply, as gmail reply-all and gmail send --reply-all do. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 + internal/cmd/gmail_autoreply.go | 8 +- internal/cmd/gmail_autoreply_sendas_test.go | 105 ++++++++++++++++++++ 3 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 internal/cmd/gmail_autoreply_sendas_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 861521fad..3df236114 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.48.1 - Unreleased +- Gmail: leave every send-as alias out of `gmail autoreply` recipients, so a message sent from another of your aliases is skipped unless `--allow-self` is set. — thanks @saariuslystoned. + ## 0.48.0 - 2026-11-05 **Highlights:** New backups stay local until you configure a remote; existing configurations keep working. Store service-account keys in the keyring, search Gmail IDs efficiently, and use environment-backed watch tokens, with Calendar fixes and security dependency updates. diff --git a/internal/cmd/gmail_autoreply.go b/internal/cmd/gmail_autoreply.go index e95eeeb15..fa882f989 100644 --- a/internal/cmd/gmail_autoreply.go +++ b/internal/cmd/gmail_autoreply.go @@ -164,7 +164,8 @@ func runGmailAutoReply(ctx context.Context, svc *gmail.Service, account string, Label: input.Label, } - from, err := resolveComposeSender(ctx, svc, account, input.From) + sendAs, sendAsErr := listSendAs(ctx, svc) + from, err := resolveComposeFrom(ctx, svc, account, input.From, sendAs, sendAsErr) if err != nil { return summary, err } @@ -183,10 +184,7 @@ func runGmailAutoReply(ctx context.Context, svc *gmail.Service, account string, return summary, nil } - selfAddrs := []string{account} - if from.sendingEmail != "" && !strings.EqualFold(from.sendingEmail, account) { - selfAddrs = append(selfAddrs, from.sendingEmail) - } + selfAddrs := selfEmailsForReply(account, from.sendingEmail, sendAs) for _, messageID := range messageIDs { msg, err := fetchMessageForAutoReply(ctx, svc, messageID) diff --git a/internal/cmd/gmail_autoreply_sendas_test.go b/internal/cmd/gmail_autoreply_sendas_test.go new file mode 100644 index 000000000..b6c40f3f6 --- /dev/null +++ b/internal/cmd/gmail_autoreply_sendas_test.go @@ -0,0 +1,105 @@ +package cmd + +import ( + "encoding/json" + "net/http" + "strings" + "testing" +) + +func TestExecuteGmailAutoReplySendAsAlias(t *testing.T) { + t.Run("alias", func(t *testing.T) { + sendCalls, summary := executeGmailAutoReplyFrom(t, "alias@example.com") + if sendCalls != 0 { + t.Fatalf("expected no messages.send calls, got %d", sendCalls) + } + if summary.Replied != 0 || summary.Skipped != 1 || len(summary.Results) != 1 { + t.Fatalf("unexpected summary: %#v", summary) + } + got := summary.Results[0] + if got.Action != autoReplyActionSkipped || got.Reason != "no_reply_recipient" { + t.Fatalf("unexpected result: %#v", got) + } + }) + + t.Run("external", func(t *testing.T) { + sendCalls, summary := executeGmailAutoReplyFrom(t, "alice@example.com") + if sendCalls != 1 { + t.Fatalf("expected one messages.send call, got %d", sendCalls) + } + if summary.Replied != 1 || summary.Skipped != 0 || len(summary.Results) != 1 { + t.Fatalf("unexpected summary: %#v", summary) + } + got := summary.Results[0] + if got.Action != "replied" || got.ReplyTo != "alice@example.com" { + t.Fatalf("unexpected result: %#v", got) + } + }) +} + +// executeGmailAutoReplyFrom runs `gmail autoreply` through Execute against an +// httptest Gmail server whose send-as list is the primary account plus +// alias@example.com. from is the matching message's From header. +func executeGmailAutoReplyFrom(t *testing.T, from string) (int, gmailAutoReplySummary) { + t.Helper() + setTestConfigHome(t) + + var sendCalls int + svc, cleanup := newGmailServiceForTest(t, func(w http.ResponseWriter, r *http.Request) { + path := strings.TrimPrefix(r.URL.Path, "/gmail/v1") + w.Header().Set("Content-Type", "application/json") + switch { + case r.Method == http.MethodGet && path == "/users/me/settings/sendAs": + sendAsListHandler(w) + case r.Method == http.MethodGet && strings.HasPrefix(path, "/users/me/labels"): + _ = json.NewEncoder(w).Encode(map[string]any{ + "labels": []map[string]any{ + {"id": "Label_1", "name": "AutoReplied", "type": "user"}, + }, + }) + case r.Method == http.MethodGet && strings.HasPrefix(path, "/users/me/messages") && r.URL.Query().Get("q") != "": + _ = json.NewEncoder(w).Encode(map[string]any{ + "messages": []map[string]any{{"id": "m1", "threadId": "t1"}}, + }) + case r.Method == http.MethodGet && path == "/users/me/messages/m1": + _ = json.NewEncoder(w).Encode(map[string]any{ + "id": "m1", + "threadId": "t1", + "labelIds": []string{"INBOX"}, + "payload": map[string]any{ + "headers": []map[string]any{ + {"name": "From", "value": from}, + {"name": "To", "value": "me@example.com"}, + {"name": "Subject", "value": "hello"}, + {"name": "Message-ID", "value": ""}, + }, + }, + }) + case r.Method == http.MethodPost && path == "/users/me/messages/send": + sendCalls++ + _ = json.NewEncoder(w).Encode(map[string]any{"id": "reply1", "threadId": "t1"}) + case r.Method == http.MethodPost && path == "/users/me/threads/t1/modify": + _ = json.NewEncoder(w).Encode(map[string]any{"id": "t1"}) + default: + http.Error(w, "unexpected "+r.Method+" "+r.URL.RequestURI(), http.StatusNotFound) + } + }) + defer cleanup() + + args := []string{ + "--json", "--no-input", "--account", "me@example.com", + "gmail", "autoreply", "in:inbox", "--body", "thanks", + } + result := executeWithGmailTestService(t, args, svc) + if result.err != nil { + t.Fatalf("Execute(%v): %v\nstderr:\n%s\nstdout:\n%s", args, result.err, result.stderr, result.stdout) + } + + var payload struct { + AutoReply gmailAutoReplySummary `json:"autoReply"` + } + if err := json.Unmarshal([]byte(result.stdout), &payload); err != nil { + t.Fatalf("decode stdout: %v\n%s", err, result.stdout) + } + return sendCalls, payload.AutoReply +} From c18ac7d97cc029c222ff23c772c40379335b9f2e Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Mon, 9 Nov 2026 10:41:30 -0500 Subject: [PATCH 2/4] fix(gmail): skip own-address mail in autoreply and stop if aliases cannot be read A message sent from one of the user's addresses with an external Reply-To was still auto-replied to without --allow-self, whose help says it allows replying to messages sent by your own account or alias. Skip those. Also stop before searching or sending if the send-as list cannot be read, instead of silently treating only the account and sending address as self. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- internal/cmd/gmail_autoreply.go | 31 ++++ internal/cmd/gmail_autoreply_sendas_test.go | 164 ++++++++++++++++++-- 3 files changed, 182 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3df236114..988ad0e6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 0.48.1 - Unreleased -- Gmail: leave every send-as alias out of `gmail autoreply` recipients, so a message sent from another of your aliases is skipped unless `--allow-self` is set. — thanks @saariuslystoned. +- Gmail: leave every send-as alias out of `gmail autoreply` recipients, so messages sent from your own addresses are skipped even with an external Reply-To unless `--allow-self` is set, and the command now stops if it can't read your send-as list. — thanks @saariuslystoned. ## 0.48.0 - 2026-11-05 diff --git a/internal/cmd/gmail_autoreply.go b/internal/cmd/gmail_autoreply.go index fa882f989..a66b1dc39 100644 --- a/internal/cmd/gmail_autoreply.go +++ b/internal/cmd/gmail_autoreply.go @@ -165,6 +165,9 @@ func runGmailAutoReply(ctx context.Context, svc *gmail.Service, account string, } sendAs, sendAsErr := listSendAs(ctx, svc) + if sendAsErr != nil { + return summary, fmt.Errorf("list send-as aliases to exclude your own addresses: %w", sendAsErr) + } from, err := resolveComposeFrom(ctx, svc, account, input.From, sendAs, sendAsErr) if err != nil { return summary, err @@ -223,6 +226,13 @@ func runGmailAutoReply(ctx context.Context, svc *gmail.Service, account string, } replyMeta := replyInfoFromMessage(msg, false) + if !input.AllowSelf && autoReplyFromIsSelf(replyMeta, selfAddrs) { + result.Action = autoReplyActionSkipped + result.Reason = "no_reply_recipient" + summary.Results = append(summary.Results, result) + summary.Skipped++ + continue + } recipients := autoReplyRecipients(replyMeta, selfAddrs) if len(recipients) == 0 && input.AllowSelf { recipients = autoReplyRecipients(replyMeta, nil) @@ -324,6 +334,27 @@ func shouldSkipAutoReplyMessage(msg *gmail.Message) (bool, string) { return false, "" } +// autoReplyFromIsSelf reports whether From is one of the caller's own +// addresses. The comparison matches autoReplyRecipients: case-insensitive on +// the bare address. +func autoReplyFromIsSelf(info *replyInfo, self []string) bool { + if info == nil || len(self) == 0 { + return false + } + selfSet := make(map[string]struct{}, len(self)) + for _, addr := range self { + if trimmed := strings.ToLower(strings.TrimSpace(addr)); trimmed != "" { + selfSet[trimmed] = struct{}{} + } + } + for _, addr := range parseEmailAddresses(info.FromAddr) { + if _, ok := selfSet[strings.ToLower(strings.TrimSpace(addr))]; ok { + return true + } + } + return false +} + func autoReplyRecipients(info *replyInfo, self []string) []string { replyAddress := strings.TrimSpace(info.ReplyToAddr) if replyAddress == "" { diff --git a/internal/cmd/gmail_autoreply_sendas_test.go b/internal/cmd/gmail_autoreply_sendas_test.go index b6c40f3f6..854853277 100644 --- a/internal/cmd/gmail_autoreply_sendas_test.go +++ b/internal/cmd/gmail_autoreply_sendas_test.go @@ -2,14 +2,20 @@ package cmd import ( "encoding/json" + "errors" "net/http" "strings" "testing" + + googleapi "google.golang.org/api/googleapi" ) func TestExecuteGmailAutoReplySendAsAlias(t *testing.T) { t.Run("alias", func(t *testing.T) { - sendCalls, summary := executeGmailAutoReplyFrom(t, "alias@example.com") + sendCalls, summary, err := executeGmailAutoReplyFrom(t, "alias@example.com", "", false, 0) + if err != nil { + t.Fatalf("Execute: %v", err) + } if sendCalls != 0 { t.Fatalf("expected no messages.send calls, got %d", sendCalls) } @@ -23,7 +29,10 @@ func TestExecuteGmailAutoReplySendAsAlias(t *testing.T) { }) t.Run("external", func(t *testing.T) { - sendCalls, summary := executeGmailAutoReplyFrom(t, "alice@example.com") + sendCalls, summary, err := executeGmailAutoReplyFrom(t, "alice@example.com", "", false, 0) + if err != nil { + t.Fatalf("Execute: %v", err) + } if sendCalls != 1 { t.Fatalf("expected one messages.send call, got %d", sendCalls) } @@ -35,21 +44,132 @@ func TestExecuteGmailAutoReplySendAsAlias(t *testing.T) { t.Fatalf("unexpected result: %#v", got) } }) + + t.Run("display name", func(t *testing.T) { + sendCalls, summary, err := executeGmailAutoReplyFrom(t, `"Alias" `, "", false, 0) + if err != nil { + t.Fatalf("Execute: %v", err) + } + if sendCalls != 0 { + t.Fatalf("expected no messages.send calls, got %d", sendCalls) + } + if summary.Replied != 0 || summary.Skipped != 1 || len(summary.Results) != 1 { + t.Fatalf("unexpected summary: %#v", summary) + } + got := summary.Results[0] + if got.Action != autoReplyActionSkipped || got.Reason != "no_reply_recipient" { + t.Fatalf("unexpected result: %#v", got) + } + }) + + t.Run("reply-to", func(t *testing.T) { + sendCalls, summary, err := executeGmailAutoReplyFrom(t, "alias@example.com", "victim@external.com", false, 0) + if err != nil { + t.Fatalf("Execute: %v", err) + } + if sendCalls != 0 { + t.Fatalf("expected no messages.send calls, got %d", sendCalls) + } + if summary.Replied != 0 || summary.Skipped != 1 || len(summary.Results) != 1 { + t.Fatalf("unexpected summary: %#v", summary) + } + got := summary.Results[0] + if got.Action != autoReplyActionSkipped || got.Reason != "no_reply_recipient" { + t.Fatalf("unexpected result: %#v", got) + } + }) + + t.Run("reply-to allow-self", func(t *testing.T) { + sendCalls, summary, err := executeGmailAutoReplyFrom(t, "alias@example.com", "victim@external.com", true, 0) + if err != nil { + t.Fatalf("Execute: %v", err) + } + if sendCalls != 1 { + t.Fatalf("expected one messages.send call, got %d", sendCalls) + } + if summary.Replied != 1 || summary.Skipped != 0 || len(summary.Results) != 1 { + t.Fatalf("unexpected summary: %#v", summary) + } + got := summary.Results[0] + if got.Action != "replied" || got.ReplyTo != "victim@external.com" { + t.Fatalf("unexpected result: %#v", got) + } + }) + + t.Run("allow-self", func(t *testing.T) { + sendCalls, summary, err := executeGmailAutoReplyFrom(t, "alias@example.com", "", true, 0) + if err != nil { + t.Fatalf("Execute: %v", err) + } + if sendCalls != 1 { + t.Fatalf("expected one messages.send call, got %d", sendCalls) + } + if summary.Replied != 1 || summary.Skipped != 0 || len(summary.Results) != 1 { + t.Fatalf("unexpected summary: %#v", summary) + } + got := summary.Results[0] + if got.Action != "replied" || got.ReplyTo != "alias@example.com" { + t.Fatalf("unexpected result: %#v", got) + } + }) + + t.Run("send-as forbidden", func(t *testing.T) { + sendCalls, _, err := executeGmailAutoReplyFrom(t, "alias@example.com", "", false, http.StatusForbidden) + if err == nil { + t.Fatal("expected error") + } + if sendCalls != 0 { + t.Fatalf("expected no messages.send calls, got %d", sendCalls) + } + if !strings.Contains(err.Error(), "list send-as aliases to exclude your own addresses") { + t.Fatalf("unexpected error: %v", err) + } + var apiErr *googleapi.Error + if !errors.As(err, &apiErr) || apiErr.Code != http.StatusForbidden { + t.Fatalf("expected wrapped 403, got %v", err) + } + if ExitCode(err) != exitCodePermissionDenied { + t.Fatalf("exit code = %d, want %d", ExitCode(err), exitCodePermissionDenied) + } + }) } // executeGmailAutoReplyFrom runs `gmail autoreply` through Execute against an // httptest Gmail server whose send-as list is the primary account plus -// alias@example.com. from is the matching message's From header. -func executeGmailAutoReplyFrom(t *testing.T, from string) (int, gmailAutoReplySummary) { +// alias@example.com. from and replyTo are the matching message's From and +// Reply-To headers. allowSelf sets --allow-self. sendAsStatus 0 serves the +// send-as list; any other status is returned by GET settings/sendAs. +// The helper fails the test unless that GET happens exactly once. +func executeGmailAutoReplyFrom(t *testing.T, from, replyTo string, allowSelf bool, sendAsStatus int) (int, gmailAutoReplySummary, error) { t.Helper() setTestConfigHome(t) - var sendCalls int + var sendCalls, sendAsGets, followupCalls int svc, cleanup := newGmailServiceForTest(t, func(w http.ResponseWriter, r *http.Request) { path := strings.TrimPrefix(r.URL.Path, "/gmail/v1") w.Header().Set("Content-Type", "application/json") + sendAsList := r.Method == http.MethodGet && path == "/users/me/settings/sendAs" + if !sendAsList { + followupCalls++ + } switch { - case r.Method == http.MethodGet && path == "/users/me/settings/sendAs": + case sendAsList: + sendAsGets++ + if sendAsStatus != 0 { + w.WriteHeader(sendAsStatus) + _ = json.NewEncoder(w).Encode(map[string]any{ + "error": map[string]any{ + "code": sendAsStatus, + "message": http.StatusText(sendAsStatus), + "errors": []map[string]any{{ + "message": http.StatusText(sendAsStatus), + "domain": "global", + "reason": "forbidden", + }}, + }, + }) + return + } sendAsListHandler(w) case r.Method == http.MethodGet && strings.HasPrefix(path, "/users/me/labels"): _ = json.NewEncoder(w).Encode(map[string]any{ @@ -62,17 +182,21 @@ func executeGmailAutoReplyFrom(t *testing.T, from string) (int, gmailAutoReplySu "messages": []map[string]any{{"id": "m1", "threadId": "t1"}}, }) case r.Method == http.MethodGet && path == "/users/me/messages/m1": + headers := []map[string]any{ + {"name": "From", "value": from}, + {"name": "To", "value": "me@example.com"}, + {"name": "Subject", "value": "hello"}, + {"name": "Message-ID", "value": ""}, + } + if replyTo != "" { + headers = append(headers, map[string]any{"name": "Reply-To", "value": replyTo}) + } _ = json.NewEncoder(w).Encode(map[string]any{ "id": "m1", "threadId": "t1", "labelIds": []string{"INBOX"}, "payload": map[string]any{ - "headers": []map[string]any{ - {"name": "From", "value": from}, - {"name": "To", "value": "me@example.com"}, - {"name": "Subject", "value": "hello"}, - {"name": "Message-ID", "value": ""}, - }, + "headers": headers, }, }) case r.Method == http.MethodPost && path == "/users/me/messages/send": @@ -90,9 +214,21 @@ func executeGmailAutoReplyFrom(t *testing.T, from string) (int, gmailAutoReplySu "--json", "--no-input", "--account", "me@example.com", "gmail", "autoreply", "in:inbox", "--body", "thanks", } + if allowSelf { + args = append(args, "--allow-self") + } result := executeWithGmailTestService(t, args, svc) + if sendAsGets != 1 { + t.Fatalf("GET settings/sendAs calls = %d, want 1", sendAsGets) + } + if sendAsStatus != 0 && (sendCalls != 0 || followupCalls != 0) { + t.Fatalf("send-as failure continued: send=%d followup=%d err=%v", sendCalls, followupCalls, result.err) + } if result.err != nil { - t.Fatalf("Execute(%v): %v\nstderr:\n%s\nstdout:\n%s", args, result.err, result.stderr, result.stdout) + if sendAsStatus == 0 { + t.Fatalf("Execute(%v): %v\nstderr:\n%s\nstdout:\n%s", args, result.err, result.stderr, result.stdout) + } + return sendCalls, gmailAutoReplySummary{}, result.err } var payload struct { @@ -101,5 +237,5 @@ func executeGmailAutoReplyFrom(t *testing.T, from string) (int, gmailAutoReplySu if err := json.Unmarshal([]byte(result.stdout), &payload); err != nil { t.Fatalf("decode stdout: %v\n%s", err, result.stdout) } - return sendCalls, payload.AutoReply + return sendCalls, payload.AutoReply, nil } From 3492f13762506b12c05d96edc06f58a34f8a72df Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Mon, 9 Nov 2026 10:49:24 -0500 Subject: [PATCH 3/4] docs(changelog): reference #1325 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 988ad0e6f..2d4e8e07c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 0.48.1 - Unreleased -- Gmail: leave every send-as alias out of `gmail autoreply` recipients, so messages sent from your own addresses are skipped even with an external Reply-To unless `--allow-self` is set, and the command now stops if it can't read your send-as list. — thanks @saariuslystoned. +- Gmail: leave every send-as alias out of `gmail autoreply` recipients, so messages sent from your own addresses are skipped even with an external Reply-To unless `--allow-self` is set, and the command now stops if it can't read your send-as list. (#1325) — thanks @saariuslystoned. ## 0.48.0 - 2026-11-05 From 36caceedea78aaed3af8d3a1b56aa8a9c80eb5cc Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Mon, 9 Nov 2026 11:19:09 -0500 Subject: [PATCH 4/4] fix(gmail): keep the autoreply sender fallback with --allow-self --allow-self already permits replies to the user's own addresses, so a failed send-as lookup there falls back as before instead of stopping the run. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- internal/cmd/gmail_autoreply.go | 5 ++++- internal/cmd/gmail_autoreply_sendas_test.go | 15 ++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d4e8e07c..bfe1c4849 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 0.48.1 - Unreleased -- Gmail: leave every send-as alias out of `gmail autoreply` recipients, so messages sent from your own addresses are skipped even with an external Reply-To unless `--allow-self` is set, and the command now stops if it can't read your send-as list. (#1325) — thanks @saariuslystoned. +- Gmail: leave every send-as alias out of `gmail autoreply` recipients, so messages sent from your own addresses are skipped even with an external Reply-To unless `--allow-self` is set, and the command now stops if it can't read your send-as list (unless `--allow-self` is set). (#1325) — thanks @saariuslystoned. ## 0.48.0 - 2026-11-05 diff --git a/internal/cmd/gmail_autoreply.go b/internal/cmd/gmail_autoreply.go index a66b1dc39..5006c8535 100644 --- a/internal/cmd/gmail_autoreply.go +++ b/internal/cmd/gmail_autoreply.go @@ -165,7 +165,10 @@ func runGmailAutoReply(ctx context.Context, svc *gmail.Service, account string, } sendAs, sendAsErr := listSendAs(ctx, svc) - if sendAsErr != nil { + // Without --allow-self the alias list is what keeps replies away from the + // user's own addresses, so a failed lookup must stop the run. With + // --allow-self those replies are allowed, so keep the previous fallback. + if sendAsErr != nil && !input.AllowSelf { return summary, fmt.Errorf("list send-as aliases to exclude your own addresses: %w", sendAsErr) } from, err := resolveComposeFrom(ctx, svc, account, input.From, sendAs, sendAsErr) diff --git a/internal/cmd/gmail_autoreply_sendas_test.go b/internal/cmd/gmail_autoreply_sendas_test.go index 854853277..cc1f26544 100644 --- a/internal/cmd/gmail_autoreply_sendas_test.go +++ b/internal/cmd/gmail_autoreply_sendas_test.go @@ -132,6 +132,19 @@ func TestExecuteGmailAutoReplySendAsAlias(t *testing.T) { t.Fatalf("exit code = %d, want %d", ExitCode(err), exitCodePermissionDenied) } }) + + // --allow-self already permits replies to the user's own addresses, so a + // failed send-as lookup keeps the previous sender fallback instead of + // stopping the run. + t.Run("send-as forbidden with allow-self", func(t *testing.T) { + sendCalls, summary, err := executeGmailAutoReplyFrom(t, "alice@example.com", "", true, http.StatusForbidden) + if err != nil { + t.Fatalf("Execute: %v", err) + } + if sendCalls != 1 || summary.Replied != 1 { + t.Fatalf("sendCalls = %d, summary = %#v, want one reply", sendCalls, summary) + } + }) } // executeGmailAutoReplyFrom runs `gmail autoreply` through Execute against an @@ -221,7 +234,7 @@ func executeGmailAutoReplyFrom(t *testing.T, from, replyTo string, allowSelf boo if sendAsGets != 1 { t.Fatalf("GET settings/sendAs calls = %d, want 1", sendAsGets) } - if sendAsStatus != 0 && (sendCalls != 0 || followupCalls != 0) { + if sendAsStatus != 0 && !allowSelf && (sendCalls != 0 || followupCalls != 0) { t.Fatalf("send-as failure continued: send=%d followup=%d err=%v", sendCalls, followupCalls, result.err) } if result.err != nil {