eazye

package module
v0.0.0-...-e4120a8 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2018 License: Apache-2.0 Imports: 9 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 VisibleText

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

Types

type Client

type Client struct {
	TLS    bool
	Folder string
	// Read only mode, false (original logic) if not initialized
	ReadOnly bool

	Imap *imap.Client
}

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

func New

func New(host, user, pwd string, options ...func(*Client)) (*Client, error)

New initializes a new Client.

func (*Client) DeleteEmail

func (c *Client) DeleteEmail(email Email) error

func (*Client) GenerateAll

func (c *Client) GenerateAll(markAsRead, delete bool) (chan Response, error)

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

func (*Client) GenerateSince

func (c *Client) GenerateSince(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 (*Client) GenerateUnread

func (c *Client) GenerateUnread(markAsRead, delete bool) (chan Response, error)

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

func (*Client) GetAll

func (c *Client) GetAll(markAsRead, delete bool) ([]Email, error)

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

func (*Client) GetSince

func (c *Client) GetSince(since time.Time, markAsRead, delete bool) ([]Email, error)

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

func (*Client) GetUnread

func (c *Client) GetUnread(markAsRead, delete bool) ([]Email, error)

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

func (*Client) SetAsRead

func (c *Client) SetAsRead(email Email) error

func (*Client) SetAsUnread

func (c *Client) SetAsUnread(email Email) error

type Email

type Email struct {
	ID      imap.Field
	Message *mail.Message
}

Email is a raw Email message from the std lib

type Option

type Option func(*Client)

Option is a type which represents a functional option.

func SetFolder

func SetFolder(folder string) Option

SetFolder is a functional option to set the Folder attr.

func SetReadOnly

func SetReadOnly(readOnly bool) Option

SetFolder is a functional option to set the ReadOnly attr.

func SetTLS

func SetTLS(tls bool) Option

SetTLS is a functional option to set the TLS attr.

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