mailreader

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2020 License: GPL-2.0 Imports: 9 Imported by: 0

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

func New(file string) (*Email, error)

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

func NewEnmime(file string) (*Email, error)

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

func (m *Email) Body() string

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.

func (*Email) Flags

func (m *Email) Flags() string

Flags returns the flags from the given message, by reading them from the filename.

As a special case if the message is in the new/ folder the flag "N" is also added.

func (*Email) Header

func (m *Email) Header(name string) string

Header returns the value of the given header from within our message.

Header values are RFC2047-decoded.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL