Documentation ¶
Overview ¶
Package email provides some functions to handle the emails.
Index ¶
- Constants
- Variables
- func GetAllBuilderTypes() (types []string)
- func RegisterHandlerBuilder(_type string, build HandlerBuilder)
- type Address
- type Email
- type Handler
- func BuildHandler(_type string, configs map[string]interface{}) (Handler, error)
- func FilterAlarmedHandler() Handler
- func FilterReadHandler() Handler
- func MoveBoxHandler(mailbox string, match func(sender, subject string) bool) Handler
- func NewHandler(_type string, handle func(*Email) (next bool, err error)) Handler
- func SetReadHandler(match func(sender, subject string) bool) Handler
- type HandlerBuilder
- type Mailbox
Constants ¶
const (
Inbox = "INBOX"
)
Predefine some mailboxes.
Variables ¶
var EmailMatcher func(senderMatcher, subjectMatcher string) (func(sender, subject string) (match bool), error) = matchEmail
EmailMatcher is used to returns an matcher to check whether an email is matched.
Functions ¶
func GetAllBuilderTypes ¶
func GetAllBuilderTypes() (types []string)
GetAllBuilderTypes returns the types of all the handler builders.
func RegisterHandlerBuilder ¶
func RegisterHandlerBuilder(_type string, build HandlerBuilder)
RegisterHandlerBuilder registers the handler builder.
Types ¶
type Address ¶
Address represents an email address.
func (Address) FullAddress ¶
FullAddress returns the full address with the name if name is not empty.
func (Address) MarshalJSON ¶
MarshalJSON implements the interface json.Marshaler.
type Email ¶
type Email struct { Froms []Address Senders []Address Subject string SentDate time.Time // The date when the message is sent. RecievedDate time.Time // The date when the mail server recieves the message. // contains filtered or unexported fields }
Email represents an email message.
func FetchEmails ¶
func FetchEmails(ctx context.Context, addr, username, password, mailbox string, tlsconfig *tls.Config, maxnum uint32, chains ...Handler) (emails []Email, goon bool, err error)
FetchEmails fetches the emails from the mailbox.
If mailbox is eqial to "", use Inbox instead. If maxnum is equal 0, use 100 instead.
func (Email) MarshalJSON ¶
MarshalJSON implements the interface json.Marshaler.
type Handler ¶
Handler is used to process the email message.
func BuildHandler ¶
BuildHandler builds a handler by the type and configs, and returns it.
func FilterAlarmedHandler ¶
func FilterAlarmedHandler() Handler
FilterAlarmedHandler returns an email handler to filter the alarmed email based on the memory.
func FilterReadHandler ¶
func FilterReadHandler() Handler
FilterReadHandler returns an email handler to filter the read email.
func MoveBoxHandler ¶
MoveBoxHandler returns an email handler to move the matched email to other mailbox.
func NewHandler ¶
NewHandler returns a new email handler.
func SetReadHandler ¶
SetReadHandler returns an email handler to set the email to read.
type HandlerBuilder ¶
HandlerBuilder is used to build an email handler.
func GetHandlerBuilder ¶
func GetHandlerBuilder(_type string) HandlerBuilder
GetHandlerBuilder returns the handler builder by the type.
type Mailbox ¶
Mailbox represents a mailbox information.
func GetMailBoxes ¶
func GetMailBoxes(ctx context.Context, addr, username, password, mailbox string, tls bool) (mailboxes []Mailbox, err error)
GetMailBoxes returns all the sub-mailboxes belonging on mailbox.
If mailbox is "", use "*" instead.
Example:
GetMailBoxes(context.Background(), "*", true) GetMailBoxes(context.Background(), "Archives.*", true)