1+ package reptile
2+
13/**
24 *
35 * @Description:
911 * @Package:
1012 * @Software: GoLand
1113 */
12- package reptile
1314
1415import (
16+ "encoding/base64"
17+ "errors"
1518 "github.com/antchfx/htmlquery"
1619 "github.com/chromedp/cdproto/page"
1720 "github.com/chromedp/chromedp"
1821 "math"
1922 "net/http"
23+ "net/mail"
24+ "strings"
2025 "time"
2126 "tool-gin/utils"
2227)
2328
29+ // DecodeMail 解码邮件内容 https://github.com/alexcesaro/quotedprintable
30+ func DecodeMail (msg * mail.Message ) ([]byte , error ) {
31+ body := utils .BytesToStringByBuffer (msg .Body )
32+ if len (body ) == 0 || body == "" {
33+ return nil , errors .New ("邮件内容不正确" )
34+ }
35+ encoding := msg .Header .Get ("Content-Transfer-Encoding" )
36+ // 解码,邮件协议Content-Transfer-Encoding指定了编码方式
37+ if encoding == "base64" {
38+ body , err := base64 .StdEncoding .DecodeString (body )
39+ return body , err
40+ }
41+ return nil , errors .New ("解码方式错误:" + encoding )
42+ }
43+
2444const LinShiYouXiang = "https://www.linshiyouxiang.net"
2545
26- // 获取邮箱号后缀
46+ // LinShiYouXiangSuffix 获取邮箱号后缀
2747func LinShiYouXiangSuffix () (string , error ) {
2848 var suffixArray []string
2949 response , err := utils .HttpRequest (http .MethodGet , LinShiYouXiang , "" , nil , nil )
@@ -46,7 +66,7 @@ func LinShiYouXiangSuffix() (string, error) {
4666 return suffixArray [utils .RandIntn (len (suffixArray )- 1 )], nil
4767}
4868
49- // 获取邮箱号
69+ // LinShiYouXiangApply 获取邮箱号
5070// prefix: 邮箱前缀
5171func LinShiYouXiangApply (prefix string ) (map [string ]interface {}, error ) {
5272 url := LinShiYouXiang + "/api/v1/mailbox/keepalive"
@@ -58,14 +78,14 @@ func LinShiYouXiangApply(prefix string) (map[string]interface{}, error) {
5878 return utils .HttpReadBodyJsonMap (http .MethodGet , url , "" , param , nil )
5979}
6080
61- // 获取邮件列表
81+ // LinShiYouXiangList 获取邮件列表
6282// prefix: 邮箱前缀
6383func LinShiYouXiangList (prefix string ) ([]map [string ]interface {}, error ) {
6484 url := LinShiYouXiang + "/api/v1/mailbox/" + prefix
6585 return utils .HttpReadBodyJsonArray (http .MethodGet , url , "" , nil , nil )
6686}
6787
68- // 获取邮件内容
88+ // LinShiYouXiangGetMail 获取邮件内容
6989// prefix: 邮箱前缀
7090// id: 邮件编号
7191//
@@ -76,12 +96,18 @@ func LinShiYouXiangList(prefix string) ([]map[string]interface{}, error) {
7696// htmlText, err := base64.StdEncoding.DecodeString(text[1])
7797// 解析HTML
7898// doc, err := goquery.NewDocumentFromReader(bytes.NewReader(htmlText))
79- func LinShiYouXiangGetMail (prefix , id string ) (string , error ) {
99+ func LinShiYouXiangGetMail (prefix , id string ) (* mail. Message , error ) {
80100 url := LinShiYouXiang + "/mailbox/" + prefix + "/" + id + "/source"
81- return utils .HttpReadBodyString (http .MethodGet , url , "" , nil , nil )
101+ content , err := utils .HttpReadBodyString (http .MethodGet , url , "" , nil , nil )
102+ if err != nil {
103+ return nil , err
104+ }
105+ r := strings .NewReader (content )
106+ m , err := mail .ReadMessage (r ) // 解析邮件
107+ return m , err
82108}
83109
84- // 删除邮件
110+ // LinShiYouXiangDelete 删除邮件
85111// prefix: 邮箱前缀
86112// id: 邮件编号
87113func LinShiYouXiangDelete (prefix , id string ) (map [string ]interface {}, error ) {
0 commit comments