fix parsing List-Post header in webmail

This commit is contained in:
Mechiel Lukkien 2023-09-11 11:55:28 +02:00
parent f6d03a0eab
commit fc7b0cc71e
No known key found for this signature in database
2 changed files with 25 additions and 4 deletions

View file

@ -316,12 +316,12 @@ func parseListPostAddress(s string) *MessageAddress {
if !strings.HasPrefix(s, "<mailto:") { if !strings.HasPrefix(s, "<mailto:") {
return nil return nil
} }
s = strings.TrimPrefix(s, "<mailto:") s = s[1:]
t := strings.SplitN(s, ">", 2) s, _, found := strings.Cut(s, ">")
if len(t) != 2 { if !found {
return nil return nil
} }
u, err := url.Parse(t[0]) u, err := url.Parse(s)
if err != nil { if err != nil {
return nil return nil
} }

21
webmail/message_test.go Normal file
View file

@ -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("<mailto:list@host.com>", &MessageAddress{User: "list", Domain: dns.Domain{ASCII: "host.com"}})
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("", nil)
}