aboutsummaryrefslogtreecommitdiffstats
path: root/lib/parse/hyperlinks.go
diff options
context:
space:
mode:
authorVitaly Ovchinnikov <v@postbox.nz>2023-09-12 21:19:12 +0000
committerRobin Jarry <robin@jarry.cc>2023-09-19 01:20:11 +0200
commit8f15b804d1a760d4f4e5c0c47a8a26ee2c04a830 (patch)
tree12926fa183e53a65154b16e767e524feaeff490a /lib/parse/hyperlinks.go
parentd57aa9e582f1644e2ee260c5c18fbf974dcc03ee (diff)
downloadaerc-8f15b804d1a760d4f4e5c0c47a8a26ee2c04a830.tar.gz
hyperlinks: better parsing of emails without mailto prefixes
Add some new tests from the emails I have and make them work by adjusting the code that looks for hyperlinks. The idea is to treat "inline" emails (those without mailto:) a little bit different and stop a little earlier while looking for their ends. Signed-off-by: Vitaly Ovchinnikov <v@postbox.nz> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/parse/hyperlinks.go')
-rw-r--r--lib/parse/hyperlinks.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/parse/hyperlinks.go b/lib/parse/hyperlinks.go
index dd334dd4..1200f936 100644
--- a/lib/parse/hyperlinks.go
+++ b/lib/parse/hyperlinks.go
@@ -37,6 +37,9 @@ func HttpLinks(r io.Reader) (io.Reader, []string) {
scheme = j - i
j = scheme
+ // "inline" email without a mailto: prefix - add some extra checks for those
+ inlineEmail := len(match) > 4 && match[2] == -1 && match[4] == -1
+
for !emitUrl && j < len(b) && bytes.IndexByte(urichars, b[j]) != -1 {
switch b[j] {
case '[':
@@ -69,9 +72,21 @@ func HttpLinks(r io.Reader) (io.Reader, []string) {
} else {
j++
}
+ case '&':
+ if inlineEmail {
+ emitUrl = true
+ } else {
+ j++
+ }
default:
j++
}
+
+ // we don't want those in inline emails
+ if inlineEmail && (paren > 0 || ltgt > 0 || bracket > 0) {
+ j--
+ emitUrl = true
+ }
}
// Heuristic to remove trailing characters that are
@@ -91,7 +106,7 @@ func HttpLinks(r io.Reader) (io.Reader, []string) {
continue
}
url := string(b[:j])
- if match[2] == -1 && match[4] == -1 {
+ if inlineEmail {
// Email address with missing mailto: scheme. Add it.
url = "mailto:" + url
}