From 77c4afc8e52b933e0170b59230511eddba6a13e6 Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Thu, 14 May 2020 19:27:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=82=AE=E4=BB=B6=E5=86=85?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.go | 1 + tmpl/view.go | 2 +- tools/imap.go | 39 ++++++++++++++++++++------------------- tools/types.go | 1 + 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/server.go b/server.go index df435e6..6b36158 100644 --- a/server.go +++ b/server.go @@ -153,6 +153,7 @@ func view(w http.ResponseWriter, r *http.Request) { render.To=mail.To render.Subject=mail.Subject render.Date=mail.Date + render.HtmlBody=template.HTML(mail.Body) }() wg.Wait() tmpl.RenderView(w,render) diff --git a/tmpl/view.go b/tmpl/view.go index 57e07bf..690a75d 100644 --- a/tmpl/view.go +++ b/tmpl/view.go @@ -60,7 +60,7 @@ func RenderView(w http.ResponseWriter,render interface{}){ 内容: - Jacob + {{.HtmlBody}} diff --git a/tools/imap.go b/tools/imap.go index e3eb0cb..919003d 100644 --- a/tools/imap.go +++ b/tools/imap.go @@ -217,25 +217,26 @@ func GetMessage(server string, email string, password string,folder string,id ui mailitem.Subject=s } // Process each message's part - //for { - // p, err := mr.NextPart() - // if err == io.EOF { - // break - // } else if err != nil { - // log.Fatal(err) - // } - // - // switch h := p.Header.(type) { - // case *mail.InlineHeader: - // // This is the message's text (can be plain-text or HTML) - // b, _ := ioutil.ReadAll(p.Body) - // log.Println("Got text: ", string(b)) - // case *mail.AttachmentHeader: - // // This is an attachment - // filename, _ := h.Filename() - // log.Println("Got attachment: ", filename) - // } - //} + for { + p, err := mr.NextPart() + if err == io.EOF { + break + } else if err != nil { + //log.Fatal(err) + } + switch h := p.Header.(type) { + case *mail.InlineHeader: + // This is the message's text (can be plain-text or HTML) + b, _ := ioutil.ReadAll(p.Body) + mailitem.Body+=string(b) + //body,_:=dec.Decode(string(b)) + log.Println("Got text: ", string(b)) + case *mail.AttachmentHeader: + // This is an attachment + filename, _ := h.Filename() + log.Println("Got attachment: ", filename) + } + } return mailitem } func GetDecoder()*mime.WordDecoder{ diff --git a/tools/types.go b/tools/types.go index 8c3cdf3..fb89957 100644 --- a/tools/types.go +++ b/tools/types.go @@ -14,6 +14,7 @@ type IndexData struct { } type ViewData struct { Folders map[string]int + HtmlBody template.HTML MailItem } type MailItem struct{