mirror of
https://github.com/axllent/mailpit.git
synced 2026-03-03 03:57:01 +00:00
Fix: Support angle brackets for text/plain URLs with spaces (#535)
This commit is contained in:
@@ -31,7 +31,14 @@ var (
|
||||
</html>`
|
||||
|
||||
expectedHTMLLinks = []string{
|
||||
"http://example.com", "https://example.com", "HTTPS://EXAMPLE.COM", "http://localhost", "https://localhost", "https://127.0.0.1", "http://link with spaces", "http://example.com/?blaah=yes&test=true",
|
||||
"http://example.com",
|
||||
"https://example.com",
|
||||
"HTTPS://EXAMPLE.COM",
|
||||
"http://localhost",
|
||||
"https://localhost",
|
||||
"https://127.0.0.1",
|
||||
"http://link with spaces",
|
||||
"http://example.com/?blaah=yes&test=true",
|
||||
"http://remote-host/style.css", // css
|
||||
"https://example.com/image.jpg", // images
|
||||
}
|
||||
@@ -41,10 +48,18 @@ var (
|
||||
[http://localhost]
|
||||
www.google.com < ignored
|
||||
|||http://example.com/?some=query-string|||
|
||||
// RFC2396 appendix E states angle brackets are recommended for text/plain emails to
|
||||
// recognize potential spaces in between the URL
|
||||
<https://example.com/ link with spaces>
|
||||
`
|
||||
|
||||
expectedTextLinks = []string{
|
||||
"http://example.com", "https://example.com", "HTTPS://EXAMPLE.COM", "http://localhost", "http://example.com/?some=query-string",
|
||||
"http://example.com",
|
||||
"https://example.com",
|
||||
"HTTPS://EXAMPLE.COM",
|
||||
"http://localhost",
|
||||
"http://example.com/?some=query-string",
|
||||
"https://example.com/ link with spaces",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -30,9 +30,28 @@ func RunTests(msg *storage.Message, followRedirects bool) (Response, error) {
|
||||
}
|
||||
|
||||
func extractTextLinks(msg *storage.Message) []string {
|
||||
testLinkRe := regexp.MustCompile(`(?im)([^<]\b)((http|https):\/\/([\-\w@:%_\+'!.~#?,&\/\/=;]+))`)
|
||||
// RFC2396 appendix E states angle brackets are recommended for text/plain emails to
|
||||
// recognize potential spaces in between the URL
|
||||
// @see https://www.rfc-editor.org/rfc/rfc2396#appendix-E
|
||||
bracketLinkRe := regexp.MustCompile(`(?im)<((http|https):\/\/([\-\w@:%_\+'!.~#?,&\/\/=;][^>]+))>`)
|
||||
|
||||
links := []string{}
|
||||
|
||||
links = append(links, linkRe.FindAllString(msg.Text, -1)...)
|
||||
matches := testLinkRe.FindAllStringSubmatch(msg.Text, -1)
|
||||
for _, match := range matches {
|
||||
if len(match) > 0 {
|
||||
links = append(links, match[2])
|
||||
}
|
||||
}
|
||||
|
||||
angleMatches := bracketLinkRe.FindAllStringSubmatch(msg.Text, -1)
|
||||
for _, match := range angleMatches {
|
||||
if len(match) > 0 {
|
||||
link := strings.ReplaceAll(match[1], "\n", "")
|
||||
links = append(links, link)
|
||||
}
|
||||
}
|
||||
|
||||
return links
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user