Documentation ¶
Overview ¶
Package mailreader allows reading a single email from disk to return the body and header-values by name.
If we want to be fast we use the golang mail.* package, which is great for retrieving (& decoding) header-values. However it doesn't provide easy access to the message body for complex cases of multipart/alternative and similar MIME messages.
To handle the case of accessing the body of an email in a reliable fashion we embed Enmime and use that if we need the body. Because opening and parsing a message two times is grossly inefficient the caller needs to use the appropriate constructor and know what they want to acces.
Header-only access? Fast? Use New().
Need the body? Use NewEnmime.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Email ¶
type Email struct { // Filename holds the name of the file we're reading. Filename string // Message holds the mail message - if we're using // the golang parser (which we do for message-indexes // as it is faster). Message *mail.Message // Enmime holds the enmime handle to the message, // which we use when we want access to the body // attachments (TODO), etc. Enmime *enmime.Envelope // contains filtered or unexported fields }
Email holds the state for this message-object.
func New ¶
New creates a new mail-reading object which will use the golang mail-package to parse the message.
Using this function will allow you access to the header-values easily, but not the message-body.
func NewEnmime ¶
NewEnmime creates a new mail-reading object which uses the enmime library.
Using this method is required if you wish to read the body of an email in a form suitable for rendering. It is slower than the golang-native approach which is why the user must opt-into it.
func (*Email) Body ¶
Body returns the body of an email message, in a useful format. That means that if a 'text/plain' part is present it will be returned, otherwise we'll use 'text/html'. If neither part is present then the raw body will be returned.