-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathheader.go
46 lines (41 loc) · 837 Bytes
/
header.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Header parsing functionality.
package emlparser
import (
"strings"
)
func split(ts []token, s token) [][]token {
r, l := [][]token{}, 0
for i, t := range ts {
if string(t) == string(s) {
r = append(r, ts[l:i])
l = i + 1
}
}
if l != len(ts) {
r = append(r, ts[l:len(ts)])
}
return r
}
// BUG: We don't currently support domain literals with commas.
func parseAddressList(s []byte) ([]Address, error) {
al := []Address{}
ts, e := tokenize(s)
if e != nil {
return al, e
}
tts := split(ts, []byte{','})
for _, ts := range tts {
a, e := parseAddress(ts)
if e != nil {
return al, e
}
al = append(al, a)
}
return al, nil
}
func decodeRFC2047(word string) string {
if strings.HasPrefix(word, "=?") && strings.HasSuffix(word, "?=") && strings.Count(word, "?") == 4 {
return ""
}
return word
}