| 1 |
// Package enmime implements a MIME encoding and decoding library. It's built on top of Go's |
| 2 |
// included mime/multipart support where possible, but is geared towards parsing MIME encoded |
| 3 |
// emails. |
| 4 |
// |
| 5 |
// Overview |
| 6 |
// |
| 7 |
// The enmime API has two conceptual layers. The lower layer is a tree of Part structs, |
| 8 |
// representing each component of a decoded MIME message. The upper layer, called an Envelope |
| 9 |
// provides an intuitive way to interact with a MIME message. |
| 10 |
// |
| 11 |
// Part Tree |
| 12 |
// |
| 13 |
// Calling ReadParts causes enmime to parse the body of a MIME message into a tree of Part objects, |
| 14 |
// each of which is aware of its content type, filename and headers. The content of a Part is |
| 15 |
// available as a slice of bytes via the Content field. |
| 16 |
// |
| 17 |
// If the part was encoded in quoted-printable or base64, it is decoded prior to being placed in |
| 18 |
// Content. If the Part contains text in a character set other than utf-8, enmime will attempt to |
| 19 |
// convert it to utf-8. |
| 20 |
// |
| 21 |
// To locate a particular Part, pass a custom PartMatcher function into the BreadthMatchFirst() or |
| 22 |
// DepthMatchFirst() methods to search the Part tree. BreadthMatchAll() and DepthMatchAll() will |
| 23 |
// collect all Parts matching your criteria. |
| 24 |
// |
| 25 |
// Envelope |
| 26 |
// |
| 27 |
// ReadEnvelope returns an Envelope struct. Behind the scenes a Part tree is constructed, and then |
| 28 |
// sorted into the correct fields of the Envelope. |
| 29 |
// |
| 30 |
// The Envelope contains both the plain text and HTML portions of the email. If there was no plain |
| 31 |
// text Part available, the HTML Part will be down-converted using the html2text library[1]. The |
| 32 |
// root of the Part tree, as well as slices of the inline and attachment Parts are also available. |
| 33 |
// |
| 34 |
// Headers |
| 35 |
// |
| 36 |
// Every MIME Part has its own headers, accessible via the Part.Header field. The raw headers for |
| 37 |
// an Envelope are available in Root.Header. Envelope also provides helper methods to fetch |
| 38 |
// headers: GetHeader(key) will return the RFC 2047 decoded value of the specified header. |
| 39 |
// AddressList(key) will convert the specified address header into a slice of net/mail.Address |
| 40 |
// values. |
| 41 |
// |
| 42 |
// Errors |
| 43 |
// |
| 44 |
// enmime attempts to be tolerant of poorly encoded MIME messages. In situations where parsing is |
| 45 |
// not possible, the ReadEnvelope and ReadParts functions will return a hard error. If enmime is |
| 46 |
// able to continue parsing the message, it will add an entry to the Errors slice on the relevant |
| 47 |
// Part. After parsing is complete, all Part errors will be appended to the Envelope Errors slice. |
| 48 |
// The Error* constants can be used to identify a specific class of error. |
| 49 |
// |
| 50 |
// Please note that enmime parses messages into memory, so it is not likely to perform well with |
| 51 |
// multi-gigabyte attachments. |
| 52 |
// |
| 53 |
// enmime is open source software released under the MIT License. The latest version can be found |
| 54 |
// at https://github.com/jhillyerd/enmime |
| 55 |
// |
| 56 |
// [1]: https://github.com/jaytaylor/html2text |
| 57 |
package enmime // import "github.com/jhillyerd/enmime" |