-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
48 lines (40 loc) · 879 Bytes
/
utils.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
47
48
package sendmail
import (
"encoding/base64"
"fmt"
"strings"
)
// CRLF represents Carriage-Return Line-Feed
const CRLF = "\r\n"
var (
base64Encode = base64.StdEncoding.EncodeToString
)
func validateLine(line string) bool {
flag := true
if line == "" || strings.ContainsAny(line, CRLF) {
flag = false
}
return flag
}
func addr(host string, port int) string {
return fmt.Sprintf("%s:%d", host, port)
}
func utf8B(str string) string {
return fmt.Sprintf("=?utf-8?B?%s?=", base64Encode([]byte(str)))
}
func contactEmailName(email, name string) string {
if name != "" {
name = utf8B(name) + " "
}
return name + "<" + email + ">"
}
func mergeEmails(emails map[string]string) string {
result := ""
for email, name := range emails {
result += contactEmailName(email, name) + ", "
}
if result != "" {
result = result[0 : len(result)-2]
}
return result
}