email

package
v0.0.0-...-2838e73 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package email provides some functions to handle the emails.

Index

Constants

View Source
const (
	Inbox = "INBOX"
)

Predefine some mailboxes.

Variables

View Source
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

type Address struct {
	Name string
	Addr string
}

Address represents an email address.

func (Address) FullAddress

func (a Address) FullAddress() string

FullAddress returns the full address with the name if name is not empty.

func (Address) MarshalJSON

func (a Address) MarshalJSON() ([]byte, error)

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) Date

func (m Email) Date() (date time.Time)

Date returns the date when the message is sent.

func (Email) IsRead

func (m Email) IsRead() bool

IsRead reports whether the message has been read.

func (Email) Mailbox

func (m Email) Mailbox() string

Mailbox returns the current mailbox which the message is in.

func (Email) MarshalJSON

func (m Email) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface json.Marshaler.

func (*Email) Move

func (m *Email) Move(box string) (err error)

Move moves the message to the given box.

func (Email) Sender

func (m Email) Sender() (sender string)

Sender returns the email address of the first sender.

func (*Email) SetRead

func (m *Email) SetRead() (err error)

SetRead marks the message to be read.

func (Email) UID

func (m Email) UID() uint32

UID returns the uid of the email.

type Handler

type Handler interface {
	Type() string
	Handle(*Email) (next bool, err error)
}

Handler is used to process the email message.

func BuildHandler

func BuildHandler(_type string, configs map[string]interface{}) (Handler, error)

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

func MoveBoxHandler(mailbox string, match func(sender, subject string) bool) Handler

MoveBoxHandler returns an email handler to move the matched email to other mailbox.

func NewHandler

func NewHandler(_type string, handle func(*Email) (next bool, err error)) Handler

NewHandler returns a new email handler.

func SetReadHandler

func SetReadHandler(match func(sender, subject string) bool) Handler

SetReadHandler returns an email handler to set the email to read.

type HandlerBuilder

type HandlerBuilder func(configs map[string]interface{}) (Handler, error)

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

type Mailbox struct {
	Name        string
	HasChildren bool
}

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)

Jump to

Keyboard shortcuts

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