type MailboxInfo struct {
Host string
TLS bool
User string
Pwd string
Folder string
}
// 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)
// 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)
// 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)
// 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.Response
s. 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