新增html模板

pull/30/head
unknown 5 years ago
parent 7af66e799d
commit 5eb5f1b1c3

@ -137,69 +137,72 @@ func main() {
if err := <-done; err != nil {
log.Fatal(err)
}
log.Println("读取第几封信信体:")
inLine = readLineFromInput()
mesIndex, _ := strconv.Atoi(inLine)
mesSeqSet := new(imap.SeqSet)
mesSeqSet.AddNum(uint32(mesIndex))
//获取整封信体
var section imap.BodySectionName
items := []imap.FetchItem{section.FetchItem()}
messages = make(chan *imap.Message, 1)
go func() {
if err := c.Fetch(mesSeqSet, items, messages); err != nil {
log.Fatal(err)
}
}()
msg := <-messages
if msg == nil {
log.Fatal("服务器没有返回信息")
}
r := msg.GetBody(&section)
if r == nil {
log.Fatal("服务器没有返回 message body")
}
mr, err := mail.CreateReader(r)
if err != nil {
log.Fatal(err)
}
//打印信息
header := mr.Header
if date, err := header.Date(); err == nil {
log.Println("Date:", date)
}
if from, err := header.AddressList("From"); err == nil {
log.Println("From:", from)
}
if to, err := header.AddressList("To"); err == nil {
log.Println("To:", to)
}
if subject, err := header.Subject(); err == nil {
log.Println("Subject:", subject)
}
// Process each message's part
for {
p, err := mr.NextPart()
if err == io.EOF {
break
} else if err != nil {
log.Println("读取第几封信信体:")
inLine = readLineFromInput()
mesIndex, _ := strconv.Atoi(inLine)
mesSeqSet := new(imap.SeqSet)
mesSeqSet.AddNum(uint32(mesIndex))
//获取整封信体
var section imap.BodySectionName
items := []imap.FetchItem{section.FetchItem()}
bodyMsg := make(chan *imap.Message, 1)
go func() {
if err := c.Fetch(mesSeqSet, items, bodyMsg); err != nil {
log.Fatal(err)
}
}()
msg := <-bodyMsg
if msg == nil {
log.Fatal("服务器没有返回信息")
}
r := msg.GetBody(&section)
if r == nil {
log.Fatal("服务器没有返回 message body")
}
mr, err := mail.CreateReader(r)
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.Printf("Got text: %s\n", string(b))
case *mail.AttachmentHeader:
// This is an attachment
filename, _ := h.Filename()
log.Printf("Got attachment: %s\n", filename)
//打印信息
header := mr.Header
if date, err := header.Date(); err == nil {
log.Println("Date:", date)
}
if from, err := header.AddressList("From"); err == nil {
log.Println("From:", from)
}
if to, err := header.AddressList("To"); err == nil {
log.Println("To:", to)
}
if subject, err := header.Subject(); err == nil {
log.Println("Subject:", subject)
}
// 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.Printf("Got text: %s\n", string(b))
case *mail.AttachmentHeader:
// This is an attachment
filename, _ := h.Filename()
log.Printf("Got attachment: %s\n", filename)
}
}
log.Printf("读取第 %d 封信, 结束!\n", mesIndex)
}
log.Println("结束!")
}
//从输入中读取一行

@ -0,0 +1,19 @@
package main
import (
"html/template"
"log"
"net/http"
)
func main(){
log.Println("listen on 8080...")
http.HandleFunc("/",index)
//监听端口
http.ListenAndServe(":8080", nil)
}
//输出首页
func index(w http.ResponseWriter, r *http.Request){
t,_:=template.ParseFiles("./tmpl/index.html")
t.Execute(w, nil)
}

@ -0,0 +1 @@
<h1>hello</h1>
Loading…
Cancel
Save