imapclient

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package imapclient is for listing folders, reading messages and moving them around (delete, unread, move).

Index

Constants

View Source
const (
	NoTLS    = tlsPolicy(-1)
	MaybeTLS = tlsPolicy(0)
	ForceTLS = tlsPolicy(1)
)
View Source
const LogAll = LogMask(true)

Variables

View Source
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")
)
View Source
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 NewClient

func NewClient(host string, port int, username, password string) Client

NewClient returns a new (not connected) Client, using TLS iff port == 143.

func NewClientNoTLS

func NewClientNoTLS(host string, port int, username, password string) Client

NewClientNoTLS returns a new (not connected) Client, without TLS.

func NewClientTLS

func NewClientTLS(host string, port int, username, password string) Client

NewClientTLS returns a new (not connected) Client, using TLS.

type DeliverFunc added in v0.7.1

type DeliverFunc func(ctx context.Context, r io.ReadSeeker, uid uint32, hsh HashArray) 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.

func MkDeliverFunc added in v0.7.1

func MkDeliverFunc(ctx context.Context, deliver DeliverFunc) DeliverFunc

type Hash added in v0.13.0

type Hash struct{ hash.Hash }

func NewHash added in v0.13.0

func NewHash() *Hash

func (Hash) Array added in v0.13.0

func (h Hash) Array() HashArray

type HashArray added in v0.13.0

type HashArray [sha512.Size224]byte

func (HashArray) String added in v0.13.0

func (h HashArray) String() string

type LogMask

type LogMask bool

type Mailbox

type Mailbox struct {
	Mailbox string
	ServerAddress
}

Mailbox is the ServerAddress with Mailbox info appended.

func ParseMailbox

func ParseMailbox(s string) (Mailbox, error)

ParseMailbox parses an imaps://user:passw@host:port/mailbox URL.

func (Mailbox) Connect

func (m Mailbox) Connect(ctx context.Context) (Client, error)

func (Mailbox) String

func (m Mailbox) String() string

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

Directories

Path Synopsis
Package o365 implements an imap client, using Office 365 Mail REST API.
Package o365 implements an imap client, using Office 365 Mail REST API.

Jump to

Keyboard shortcuts

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