-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
25 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
} |