|
|
|
@ -14,6 +14,7 @@ import (
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//验证邮箱密码
|
|
|
|
|
func CheckEmailPassword(server string, email string, password string) bool {
|
|
|
|
|
if !strings.Contains(server, ":") {
|
|
|
|
@ -36,6 +37,7 @@ func CheckEmailPassword(server string, email string, password string) bool {
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取连接
|
|
|
|
|
func connect(server string, email string, password string) *client.Client {
|
|
|
|
|
var c *client.Client
|
|
|
|
@ -61,6 +63,7 @@ func connect(server string, email string, password string)*client.Client{
|
|
|
|
|
}
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取邮件夹
|
|
|
|
|
func GetFolders(server string, email string, password string, folder string) map[string]int {
|
|
|
|
|
var c *client.Client
|
|
|
|
@ -188,17 +191,18 @@ func GetMessage(server string, email string, password string,folder string,id ui
|
|
|
|
|
|
|
|
|
|
// Print some info about the message
|
|
|
|
|
header := mr.Header
|
|
|
|
|
if date, err := header.Date(); err == nil {
|
|
|
|
|
log.Println(header)
|
|
|
|
|
date, _ := header.Date()
|
|
|
|
|
log.Println("Date:", date)
|
|
|
|
|
mailitem.Date = date.String()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var f string
|
|
|
|
|
dec := GetDecoder()
|
|
|
|
|
|
|
|
|
|
if from, err := header.AddressList("From"); err == nil {
|
|
|
|
|
log.Println("From:", from)
|
|
|
|
|
for _, address := range from {
|
|
|
|
|
fromStr:=strings.ToLower(address.String())
|
|
|
|
|
fromStr := address.String()
|
|
|
|
|
temp, _ := dec.DecodeHeader(fromStr)
|
|
|
|
|
f += " " + temp
|
|
|
|
|
}
|
|
|
|
@ -208,22 +212,20 @@ func GetMessage(server string, email string, password string,folder string,id ui
|
|
|
|
|
if to, err := header.AddressList("To"); err == nil {
|
|
|
|
|
log.Println("To:", to)
|
|
|
|
|
for _, address := range to {
|
|
|
|
|
toStr:=strings.ToLower(address.String())
|
|
|
|
|
toStr := address.String()
|
|
|
|
|
temp, _ := dec.DecodeHeader(toStr)
|
|
|
|
|
t += " " + temp
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mailitem.To = t
|
|
|
|
|
|
|
|
|
|
if subject, err := header.Subject(); err == nil {
|
|
|
|
|
subject=strings.ToLower(subject)
|
|
|
|
|
subject, _ := header.Subject()
|
|
|
|
|
s, err := dec.Decode(subject)
|
|
|
|
|
if err != nil {
|
|
|
|
|
s, _ = dec.DecodeHeader(subject)
|
|
|
|
|
}
|
|
|
|
|
log.Println("Subject:", s)
|
|
|
|
|
mailitem.Subject = s
|
|
|
|
|
}
|
|
|
|
|
// Process each message's part
|
|
|
|
|
for {
|
|
|
|
|
p, err := mr.NextPart()
|
|
|
|
@ -243,7 +245,9 @@ func GetMessage(server string, email string, password string,folder string,id ui
|
|
|
|
|
filename, _ := h.Filename()
|
|
|
|
|
log.Println("Got attachment: ", filename)
|
|
|
|
|
}
|
|
|
|
|
mailitem.Body=Encoding(mailitem.Body)
|
|
|
|
|
ct,_,_:=header.ContentType()
|
|
|
|
|
log.Println(ct)
|
|
|
|
|
mailitem.Body = Encoding(mailitem.Body,ct)
|
|
|
|
|
}
|
|
|
|
|
return mailitem
|
|
|
|
|
}
|
|
|
|
@ -298,12 +302,14 @@ func GetDecoder()*mime.WordDecoder{
|
|
|
|
|
}
|
|
|
|
|
return dec
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 任意编码转特定编码
|
|
|
|
|
func ConvertToStr(src string, srcCode string, tagCode string) string {
|
|
|
|
|
srcCoder := mahonia.NewDecoder(srcCode)
|
|
|
|
|
srcResult := srcCoder.ConvertString(src)
|
|
|
|
|
tagCoder := mahonia.NewDecoder(tagCode)
|
|
|
|
|
_, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
|
|
|
|
|
result := string(cdata)
|
|
|
|
|
result := mahonia.NewDecoder(srcCode).ConvertString(src)
|
|
|
|
|
//srcCoder := mahonia.NewDecoder(srcCode)
|
|
|
|
|
//srcResult := srcCoder.ConvertString(src)
|
|
|
|
|
//tagCoder := mahonia.NewDecoder(tagCode)
|
|
|
|
|
//_, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
|
|
|
|
|
//result := string(cdata)
|
|
|
|
|
return result
|
|
|
|
|
}
|