I have a bunch of emails that I decided to process in Go. Go parse everything (headers, multipart) very well.
How do I convert all emails text to UTF-8
?
I read encoding name from Content-Type
field and parse it with mime.ParseMediaType
I believe some emails may have bugs in encodings. e.g. wrong encoding or multiple encodings in single body.
So if there is single wrong character but 99% of text is readable. I wish to be able to read it.
PS
There are libs in go to work with charset. https://godoc.org/code.google.com/p/go.text/encoding
and a set of iconv
wrappers like https://github.com/djimenez/iconv-go
I think first lacks encodings and it does give decoder by encoding name. I am not sure sure that I know all synonyms of encodings. e.g. UTF-8 and utf8 are same encoding. Windows-1251 and CP-1251 are same also.
Second is iconv wrapper. Go is secure language and that is why I wish to do that in Go. There is no buffer overflow. But iconv
is written in C and is less secure. I do