Maison >développement back-end >Golang >Analyser les e-mails à l'aide de net/mail
J'utilise actuellement net/mail
dans Golang pour analyser les e-mails.
import ( "net/mail" "io" "strings" ) func main() { email := "some email received" reader := strings.newreader(emailinput) msg, err := mail.readmessage(inputreader) check(err) body, err := io.readall(msg.body) check(err) fmt.println(string(body)) }
Cela fonctionne très bien pour les e-mails en texte brut. Cependant, lorsque j'envoie un e-mail à l'aide de l'application Apple Mail contenant du HTML, le corps suivant est renvoyé :
--Apple-Mail=3D_4A1E75FB-9514-439D-B922-8526851CA743 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=3Dus-ascii fn main() { println!("Hello world!"); } --Apple-Mail=3D_4A1E75FB-9514-439D-B922-8526851CA743 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=3Dus-ascii <html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; charset= =3Dus-ascii"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode= : space; line-break: after-white-space;" class=3D""><pre class=3D"" style= =3D"color: rgb(209, 209, 209); background-color: rgb(0, 0, 0);">fn <span cl= ass=3D"" style=3D"color: rgb(230, 97, 112); font-weight: bold;">main</span>= <span class=3D"" style=3D"color: rgb(210, 205, 134);">(</span><span class= =3D"" style=3D"color: rgb(210, 205, 134);">)</span> <span class=3D"" style= =3D"color: rgb(176, 96, 176);">{</span> println<span class=3D"" style=3D"color: rgb(210, 205, 134);">!</span><spa= n class=3D"" style=3D"color: rgb(210, 205, 134);">(</span><span class=3D"" = style=3D"color: rgb(2, 208, 69);">"</span><span class=3D"" style=3D"color: = rgb(0, 196, 196);">Hello world!</span><span class=3D"" style=3D"color: rgb(= 2, 208, 69);">"</span><span class=3D"" style=3D"color: rgb(210, 205, 134);"= >)</span><span class=3D"" style=3D"color: rgb(176, 96, 176);">;</span> <span class=3D"" style=3D"color: rgb(176, 96, 176);">}</span>