Skip to content

Commit

Permalink
webmail: recognize multiple urls in List-Post addresses
Browse files Browse the repository at this point in the history
there may be a http(s)-address, which we'll ignore. the mailto may come after
that. like in google groups.
  • Loading branch information
mjl- committed Apr 16, 2024
1 parent 8654a1f commit 8bcce40
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
40 changes: 24 additions & 16 deletions webmail/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,23 +369,31 @@ func parseListPostAddress(s string) *MessageAddress {
List-Post: <mailto:[email protected]> (Postings are Moderated)
List-Post: <mailto:[email protected]?subject=list%20posting>
List-Post: NO (posting not allowed on this list)
List-Post: <https://groups.google.com/group/golang-dev/post>, <mailto:[email protected]>
*/
s = strings.TrimSpace(s)
if !strings.HasPrefix(s, "<mailto:") {
return nil
}
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
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)
}
return &MessageAddress{User: addr.Localpart.String(), Domain: addr.Domain}
return nil
}
1 change: 1 addition & 0 deletions webmail/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ func TestParseListPostAddress(t *testing.T) {
check("<mailto:[email protected]> (Postings are Moderated)", &MessageAddress{User: "moderator", Domain: dns.Domain{ASCII: "host.com"}})
check("<mailto:[email protected]?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:[email protected]>", &MessageAddress{User: "golang-dev", Domain: dns.Domain{ASCII: "googlegroups.com"}})
check("", nil)
}

0 comments on commit 8bcce40

Please sign in to comment.