The following code (partial of the full code), creates a reader, then read the body of an email and store them into 'final body'. this final body is then passed into mongoldb for archiving. However, the message body that is read is quoted printable, and I want the body passed into mongodb to be decoded into utf8. how to implement quoted printable package into this code, and where exactly?
// Creates a reader.
mediaType, params, err := mime.ParseMediaType(contentType)
if err != nil {
log.Println("Unable to read the type of the content.")
log.Println(err)
return
}
reader := multipart.NewReader(msg.Body, params["boundary"])
// Reads the body
finalBody := ""
if strings.HasPrefix(mediaType, "multipart/") {
for {
p, err := reader.NextPart()
if err == io.EOF {
break
}
if err != nil {
log.Println(err)
return
}
slurp, err := ioutil.ReadAll(p)
if err != nil {
log.Println(err)
return
}
finalBody += string(slurp)
}
} else {
txt, err := ioutil.ReadAll(msg.Body)
if err != nil {
log.Fatal(err)
}
finalBody += string(txt)
}
and this segment passed the final body into mongodb
importMsg := &importer.Mail{
Body: finalBody }
// Saves in MongoDB
dal := importer.NewMailDAO(c, mongo)
dal.Save(importMsg)
}