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(ctx context.Context, c Client, inbox, pattern string, deliver DeliverFunc, ...) (int, error)
- func DeliveryLoop(ctx context.Context, c Client, inbox, pattern string, deliver DeliverFunc, ...) error
- type Client
- type DeliverFunc
- type Hash
- type HashArray
- type LogMask
- type Mailbox
- type ServerAddress
Constants ¶
const ( NoTLS = tlsPolicy(-1) MaybeTLS = tlsPolicy(0) ForceTLS = tlsPolicy(1) )
const LogAll = LogMask(true)
Variables ¶
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") )
var TLSConfig = tls.Config{InsecureSkipVerify: true} //nolint:gas
TLSConfig is the client's config for DialTLS. nosemgrep
Functions ¶
func CramAuth ¶
func CramAuth(username, password string) sasl.Client
CramAuth returns an sasl.Client usable for CRAM-MD5 authentication.
func DeliverOne ¶ added in v0.7.1
func DeliverOne(ctx context.Context, c Client, inbox, pattern string, deliver DeliverFunc, outbox, errbox string, logger *slog.Logger) (int, error)
DeliverOne does one round of message reading and delivery. Does not loop. Returns the number of messages delivered.
func DeliveryLoop ¶ added in v0.7.1
func DeliveryLoop(ctx context.Context, c Client, inbox, pattern string, deliver DeliverFunc, outbox, errbox string, logger *slog.Logger) error
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.
Types ¶
type Client ¶
type Client interface { Close(ctx context.Context, commit bool) error Mailboxes(ctx context.Context, root string) ([]string, 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) Delete(ctx context.Context, msgID uint32) error 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 Connect(ctx context.Context) error Move(ctx context.Context, msgID uint32, mbox string) error Mark(ctx context.Context, msgID uint32, seen bool) error List(ctx context.Context, mbox, pattern string, all bool) ([]uint32, error) ReadTo(ctx context.Context, w io.Writer, msgID uint32) (int64, error) SetLogger(*slog.Logger) SetLogMask(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 ¶ added in v0.7.1
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.
func MkDeliverFunc ¶ added in v0.7.1
func MkDeliverFunc(ctx context.Context, deliver DeliverFunc) DeliverFunc
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 ServerAddress ¶
type ServerAddress struct { Host string Username string ClientID, ClientSecret string Port uint32 TLSPolicy tlsPolicy // contains filtered or unexported fields }
ServerAddress represents the server's address.
func (ServerAddress) Password ¶
func (m ServerAddress) Password() string
func (ServerAddress) String ¶
func (m ServerAddress) String() string
func (ServerAddress) URL ¶
func (m ServerAddress) URL() *url.URL
URL representation of the server address.
The password is masked is withPassword is false!
func (ServerAddress) WithPassword ¶ added in v0.7.2
func (m ServerAddress) WithPassword(password string) ServerAddress