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.
This commit is contained in:
Mechiel Lukkien 2024-04-16 19:37:37 +02:00
parent 8654a1f901
commit 8bcce40c55
No known key found for this signature in database
2 changed files with 25 additions and 16 deletions

View file

@ -369,23 +369,31 @@ func parseListPostAddress(s string) *MessageAddress {
List-Post: <mailto:moderator@host.com> (Postings are Moderated)
List-Post: <mailto:moderator@host.com?subject=list%20posting>
List-Post: NO (posting not allowed on this list)
List-Post: <https://groups.google.com/group/golang-dev/post>, <mailto:golang-dev@googlegroups.com>
*/
s = strings.TrimSpace(s)
if !strings.HasPrefix(s, "<mailto:") {
return nil
for s != "" {
if !strings.HasPrefix(s, "<") {
return nil
}
addr, ns, found := strings.Cut(s[1:], ">")
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
}

View file

@ -45,5 +45,6 @@ func TestParseListPostAddress(t *testing.T) {
check("<mailto:moderator@host.com> (Postings are Moderated)", &MessageAddress{User: "moderator", Domain: dns.Domain{ASCII: "host.com"}})
check("<mailto:moderator@host.com?subject=list%20posting>", &MessageAddress{User: "moderator", Domain: dns.Domain{ASCII: "host.com"}})
check("NO (posting not allowed on this list)", nil)
check("<https://groups.google.com/group/golang-dev/post>, <mailto:golang-dev@googlegroups.com>", &MessageAddress{User: "golang-dev", Domain: dns.Domain{ASCII: "googlegroups.com"}})
check("", nil)
}