-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.go
39 lines (32 loc) · 913 Bytes
/
shared.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
package googlemail
import (
"regexp"
"google.golang.org/api/gmail/v1"
"github.com/wakflo/go-sdk/autoform"
sdkcore "github.com/wakflo/go-sdk/core"
)
var (
// #nosec
tokenURL = "https://oauth2.googleapis.com/token"
sharedAuth = autoform.NewOAuthField("https://accounts.google.com/o/oauth2/auth", &tokenURL, []string{
"https://mail.google.com/",
}).Build()
)
var viewMailFormat = []*sdkcore.AutoFormSchema{
{Const: "full", Title: "Full"},
{Const: "minimal", Title: "Minimal"},
{Const: "raw", Title: "Raw"},
{Const: "metadata", Title: "Metadata"},
}
func isValidEmail(email string) bool {
emailRegex := regexp.MustCompile(`^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`)
return emailRegex.MatchString(email)
}
func getHeader(headers []*gmail.MessagePartHeader, name string) string {
for _, header := range headers {
if header.Name == name {
return header.Value
}
}
return ""
}