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()