解决没有mailreader时崩溃问题

pull/30/head
陶士涵 4 years ago
parent af503b77b9
commit bd93b64dbb

@ -24,11 +24,9 @@
### 安装使用
1.git clone https://github.com/taoshihan1991/imaptool.git
1.在$GOPATH的src/github.com下 git clone https://github.com/taoshihan1991/imaptool.git
2.进入目录执行 go mod tidy
2.源码运行 go run server.go
3.源码运行 go run server.go
4.源码打包 go build server.go
3.源码打包 go build server.go

@ -179,15 +179,15 @@ func GetMessage(server string, email string, password string, folder string, id
if r == nil {
log.Fatal("Server didn't returned message body")
}
var mailitem = new(MailItem)
// Create a new mail reader
mr, err := mail.CreateReader(r)
if err != nil {
//log.Fatal(err)
return mailitem
}
var mailitem = new(MailItem)
// Print some info about the message
header := mr.Header
date, _ := header.Date()
@ -226,9 +226,9 @@ func GetMessage(server string, email string, password string, folder string, id
log.Println("Subject:", s)
mailitem.Subject = s
// Process each message's part
var bodyMap=make(map[string]string)
bodyMap["text/plain"]= ""
bodyMap["text/html"]= ""
var bodyMap = make(map[string]string)
bodyMap["text/plain"] = ""
bodyMap["text/html"] = ""
for {
p, err := mr.NextPart()
@ -242,11 +242,11 @@ func GetMessage(server string, email string, password string, folder string, id
// This is the message's text (can be plain-text or HTML)
b, _ := ioutil.ReadAll(p.Body)
ct:=p.Header.Get("Content-Type")
if strings.Contains(ct,"text/plain"){
bodyMap["text/plain"]+=Encoding(string(b),ct)
}else{
bodyMap["text/html"]+=Encoding(string(b),ct)
ct := p.Header.Get("Content-Type")
if strings.Contains(ct, "text/plain") {
bodyMap["text/plain"] += Encoding(string(b), ct)
} else {
bodyMap["text/html"] += Encoding(string(b), ct)
}
//body,_:=dec.Decode(string(b))
case *mail.AttachmentHeader:
@ -256,10 +256,10 @@ func GetMessage(server string, email string, password string, folder string, id
}
}
if bodyMap["text/html"]!=""{
mailitem.Body =bodyMap["text/html"]
}else{
mailitem.Body =bodyMap["text/plain"]
if bodyMap["text/html"] != "" {
mailitem.Body = bodyMap["text/html"]
} else {
mailitem.Body = bodyMap["text/plain"]
}
//log.Println(mailitem.Body)
return mailitem

@ -1,4 +1,4 @@
package main
package tools
import (
"bufio"
@ -23,7 +23,7 @@ var (
folders map[int]string
)
func main() {
func testmain() {
//获取参数中的数据
flag.StringVar(&server, "server", "", "imap服务地址(包含端口)")
Loading…
Cancel
Save