commit | 13d75079e2833ee940bcc003d386e2d474a35acf | [log] [tgz] |
---|---|---|
author | DuĊĦan Kasan <dusan@kasan.sk> | Sun Apr 05 20:50:12 2020 +0200 |
committer | GitHub <noreply@github.com> | Sun Apr 05 20:50:12 2020 +0200 |
tree | f69369fa7f343b2ecd45fa848336f6d0e00baaf4 | |
parent | 981d4041d6969a4f57f46bb3ff548172e523c4d9 [diff] | |
parent | 1f56fdd2b6c8e674d282bcc035c782284368f105 [diff] |
Merge pull request #15 from xgess/xgess/fix-gomod fix go.mod to this repo
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 }