chore: migrate mail themes to shared framework and locked upstream inputs
This commit is contained in:
1 parent
5c0589f6f6
commit
fec3ace600
225 files changed
+4718
-15807
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"golang.org/x/net/html"
|
||||
"io"
|
||||
)
|
||||
|
||||
func BodyAnchors(masked []byte) ([2]int, error) {
|
||||
var anchors [2]int
|
||||
opens, closes, offset := 0, 0, 0
|
||||
z := html.NewTokenizer(bytes.NewReader(masked))
|
||||
for {
|
||||
kind := z.Next()
|
||||
raw := z.Raw()
|
||||
start := offset
|
||||
offset += len(raw)
|
||||
switch kind {
|
||||
case html.ErrorToken:
|
||||
if z.Err() != io.EOF {
|
||||
return anchors, z.Err()
|
||||
}
|
||||
if opens != 1 || closes != 1 || anchors[0] >= anchors[1] {
|
||||
return anchors, fmt.Errorf("expected exactly one static body start and end")
|
||||
}
|
||||
return anchors, nil
|
||||
case html.StartTagToken:
|
||||
tag, _ := z.TagName()
|
||||
if bytes.Equal(tag, []byte("body")) {
|
||||
opens++
|
||||
anchors[0] = offset
|
||||
}
|
||||
case html.EndTagToken:
|
||||
tag, _ := z.TagName()
|
||||
if bytes.Equal(tag, []byte("body")) {
|
||||
closes++
|
||||
anchors[1] = start
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user