From fb5870350c403063207071e551c61faeba4521c5 Mon Sep 17 00:00:00 2001 From: gastown/polecats/dementus Date: Tue, 30 Dec 2025 22:09:38 -0800 Subject: [PATCH] Add isQueueAddress() and parseQueueName() helpers to router.go (gt-0q3cg) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add queue address detection following the same pattern as list address detection. Includes tests in router_test.go. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- internal/mail/router.go | 10 ++++++++ internal/mail/router_test.go | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/internal/mail/router.go b/internal/mail/router.go index 46561874..ae1038b2 100644 --- a/internal/mail/router.go +++ b/internal/mail/router.go @@ -60,6 +60,16 @@ func parseListName(address string) string { return strings.TrimPrefix(address, "list:") } +// isQueueAddress returns true if the address uses queue:name syntax. +func isQueueAddress(address string) bool { + return strings.HasPrefix(address, "queue:") +} + +// parseQueueName extracts the queue name from a queue:name address. +func parseQueueName(address string) string { + return strings.TrimPrefix(address, "queue:") +} + // expandList returns the recipients for a mailing list. // Returns ErrUnknownList if the list is not found. func (r *Router) expandList(listName string) ([]string, error) { diff --git a/internal/mail/router_test.go b/internal/mail/router_test.go index c42f67ad..94ae00f4 100644 --- a/internal/mail/router_test.go +++ b/internal/mail/router_test.go @@ -267,6 +267,52 @@ func TestParseListName(t *testing.T) { } } +func TestIsQueueAddress(t *testing.T) { + tests := []struct { + address string + want bool + }{ + {"queue:work", true}, + {"queue:gastown/polecats", true}, + {"queue:", true}, // Edge case: empty queue name (will fail on expand) + {"mayor/", false}, + {"gastown/witness", false}, + {"queuework", false}, // Missing colon + {"list:oncall", false}, + {"", false}, + } + + for _, tt := range tests { + t.Run(tt.address, func(t *testing.T) { + got := isQueueAddress(tt.address) + if got != tt.want { + t.Errorf("isQueueAddress(%q) = %v, want %v", tt.address, got, tt.want) + } + }) + } +} + +func TestParseQueueName(t *testing.T) { + tests := []struct { + address string + want string + }{ + {"queue:work", "work"}, + {"queue:gastown/polecats", "gastown/polecats"}, + {"queue:", ""}, + {"queue:priority-high", "priority-high"}, + } + + for _, tt := range tests { + t.Run(tt.address, func(t *testing.T) { + got := parseQueueName(tt.address) + if got != tt.want { + t.Errorf("parseQueueName(%q) = %q, want %q", tt.address, got, tt.want) + } + }) + } +} + func TestExpandList(t *testing.T) { // Create temp directory with messaging config tmpDir := t.TempDir()