实现编码转换测试

pull/30/head
taoshihan1991 4 years ago
parent 525a140fb3
commit e8f687d23d

@ -7,4 +7,6 @@ require github.com/emersion/go-imap v1.0.4
require (
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394
github.com/emersion/go-message v0.11.2
golang.org/x/net v0.0.0-20200513185701-a91f0712d120
golang.org/x/text v0.3.2
)

@ -19,6 +19,12 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20200513185701-a91f0712d120 h1:EZ3cVSzKOlJxAd8e8YAJ7no8nNypTxexh/YE/xW3ZEY=
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

@ -60,7 +60,9 @@ func RenderView(w http.ResponseWriter,render interface{}){
</tr>
<tr>
<th scope="row">:</th>
<td>{{.HtmlBody}}</td>
<td>
{{.HtmlBody}}
</td>
</tr>
</tbody>
</table>

@ -239,6 +239,7 @@ func GetMessage(server string, email string, password string,folder string,id ui
filename, _ := h.Filename()
log.Println("Got attachment: ", filename)
}
mailitem.Body=Encoding(mailitem.Body)
}
return mailitem
}

@ -1,6 +1,14 @@
// stringutil 包含有用于处理字符串的工具函数。
package tools
import (
"golang.org/x/net/html/charset"
"golang.org/x/text/transform"
"io/ioutil"
"log"
"strings"
)
// Reverse 将其实参字符串以符文为单位左右反转。
func Reverse(s string) string {
r := []rune(s)
@ -9,3 +17,14 @@ func Reverse(s string) string {
}
return string(r)
}
//转换编码
func Encoding(html string)string {
e,_,_ :=charset.DetermineEncoding([]byte(html),"")
r:=strings.NewReader(html)
log.Println(r);
utf8Reader := transform.NewReader(r,e.NewDecoder())
//将其他编码的reader转换为常用的utf8reader
all,_ := ioutil.ReadAll(utf8Reader)
return string(all)
}

Loading…
Cancel
Save