Giter VIP home page Giter VIP logo

eazye's Introduction

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)
... or all mail matching an IMAP Command search
// GetCommand will pull all emails that match the provided IMAP Command.
// Examples of IMAP Commands include TO/FROM/BCC, some examples are here http://www.marshallsoft.com/ImapSearch.htm
func GetCommand(info MailboxInfo, IMAPCommand string, markAsRead, delete bool)
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

eazye's People

Contributors

jprobinson avatar itisnathaniel avatar glennzw avatar philippedesjacques avatar senkinalex avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.