From 8bcce40c556b9cbb958ebe6510fc27fda04844f2 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Tue, 16 Apr 2024 19:37:37 +0200 Subject: [PATCH] webmail: recognize multiple urls in List-Post addresses there may be a http(s)-address, which we'll ignore. the mailto may come after that. like in google groups. --- webmail/message.go | 40 ++++++++++++++++++++++++---------------- webmail/message_test.go | 1 + 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/webmail/message.go b/webmail/message.go index cd07457..73cb822 100644 --- a/webmail/message.go +++ b/webmail/message.go @@ -369,23 +369,31 @@ func parseListPostAddress(s string) *MessageAddress { List-Post: (Postings are Moderated) List-Post: List-Post: NO (posting not allowed on this list) + List-Post: , */ s = strings.TrimSpace(s) - if !strings.HasPrefix(s, "") + if !found { + return nil + } + if strings.HasPrefix(addr, "mailto:") { + u, err := url.Parse(addr) + if err != nil { + return nil + } + addr, err := smtp.ParseAddress(u.Opaque) + if err != nil { + return nil + } + return &MessageAddress{User: addr.Localpart.String(), Domain: addr.Domain} + } + s = strings.TrimSpace(ns) + s = strings.TrimPrefix(s, ",") + s = strings.TrimSpace(s) } - s = s[1:] - s, _, found := strings.Cut(s, ">") - if !found { - return nil - } - u, err := url.Parse(s) - if err != nil { - return nil - } - addr, err := smtp.ParseAddress(u.Opaque) - if err != nil { - return nil - } - return &MessageAddress{User: addr.Localpart.String(), Domain: addr.Domain} + return nil } diff --git a/webmail/message_test.go b/webmail/message_test.go index e7d275a..3495172 100644 --- a/webmail/message_test.go +++ b/webmail/message_test.go @@ -45,5 +45,6 @@ func TestParseListPostAddress(t *testing.T) { 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(", ", &MessageAddress{User: "golang-dev", Domain: dns.Domain{ASCII: "googlegroups.com"}}) check("", nil) }