处理gbk乱码

pull/30/head
陶士涵 5 years ago
parent 21a17ced91
commit 5d46a0e455

@ -15,6 +15,7 @@ type IndexData struct {
Folders map[string]int Folders map[string]int
Mails interface{} Mails interface{}
CurrentPage int CurrentPage int
Fid string
NextPage,PrePage string NextPage,PrePage string
NumPages template.HTML NumPages template.HTML
@ -89,6 +90,8 @@ func list(w http.ResponseWriter, r *http.Request) {
defer wg.Done() defer wg.Done()
folders :=tools.GetFolders(authStrings[0], authStrings[1], authStrings[2],fid) folders :=tools.GetFolders(authStrings[0], authStrings[1], authStrings[2],fid)
render.Folders = folders render.Folders = folders
render.Fid = fid
PageCount:= render.Folders[fid]/PAGE_SIZE PageCount:= render.Folders[fid]/PAGE_SIZE
log.Println(PageCount) log.Println(PageCount)
numPages:="" numPages:=""

@ -32,10 +32,10 @@
</div> </div>
<div class="col-md-9"> <div class="col-md-9">
<ul class="list-group"> <ul class="list-group">
<li class="list-group-item active">邮件列表</li> <li class="list-group-item active">[{{.Fid}}]邮件列表</li>
{{ range $key, $value := .Mails}} {{ range $key, $value := .Mails}}
<li class="list-group-item d-flex justify-content-between align-items-center"> <li class="list-group-item d-flex justify-content-between align-items-center">
{{$value}} {{$value}}{{if eq $value "" }}无标题{{end}}
</li> </li>
{{end}} {{end}}
</ul> </ul>

@ -104,6 +104,9 @@ func GetFolderMail(server string, email string, password string,folder string,cu
mbox, _ := c.Select(folder, true) mbox, _ := c.Select(folder, true)
to := mbox.Messages-uint32((currentPage-1)*pagesize) to := mbox.Messages-uint32((currentPage-1)*pagesize)
from := to-uint32(pagesize) from := to-uint32(pagesize)
if to <=uint32(pagesize){
from=1
}
seqset := new(imap.SeqSet) seqset := new(imap.SeqSet)
seqset.AddRange(from, to) seqset.AddRange(from, to)
@ -126,6 +129,19 @@ func GetFolderMail(server string, email string, password string,folder string,cu
//ret:=bytes.NewReader(content) //ret:=bytes.NewReader(content)
//ret:=transform.NewReader(bytes.NewReader(content), simplifiedchinese.HZGB2312.NewEncoder()) //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") utf8str:=ConvertToStr(string(content),"gbk","utf-8")
t:=bytes.NewReader([]byte(utf8str)) t:=bytes.NewReader([]byte(utf8str))
//ret:=utf8.DecodeRune(t) //ret:=utf8.DecodeRune(t)
@ -150,6 +166,7 @@ func GetFolderMail(server string, email string, password string,folder string,cu
} }
} }
for msg:=range messages{ for msg:=range messages{
ret,err:=dec.Decode(msg.Envelope.Subject) ret,err:=dec.Decode(msg.Envelope.Subject)
if err!=nil{ if err!=nil{
ret,_=dec.DecodeHeader(msg.Envelope.Subject) ret,_=dec.DecodeHeader(msg.Envelope.Subject)

Loading…
Cancel
Save