From fc7b0cc71eb5e67b8895036a8a0d60cff9232eee Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Mon, 11 Sep 2023 11:55:28 +0200 Subject: [PATCH] fix parsing List-Post header in webmail --- webmail/message.go | 8 ++++---- webmail/message_test.go | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 webmail/message_test.go diff --git a/webmail/message.go b/webmail/message.go index 5c1376f..1128371 100644 --- a/webmail/message.go +++ b/webmail/message.go @@ -316,12 +316,12 @@ func parseListPostAddress(s string) *MessageAddress { if !strings.HasPrefix(s, "", 2) - if len(t) != 2 { + s = s[1:] + s, _, found := strings.Cut(s, ">") + if !found { return nil } - u, err := url.Parse(t[0]) + u, err := url.Parse(s) if err != nil { return nil } diff --git a/webmail/message_test.go b/webmail/message_test.go new file mode 100644 index 0000000..3d107ab --- /dev/null +++ b/webmail/message_test.go @@ -0,0 +1,21 @@ +package webmail + +import ( + "testing" + + "github.com/mjl-/mox/dns" +) + +func TestParseListPostAddress(t *testing.T) { + check := func(s string, exp *MessageAddress) { + t.Helper() + v := parseListPostAddress(s) + tcompare(t, v, exp) + } + + check("", &MessageAddress{User: "list", Domain: dns.Domain{ASCII: "host.com"}}) + check(" (Postings are Moderated)", &MessageAddress{User: "moderator", Domain: dns.Domain{ASCII: "host.com"}}) + check("", &MessageAddress{User: "moderator", Domain: dns.Domain{ASCII: "host.com"}}) + check("NO (posting not allowed on this list)", nil) + check("", nil) +}