处理gbk乱码

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

@ -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:=""

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

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

Loading…
Cancel
Save