邮件列表增加详情链接

pull/30/head
unknown 5 years ago
parent 086db15aff
commit d829d0db60

@ -12,15 +12,7 @@ import (
"sync"
)
type IndexData struct {
Folders map[string]int
Mails interface{}
CurrentPage int
Fid string
NextPage,PrePage string
NumPages template.HTML
}
const PAGE_SIZE=20
func main() {
log.Println("listen on 8080...")
@ -74,7 +66,7 @@ func list(w http.ResponseWriter, r *http.Request) {
auth := getCookie(r, "auth")
authStrings := strings.Split(auth, "|")
render := new(IndexData)
render := new(tools.IndexData)
render.CurrentPage = currentPage
var prePage int
if(currentPage-1) <=0 {
@ -93,14 +85,16 @@ func list(w http.ResponseWriter, r *http.Request) {
render.Folders = folders
render.Fid = fid
PageCount:= render.Folders[fid]/PAGE_SIZE
log.Println(PageCount)
//PageCount:= render.Folders[fid]/PAGE_SIZE
numPages:=""
start:=currentPage-5
if start <=0 {
start=1
}
end:=start+11
//if end>=PageCount{
// end=PageCount
//}
for i:=start;i<end;i++{
active:=""
@ -114,7 +108,7 @@ func list(w http.ResponseWriter, r *http.Request) {
go func() {
defer wg.Done()
mails := tools.GetFolderMail(authStrings[0], authStrings[1], authStrings[2], fid, currentPage, PAGE_SIZE)
render.Mails = mails
render.MailPagelist = mails
}()
wg.Wait()

@ -42,9 +42,11 @@ func RenderList(w http.ResponseWriter,render interface{}){
<div class="col-md-9">
<ul class="list-group">
<li class="list-group-item active">[{{.Fid}}]</li>
{{ range $key, $value := .Mails}}
{{ range .MailPagelist}}
<li class="list-group-item d-flex justify-content-between align-items-center">
{{$value}}{{if eq $value "" }}{{end}}
<a href="/view?fid={{.Fid}}&id={{.Id}}">
{{.Subject}}{{if eq .Subject "" }}{{end}}
</a>
</li>
{{end}}
</ul>

@ -93,7 +93,7 @@ func GetFolders(server string, email string, password string,folder string)map[s
}
//获取邮件夹邮件
func GetFolderMail(server string, email string, password string,folder string,currentPage int,pagesize int)[]string{
func GetFolderMail(server string, email string, password string,folder string,currentPage int,pagesize int)[]*MailItem{
var c *client.Client
//defer c.Logout()
c=connect(server,email,password)
@ -116,7 +116,7 @@ func GetFolderMail(server string, email string, password string,folder string,cu
go func() {
done <- c.Fetch(seqset, []imap.FetchItem{imap.FetchEnvelope}, messages)
}()
var res []string
var mailPagelist=new(MailPageList)
dec :=new(mime.WordDecoder)
dec.CharsetReader= func(charset string, input io.Reader) (io.Reader, error) {
@ -171,11 +171,15 @@ func GetFolderMail(server string, email string, password string,folder string,cu
if err!=nil{
ret,_=dec.DecodeHeader(msg.Envelope.Subject)
}
res=append(res,ret)
}
var mailitem =new(MailItem)
log.Println(msg.SeqNum)
log.Println(res)
return res
mailitem.Subject=ret
mailitem.Id=msg.SeqNum
mailitem.Fid=folder
mailPagelist.MailItems=append(mailPagelist.MailItems,mailitem)
}
return mailPagelist.MailItems
}
// 任意编码转特定编码
func ConvertToStr(src string, srcCode string, tagCode string) string {

@ -0,0 +1,22 @@
package tools
import "html/template"
type IndexData struct {
Folders map[string]int
Mails interface{}
MailPagelist []*MailItem
CurrentPage int
Fid string
NextPage,PrePage string
NumPages template.HTML
}
type MailItem struct{
Subject string
Id uint32
Fid string
}
type MailPageList struct{
MailItems []*MailItem
}
Loading…
Cancel
Save