eazye

package module
v0.0.0-...-8ac234e Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

README

eazye GoDoc Travis CI

The Gangsta Gangsta way to pull email.
Getting your emails is eazy...
Start by putting credentials and mailbox info into a MailboxInfo:
type MailboxInfo struct {
    Host   string
    TLS    bool
    User   string
    Pwd    string
    Folder string
}
Then connect and pull all mail...
// GetAll will pull all emails from the email folder and return them as a list.
func GetAll(info MailboxInfo, markAsRead, delete bool) ([]Email, error)
// GenerateAll will find all emails in the email folder and pass them along to the response channel.
func GenerateAll(info MailboxInfo, markAsRead, delete bool) (chan Response, error)
... or all unread mail...
// GetUnread will find all unread emails in the folder and return them as a list.
func GetUnread(info MailboxInfo, markAsRead, delete bool) ([]Email, error)
// GenerateUnread will find all unread emails in the folder and pass them along to the response channel.
func GenerateUnread(info MailboxInfo, markAsRead, delete bool) (chan Response, error)
... or all mail received since a particular date.
// GetSince will pull all emails that have an internal date after the given time.
func GetSince(info MailboxInfo, since time.Time, markAsRead, delete bool)
// GenerateSince will find all emails that have an internal date after the given time and pass them along to the responses channel.
func GenerateSince(info MailboxInfo, since time.Time, markAsRead, delete bool) (chan Response, error)
eazye will pull out the most common headers and bits but also provides the mail.Message in case you want to pull additional data.
type Email struct {
    Message *mail.Message

    From         *mail.Address   `json:"from"`
    To           []*mail.Address `json:"to"`
    InternalDate time.Time       `json:"internal_date"`
    Precedence   string          `json:"precedence"`
    Subject      string          `json:"subject"`
    HTML         []byte          `json:"html"`
    Text         []byte          `json:"text"`
    IsMultiPart  bool            `json:"is_multipart"`
}
The eazye Email type also has a handy func (e *Email) VisibleText() ([][]byte, error) that will return all the visible text from an HTML email or the body of a Text email if HTML is not available.
If you have a lot of messages and do not want to load everything into memory, use the GenerateXXX functions and the emails will be passed along on a channel of eazye.Responses. To configure the buffer size of the response channel, you can use the exported GenerateBufferSize variable, which is defaulted to 100.
// Response is a helper struct to wrap the email responses and possible errors.
type Response struct {
    Email Email
    Err   error
}

This package has several dependencies:

  • github.com/mxk/go-imap/imap
  • github.com/paulrosania/charset
  • github.com/paulrosania/go-charset/data
  • github.com/sloonz/go-qprintable
  • golang.org/x/net/html

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GenerateBufferSize = 100

Functions

func GenerateAll

func GenerateAll(info MailboxInfo, markAsRead, delete bool) (chan Response, error)

GenerateAll will find all emails in the email folder and pass them along to the responses channel.

func GenerateSince

func GenerateSince(info MailboxInfo, since time.Time, markAsRead, delete bool) (chan Response, error)

GenerateSince will find all emails that have an internal date after the given time and pass them along to the responses channel.

func GenerateUnread

func GenerateUnread(info MailboxInfo, markAsRead, delete bool) (chan Response, error)

GenerateUnread will find all unread emails in the folder and pass them along to the responses channel.

func VisibleText

func VisibleText(body io.Reader) ([][]byte, error)

Types

type Email

type Email struct {
	Message *mail.Message

	From         *mail.Address   `json:"from"`
	To           []*mail.Address `json:"to"`
	InternalDate time.Time       `json:"internal_date"`
	Precedence   string          `json:"precedence"`
	Subject      string          `json:"subject"`
	HTML         []byte          `json:"html"`
	Text         []byte          `json:"text"`
	IsMultiPart  bool            `json:"is_multipart"`
}

Email is a simplified email struct containing the basic pieces of an email. If you want more info, it should all be available within the Message attribute.

func GetAll

func GetAll(info MailboxInfo, markAsRead, delete bool) ([]Email, error)

GetAll will pull all emails from the email folder and return them as a list.

func GetSince

func GetSince(info MailboxInfo, since time.Time, markAsRead, delete bool) ([]Email, error)

GetSince will pull all emails that have an internal date after the given time.

func GetUnread

func GetUnread(info MailboxInfo, markAsRead, delete bool) ([]Email, error)

GetUnread will find all unread emails in the folder and return them as a list.

func NewEmail

func NewEmail(msgFields imap.FieldMap) (Email, error)

NewEmail will parse an imap.FieldMap into an Email. This will expect the message to container the internaldate and the body with all headers included.

func (*Email) String

func (e *Email) String() string

String is to spit out a somewhat pretty version of the email.

func (*Email) VisibleText

func (e *Email) VisibleText() ([][]byte, error)

VisibleText will return any visible text from an HTML email body.

type MailboxInfo

type MailboxInfo struct {
	Host   string
	TLS    bool
	User   string
	Pwd    string
	Folder string
	// Read only mode, false (original logic) if not initialized
	ReadOnly bool
}

MailboxInfo holds onto the credentials and other information needed for connecting to an IMAP server.

type Response

type Response struct {
	Email Email
	Err   error
}

Response is a helper struct to wrap the email responses and possible errors.

Jump to

Keyboard shortcuts

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