commit | c6b0460df41fcfa7333639a3a15bada76034dcd8 | [log] [tgz] |
---|---|---|
author | avm99963 <me@avm99963.com> | Thu Jan 21 01:18:53 2021 +0100 |
committer | avm99963 <me@avm99963.com> | Fri Jan 22 14:30:08 2021 +0100 |
tree | fc2913cb7e1042887c0461e2a037c45c9c090b2a | |
parent | d916cfba4beb69eda6a8acf0a0702acade707108 [diff] |
Fix support for base64 content - Sometimes the content-type is set as Base64 instead of base64. This change adds support for the Base64 value. - Parts inside a multipart message which have the Content-Transfer-Encoding header set are now decoded (before the raw text was returned).
Note: This is a fork of the original library at https://github.com/DusanKasan/parsemail
This library allows for parsing an email message into a more convenient form than the net/mail
provides. Where the net/mail
just gives you a map of header fields and a io.Reader
of its body, Parsemail allows access to all the standard header fields set in RFC5322, html/text body as well as attachements/embedded content as binary streams with metadata.
You just parse a io.Reader that holds the email data. The returned Email struct contains all the standard email information/headers as public fields.
var reader io.Reader // this reads an email message email, err := parsemail.Parse(reader) // returns Email struct and error if err != nil { // handle error } fmt.Println(email.Subject) fmt.Println(email.From) fmt.Println(email.To) fmt.Println(email.HTMLBody)
Attachments are a easily accessible as Attachment
type, containing their mime type, filename and data stream.
var reader io.Reader email, err := parsemail.Parse(reader) if err != nil { // handle error } for _, a := range(email.Attachments) { fmt.Println(a.Filename) fmt.Println(a.ContentType) //and read a.Data }
You can access embedded files in the same way you can access attachments. They contain the mime type, data stream and content id that is used to reference them through the email.
var reader io.Reader email, err := parsemail.Parse(reader) if err != nil { // handle error } for _, a := range(email.EmbeddedFiles) { fmt.Println(a.CID) fmt.Println(a.ContentType) //and read a.Data }