From 5d46a0e45567fb59b7638433d3c97528e0dbabf7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=B6=E5=A3=AB=E6=B6=B5?= <630892807@qq.com>
Date: Sun, 10 May 2020 01:59:07 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86gbk=E4=B9=B1=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
server.go | 3 +++
tmpl/index.html | 4 ++--
tools/imap.go | 17 +++++++++++++++++
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/server.go b/server.go
index d0bbdb4..d9fd7bf 100644
--- a/server.go
+++ b/server.go
@@ -15,6 +15,7 @@ type IndexData struct {
Folders map[string]int
Mails interface{}
CurrentPage int
+ Fid string
NextPage,PrePage string
NumPages template.HTML
@@ -89,6 +90,8 @@ func list(w http.ResponseWriter, r *http.Request) {
defer wg.Done()
folders :=tools.GetFolders(authStrings[0], authStrings[1], authStrings[2],fid)
render.Folders = folders
+ render.Fid = fid
+
PageCount:= render.Folders[fid]/PAGE_SIZE
log.Println(PageCount)
numPages:=""
diff --git a/tmpl/index.html b/tmpl/index.html
index fcd82ab..0fae8d7 100644
--- a/tmpl/index.html
+++ b/tmpl/index.html
@@ -32,10 +32,10 @@
- - 邮件列表
+ - [{{.Fid}}]邮件列表
{{ range $key, $value := .Mails}}
-
- {{$value}}
+ {{$value}}{{if eq $value "" }}无标题{{end}}
{{end}}
diff --git a/tools/imap.go b/tools/imap.go
index c484d8f..7e936cf 100644
--- a/tools/imap.go
+++ b/tools/imap.go
@@ -104,6 +104,9 @@ func GetFolderMail(server string, email string, password string,folder string,cu
mbox, _ := c.Select(folder, true)
to := mbox.Messages-uint32((currentPage-1)*pagesize)
from := to-uint32(pagesize)
+ if to <=uint32(pagesize){
+ from=1
+ }
seqset := new(imap.SeqSet)
seqset.AddRange(from, to)
@@ -126,6 +129,19 @@ func GetFolderMail(server string, email string, password string,folder string,cu
//ret:=bytes.NewReader(content)
//ret:=transform.NewReader(bytes.NewReader(content), simplifiedchinese.HZGB2312.NewEncoder())
+ utf8str:=ConvertToStr(string(content),"gbk","utf-8")
+ t:=bytes.NewReader([]byte(utf8str))
+ //ret:=utf8.DecodeRune(t)
+ //log.Println(ret)
+ return t, nil
+ case "gbk":
+ content, err := ioutil.ReadAll(input)
+ if err != nil {
+ return nil, err
+ }
+ //ret:=bytes.NewReader(content)
+ //ret:=transform.NewReader(bytes.NewReader(content), simplifiedchinese.HZGB2312.NewEncoder())
+
utf8str:=ConvertToStr(string(content),"gbk","utf-8")
t:=bytes.NewReader([]byte(utf8str))
//ret:=utf8.DecodeRune(t)
@@ -150,6 +166,7 @@ func GetFolderMail(server string, email string, password string,folder string,cu
}
}
for msg:=range messages{
+
ret,err:=dec.Decode(msg.Envelope.Subject)
if err!=nil{
ret,_=dec.DecodeHeader(msg.Envelope.Subject)