diff --git a/README.md b/README.md index 8648e8f..bcf6029 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ # Parsemail - simple email parsing Go library -[![Build Status](https://circleci.com/gh/DusanKasan/Parsemail.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/DusanKasan/Parsemail) [![Coverage Status](https://coveralls.io/repos/github/DusanKasan/Parsemail/badge.svg?branch=master)](https://coveralls.io/github/DusanKasan/Parsemail?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/DusanKasan/Parsemail)](https://goreportcard.com/report/github.com/DusanKasan/Parsemail) +[![Build Status](https://circleci.com/gh/DusanKasan/parsemail.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/DusanKasan/parsemail) [![Coverage Status](https://coveralls.io/repos/github/DusanKasan/parsemail/badge.svg?branch=master)](https://coveralls.io/github/DusanKasan/parsemail?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/DusanKasan/parsemail)](https://goreportcard.com/report/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](https://tools.ietf.org/html/rfc5322), html/text body as well as attachements/embedded content as binary streams with metadata. ## Simple usage +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. + ```go var reader io.Reader // this reads an email message email, err := parsemail.Parse(reader) // returns Email struct and error @@ -19,13 +21,38 @@ fmt.Println(email.To) fmt.Println(email.HTMLBody) ``` -## This library is WIP. +## Retrieving attachments + +Attachments are a easily accessible as `Attachment` type, containing their mime type, filename and data stream. + +```go +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 +} +``` + +## Retrieving embedded files -It is missing some tests, and needs more work. Use at your own discretion. +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. -## TODO +```go +var reader io.Reader +email, err := parsemail.Parse(reader) +if err != nil { + // handle error +} -- CI -- Readme with use cases -- More tests for 100% coverage -- quoted text? \ No newline at end of file +for _, a := range(email.EmbeddedFiles) { + fmt.Println(a.CID) + fmt.Println(a.ContentType) + //and read a.Data +} +``` \ No newline at end of file