Documentation
¶
Overview ¶
Package imapx is frostmail's only door to IMAP. It wraps the patched go-imap v2 client in third_party/go-imap (docs/adr/0004-go-imap-fork.md), so sync code never imports go-imap directly and the fork stays replaceable.
Index ¶
- Constants
- Variables
- func AssignRoles(list []store.ServerMailbox)
- func Dial(ctx context.Context, opts DialOptions) (*imapclient.Client, error)
- func RoleFor(path, delim string, attrs []string) api.MailboxRole
- type Capabilities
- type DialOptions
- type Part
- type Selected
- type Session
- func (s *Session) Append(ctx context.Context, mailbox string, raw []byte, flags []string) (uint32, error)
- func (s *Session) Capabilities() Capabilities
- func (s *Session) Close() error
- func (s *Session) Copy(ctx context.Context, uids []uint32, dest string) (map[uint32]uint32, error)
- func (s *Session) Create(ctx context.Context, path string) error
- func (s *Session) Delete(ctx context.Context, path string) error
- func (s *Session) Expunge(ctx context.Context, uids []uint32) error
- func (s *Session) FetchDisplay(ctx context.Context, uid uint32) ([]byte, error)
- func (s *Session) FetchFlags(ctx context.Context, uids []uint32, changedSince uint64) ([]store.FlagUpdate, error)
- func (s *Session) FetchGmailChanges(ctx context.Context, uids []uint32, changedSince uint64) ([]store.FlagUpdate, error)
- func (s *Session) FetchGmailHeaders(ctx context.Context, uids []uint32) ([]store.MessageHeader, error)
- func (s *Session) FetchHeaders(ctx context.Context, uids []uint32) ([]store.MessageHeader, error)
- func (s *Session) FetchRaw(ctx context.Context, uid uint32) ([]byte, error)
- func (s *Session) Idle(ctx context.Context, wake <-chan struct{}, max time.Duration, started func()) error
- func (s *Session) List(ctx context.Context) ([]store.ServerMailbox, error)
- func (s *Session) Mailbox() string
- func (s *Session) Move(ctx context.Context, uids []uint32, dest string) (map[uint32]uint32, error)
- func (s *Session) Rename(ctx context.Context, from, to string) error
- func (s *Session) SearchGmailRaw(ctx context.Context, raw string, since time.Time, minUID uint32) ([]uint32, error)
- func (s *Session) SearchHeader(ctx context.Context, field, value string) ([]uint32, error)
- func (s *Session) SearchMessageID(ctx context.Context, msgid string) ([]uint32, error)
- func (s *Session) Select(ctx context.Context, path string) (Selected, error)
- func (s *Session) Status(ctx context.Context, path string) (Selected, error)
- func (s *Session) StoreFlags(ctx context.Context, uids []uint32, add, remove []string) error
- func (s *Session) StoreLabels(ctx context.Context, uids []uint32, add, remove []string) error
- func (s *Session) UIDs(ctx context.Context) ([]uint32, error)
- func (s *Session) UIDsSince(ctx context.Context, since time.Time) ([]uint32, error)
Constants ¶
const PreviewBytes = 2048
PreviewBytes is how much of a message's text part a header fetch reads for its preview.
const PreviewRunes = 200
PreviewRunes is the length of a stored preview.
Variables ¶
var ErrAuth = errors.New("imapx: login rejected")
ErrAuth means the server rejected the credentials. Retrying with the same password will not help.
var ErrNoDisplay = errors.New("imapx: no display copy")
ErrNoDisplay means a message's structure cannot be made into a display copy (a multipart without a boundary, a part without a header): fetch the whole message instead.
var ErrNoMessage = errors.New("imapx: message not on the server")
ErrNoMessage means the server no longer has the requested message.
var ErrNotGmail = errors.New("imapx: the server has no Gmail extensions")
ErrNotGmail means a Gmail command was sent to a server without X-GM-EXT-1.
var ErrReadOnly = errors.New("imapx: the session is read-only")
ErrReadOnly means a read-only session was asked to change the server.
ErrUnavailable means the server accepted the credentials but cannot open the mailbox now, so a later login can succeed: the response code UNAVAILABLE (RFC 5530), or Outlook's "User is authenticated but not connected.", which it answers while the mailbox's backend is away.
Functions ¶
func AssignRoles ¶
func AssignRoles(list []store.ServerMailbox)
AssignRoles gives each role to at most one mailbox. Roles the server states (INBOX and special-use attributes) are given first, in list order; roles guessed from names only go to roles still free, so iCloud's "Sent Messages" (\Sent) wins over a "Sent Items" another client made.
func Dial ¶
func Dial(ctx context.Context, opts DialOptions) (*imapclient.Client, error)
Dial connects, secures the connection as opts.TLS says, and logs in.
Types ¶
type Capabilities ¶
type Capabilities struct {
CondStore bool
ESearch bool
Binary bool
Move bool
UIDPlus bool
Idle bool
SpecialUse bool
ListExtended bool
// Gmail is X-GM-EXT-1: X-GM-MSGID, X-GM-THRID, X-GM-LABELS (ADR-0012).
Gmail bool
}
Capabilities are the server extensions sync uses, probed once after login.
type DialOptions ¶
type DialOptions struct {
Host string
Port int
TLS api.TLSMode
Username string
Password string
// OAuth makes Password an OAuth access token, sent with AUTHENTICATE
// XOAUTH2 instead of LOGIN.
OAuth bool
// ReadOnly opens mailboxes with EXAMINE, and the session refuses every
// command that would change the server with ErrReadOnly.
ReadOnly bool
// InsecureSkipVerify accepts any certificate; only for test servers
// with self-signed certificates.
InsecureSkipVerify bool
// Trace, when set, receives the session's lines with their direction
// and credentials redacted (trace.go); a Closer is closed with the
// connection. STARTTLS connections are not traced.
Trace io.Writer
// Timeout bounds connecting and logging in; zero means 30s.
Timeout time.Duration
// OnUpdate, if set, is called from the connection's reader for every
// unsolicited EXISTS, EXPUNGE or FETCH. It must not block.
OnUpdate func()
// Log, if set, receives what the session skips: a message whose
// BODYSTRUCTURE the parser rejected is logged with the structure's
// shape, its strings masked.
Log *slog.Logger
}
DialOptions says how to reach and log in to one IMAP server.
type Session ¶
type Session struct {
Caps Capabilities
// contains filtered or unexported fields
}
Session is one logged-in IMAP connection. It is not safe for concurrent use: the account actor drives it from one goroutine. Every method takes a context; when the context ends mid-command the connection is closed and the session must be discarded.
func Open ¶
func Open(ctx context.Context, opts DialOptions) (*Session, error)
Open dials, logs in and probes capabilities. opts.OnUpdate, if set, is called for every unsolicited EXISTS, EXPUNGE or FETCH, from the connection's reader goroutine; it must not block.
func (*Session) Append ¶
func (s *Session) Append(ctx context.Context, mailbox string, raw []byte, flags []string) (uint32, error)
Append stores a raw message in mailbox with flags and returns its UID when the server reports it (UIDPLUS), else 0.
func (*Session) Capabilities ¶
func (s *Session) Capabilities() Capabilities
Capabilities returns what the server offers, as probed at login.
func (*Session) Copy ¶
Copy copies messages of the selected mailbox to dest by UID and returns each source UID's new UID when the server reports COPYUID (UIDPLUS).
func (*Session) Create ¶
Expunge permanently removes uids, which must already be \Deleted, from the selected mailbox. It needs UIDPLUS; a bare EXPUNGE could remove messages another client marked. Create makes a mailbox; one the server already has is not an error.
func (*Session) FetchDisplay ¶
FetchDisplay fetches the display copy of message uid in the selected mailbox: its BODYSTRUCTURE and header, then the MIME headers of its parts and the content of those a reader shows (shown).
func (*Session) FetchFlags ¶
func (s *Session) FetchFlags(ctx context.Context, uids []uint32, changedSince uint64) ([]store.FlagUpdate, error)
FetchFlags fetches flags for uids in the selected mailbox; with changedSince > 0 and CONDSTORE, only those changed since that modseq.
func (*Session) FetchGmailChanges ¶
func (s *Session) FetchGmailChanges(ctx context.Context, uids []uint32, changedSince uint64) ([]store.FlagUpdate, error)
FetchGmailChanges is FetchFlags plus each message's X-GM-LABELS.
func (*Session) FetchGmailHeaders ¶
func (s *Session) FetchGmailHeaders(ctx context.Context, uids []uint32) ([]store.MessageHeader, error)
FetchGmailHeaders is FetchHeaders plus X-GM-MSGID, X-GM-THRID and X-GM-LABELS (Caps.Gmail).
func (*Session) FetchHeaders ¶
FetchHeaders fetches headers, structure, flags and a preview for uids in the selected mailbox. UIDs the server no longer has are missing from the result.
func (*Session) FetchRaw ¶
FetchRaw fetches the whole message (BODY.PEEK[]) of uid in the selected mailbox.
func (*Session) Idle ¶
func (s *Session) Idle(ctx context.Context, wake <-chan struct{}, max time.Duration, started func()) error
Idle runs IDLE on the selected mailbox until ctx ends, wake fires, or max elapses. It returns nil in all three cases unless the connection failed. started, if not nil, is called once the server has accepted IDLE.
func (*Session) Move ¶
Move moves uids from the selected mailbox to dest and returns the new UIDs by old UID when the server reports them (UIDPLUS). Without MOVE, go-imap copies, flags \Deleted and expunges by UID; without UIDPLUS either, the move fails rather than risk a bare EXPUNGE.
func (*Session) SearchGmailRaw ¶
func (s *Session) SearchGmailRaw(ctx context.Context, raw string, since time.Time, minUID uint32) ([]uint32, error)
SearchGmailRaw returns the UIDs in the selected mailbox that a Gmail search matches (X-GM-RAW, in the web's search language, such as "category:promotions"), limited to UIDs at or above minUID unless it is 0 and to mail that arrived on since's day or later unless it is zero; ascending.
func (*Session) SearchHeader ¶
SearchHeader returns the UIDs in the selected mailbox whose header field contains value, ascending.
func (*Session) SearchMessageID ¶
SearchMessageID returns the UIDs in the selected mailbox whose Message-ID header contains msgid (given without angle brackets), ascending.
func (*Session) Select ¶
Select opens a mailbox: read-write, or with EXAMINE on a read-only session.
func (*Session) StoreFlags ¶
StoreFlags adds and removes flags on uids in the selected mailbox.
func (*Session) StoreLabels ¶
StoreLabels adds and removes Gmail labels (STORE ±X-GM-LABELS) on uids in the selected mailbox.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package imapxtest runs go-imap's in-memory IMAP server for unit tests.
|
Package imapxtest runs go-imap's in-memory IMAP server for unit tests. |
|
Package replay serves a recorded IMAP session back to a client (docs/design/testing.md, transcript replay).
|
Package replay serves a recorded IMAP session back to a client (docs/design/testing.md, transcript replay). |