mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 16:33:47 +03:00
fix parsing List-Post header in webmail
This commit is contained in:
parent
f6d03a0eab
commit
fc7b0cc71e
2 changed files with 25 additions and 4 deletions
|
@ -316,12 +316,12 @@ func parseListPostAddress(s string) *MessageAddress {
|
|||
if !strings.HasPrefix(s, "<mailto:") {
|
||||
return nil
|
||||
}
|
||||
s = strings.TrimPrefix(s, "<mailto:")
|
||||
t := strings.SplitN(s, ">", 2)
|
||||
if len(t) != 2 {
|
||||
s = s[1:]
|
||||
s, _, found := strings.Cut(s, ">")
|
||||
if !found {
|
||||
return nil
|
||||
}
|
||||
u, err := url.Parse(t[0])
|
||||
u, err := url.Parse(s)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
|
21
webmail/message_test.go
Normal file
21
webmail/message_test.go
Normal 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)
|
||||
}
|
Loading…
Reference in a new issue