Documentation
¶
Overview ¶
Package imapclient is for listing folders, reading messages and moving them around (delete, unread, move).
Index ¶
- Constants
- Variables
- func CramAuth(username, password string) sasl.Client
- func DeliverOne(c Client, inbox, pattern string, deliver DeliverFunc, outbox, errbox string) (int, error)
- func DeliverOneC(ctx context.Context, c Client, inbox, pattern string, deliver DeliverFuncC, ...) (int, error)
- func DeliveryLoop(c Client, inbox, pattern string, deliver DeliverFunc, outbox, errbox string, ...)
- func DeliveryLoopC(ctx context.Context, c Client, inbox, pattern string, deliver DeliverFuncC, ...) error
- func GetLogger(ctx context.Context) *slog.Logger
- func SetLogger(lgr *slog.Logger)
- type Client
- type DeliverFunc
- type DeliverFuncC
- type LogMask
- type Mailbox
- type MaxClient
- func (c MaxClient) Connect() error
- func (c MaxClient) List(mbox, pattern string, all bool) ([]uint32, error)
- func (c MaxClient) MarkC(ctx context.Context, msgID uint32, seen bool) error
- func (c MaxClient) MoveC(ctx context.Context, msgID uint32, mbox string) error
- func (c MaxClient) ReadTo(w io.Writer, msgID uint32) (int64, error)
- func (c MaxClient) SetLogMaskC(ctx context.Context, mask LogMask) LogMask
- func (c MaxClient) SetLogger(logger *slog.Logger)
- type MinClient
- type ServerAddress
Constants ¶
const ( NoTLS = tlsPolicy(-1) MaybeTLS = tlsPolicy(0) ForceTLS = tlsPolicy(1) )
const LogAll = LogMask(true)
Variables ¶
var ( // Timeout is the client timeout - 30 seconds by default. Timeout = 30 * time.Second // TLSConfig is the client's config for DialTLS. // nosemgrep TLSConfig = tls.Config{InsecureSkipVerify: true} //nolint:gas )
var ( // ShortSleep is the duration which ised for sleep after successful delivery. ShortSleep = 1 * time.Second // LongSleep is the duration which used for sleep between errors and if the inbox is empty. LongSleep = 5 * time.Minute // ErrSkip from DeliverFunc means leave the message as is. ErrSkip = errors.New("skip move") )
Functions ¶
func CramAuth ¶
func CramAuth(username, password string) sasl.Client
CramAuth returns an sasl.Client usable for CRAM-MD5 authentication.
func DeliverOne ¶
func DeliverOne(c Client, inbox, pattern string, deliver DeliverFunc, outbox, errbox string) (int, error)
DeliverOne does one round of message reading and delivery. Does not loop. Returns the number of messages delivered.
func DeliverOneC ¶
func DeliverOneC(ctx context.Context, c Client, inbox, pattern string, deliver DeliverFuncC, outbox, errbox string) (int, error)
DeliverOneC does one round of message reading and delivery. Does not loop. Returns the number of messages delivered.
func DeliveryLoop ¶
func DeliveryLoop(c Client, inbox, pattern string, deliver DeliverFunc, outbox, errbox string, closeCh <-chan struct{})
DeliveryLoop periodically checks the inbox for mails with the specified pattern in the subject (or for any unseen mail if pattern == ""), tries to parse the message, and call the deliver function with the parsed message.
If deliver did not returned error, the message is marked as Seen, and if outbox is not empty, then moved to outbox. Except when the error is ErrSkip - then the message is left there as is.
deliver is called with the message, UID and hsh.
func DeliveryLoopC ¶
func DeliveryLoopC(ctx context.Context, c Client, inbox, pattern string, deliver DeliverFuncC, outbox, errbox string) error
DeliveryLoopC periodically checks the inbox for mails with the specified pattern in the subject (or for any unseen mail if pattern == ""), tries to parse the message, and call the deliver function with the parsed message.
If deliver did not returned error, the message is marked as Seen, and if outbox is not empty, then moved to outbox. Except when the error is ErrSkip - then the message is left there as is.
deliver is called with the message, UID and hsh.
Types ¶
type Client ¶
type Client interface { MinClient Connect() error MoveC(ctx context.Context, msgID uint32, mbox string) error MarkC(ctx context.Context, msgID uint32, seen bool) error List(mbox, pattern string, all bool) ([]uint32, error) ReadTo(w io.Writer, msgID uint32) (int64, error) SetLogger(*slog.Logger) SetLogMaskC(context.Context, LogMask) LogMask }
Client interface declares the needed methods for listing messages, deleting and moving them around.
func FromServerAddress ¶
func FromServerAddress(sa ServerAddress) Client
FromServerAddress returns a new (not connected) Client, using the ServerAddress.
func NewClientNoTLS ¶
NewClientNoTLS returns a new (not connected) Client, without TLS.
type DeliverFunc ¶
type DeliverFunc func(r io.ReadSeeker, uid uint32, hsh []byte) error
DeliverFunc is the type for message delivery.
r is the message data, uid is the IMAP server sent message UID, hsh is the message's hash.
type DeliverFuncC ¶
DeliverFuncC is the type for message delivery.
r is the message data, uid is the IMAP server sent message UID, hsh is the message's hash.
func MkDeliverFuncC ¶
func MkDeliverFuncC(ctx context.Context, deliver DeliverFunc) DeliverFuncC
type Mailbox ¶
type Mailbox struct { Mailbox string ServerAddress }
Mailbox is the ServerAddress with Mailbox info appended.
func ParseMailbox ¶
ParseMailbox parses an imaps://user:passw@host:port/mailbox URL.
type MaxClient ¶
type MaxClient struct {
MinClient
}
func (MaxClient) SetLogMaskC ¶
type MinClient ¶
type MinClient interface { ConnectC(context.Context) error Close(commit bool) error ListC(ctx context.Context, mbox, pattern string, all bool) ([]uint32, error) Mailboxes(ctx context.Context, root string) ([]string, error) ReadToC(ctx context.Context, w io.Writer, msgID uint32) (int64, error) FetchArgs(ctx context.Context, what string, msgIDs ...uint32) (map[uint32]map[string][]string, error) Peek(ctx context.Context, w io.Writer, msgID uint32, what string) (int64, error) Mark(msgID uint32, seen bool) error Delete(msgID uint32) error Move(msgID uint32, mbox string) error SetLogMask(mask LogMask) LogMask SetLoggerC(ctx context.Context) Select(ctx context.Context, mbox string) error Watch(ctx context.Context) ([]uint32, error) WriteTo(ctx context.Context, mbox string, msg []byte, date time.Time) error }
MinClient is the minimal required methods for a client. You can make a full Client from it by wrapping in a MaxClient.
type ServerAddress ¶
type ServerAddress struct { Host string Username, Password string ClientID, ClientSecret string Port uint32 TLSPolicy tlsPolicy }
ServerAddress represents the server's address.
func (ServerAddress) String ¶
func (m ServerAddress) String() string
func (ServerAddress) URL ¶
func (m ServerAddress) URL() *url.URL
URL representation of the server address.
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
Package o365 implements an imap client, using Office 365 Mail REST API.
|
Package o365 implements an imap client, using Office 365 Mail REST API. |
Package imapclient is for listing folders, reading messages and moving them around (delete, unread, move).
|
Package imapclient is for listing folders, reading messages and moving them around (delete, unread, move). |
o365
Package o365 implements an imap client, using Office 365 Mail REST API.
|
Package o365 implements an imap client, using Office 365 Mail REST API. |
Package xoauth2 is Go library for generating XOAuth2 strings (for use in XOAUTH2 SASL auth schemes for IMAP/SMTP)
|
Package xoauth2 is Go library for generating XOAuth2 strings (for use in XOAUTH2 SASL auth schemes for IMAP/SMTP) |