获取邮件内容

pull/30/head
taoshihan1991 5 years ago
parent 413cbc07ce
commit 77c4afc8e5

@ -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)

@ -60,7 +60,7 @@ func RenderView(w http.ResponseWriter,render interface{}){
</tr>
<tr>
<th scope="row">:</th>
<td>Jacob</td>
<td>{{.HtmlBody}}</td>
</tr>
</tbody>
</table>

@ -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{

@ -14,6 +14,7 @@ type IndexData struct {
}
type ViewData struct {
Folders map[string]int
HtmlBody template.HTML
MailItem
}
type MailItem struct{

Loading…
Cancel
Save