Help us shape the future of Go! Take the 2026 Go Developer Survey

mailclient

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT-0 Imports: 11 Imported by: 0

Documentation

Overview

Package mailclient implements the small IMAP client used by the perch CLI. It deliberately exposes only the operations needed to list, search, and fetch mail so that the command-line surface stays predictable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseQuery

func ParseQuery(query string) (*imap.SearchCriteria, error)

ParseQuery converts a compact, shell-friendly search expression into IMAP search criteria. Bare words are matched against the message text. Supported keys are from, to, cc, bcc, subject, body, text, header:Name=Value, since, before, on, sent-since, sent-before, sent-on, seen, unseen, answered, unanswered, flagged, unflagged, deleted, undeleted, draft, undraft, larger, smaller, uid, flag/keyword, and unflag/unkeyword.

func ParseUIDSet

func ParseUIDSet(value string) (imap.UIDSet, error)

ParseUIDSet parses an IMAP UID set such as "1,3:5,10:*". A zero value means "*" in the go-imap API.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps the go-imap client with the operations perch exposes.

func Dial

func Dial(opts Options) (*Client, error)

Dial connects and authenticates to an IMAP server.

func (*Client) Close

func (c *Client) Close() error

Close logs out and closes the connection.

func (*Client) FetchRaw

func (c *Client) FetchRaw(uid imap.UID, markSeen bool) (Message, error)

FetchRaw fetches one complete message. When markSeen is false, BODY.PEEK is used so the server does not change the \Seen flag.

func (*Client) Mailboxes

func (c *Client) Mailboxes(subscribedOnly bool) ([]Mailbox, error)

Mailboxes lists mailboxes. When subscribedOnly is set, only subscribed mailboxes are returned.

func (*Client) SearchUIDs

func (c *Client) SearchUIDs(criteria *imap.SearchCriteria) ([]imap.UID, error)

SearchUIDs runs a UID SEARCH and returns the matching UIDs in server order.

func (*Client) Select

func (c *Client) Select(mailbox string, readOnly bool) (*imap.SelectData, error)

Select selects a mailbox. When readOnly is set, EXAMINE is used.

func (*Client) Summaries

func (c *Client) Summaries(uids []imap.UID) ([]Message, error)

Summaries fetches metadata for the given UIDs. The result is in the order returned by the server.

type Mailbox

type Mailbox struct {
	Name       string
	Delimiter  string
	Attributes []string
	SpecialUse []string
	Subscribed bool
}

Mailbox is one entry returned by LIST.

type Message

type Message struct {
	UID          imap.UID
	SeqNum       uint32
	Flags        []string
	Size         int64
	InternalDate time.Time
	Envelope     *imap.Envelope
	Raw          []byte
}

Message contains the metadata and, when requested, the raw message.

type Options

type Options struct {
	Addr      string
	TLSMode   TLSMode
	TLSConfig *tls.Config
	Username  string
	Password  string
	Timeout   time.Duration
}

Options configures Dial.

type TLSMode

type TLSMode int

TLSMode selects how the client secures its IMAP connection.

const (
	// TLSImplicit connects with TLS immediately (usually port 993).
	TLSImplicit TLSMode = iota
	// TLSStartTLS connects in plaintext and upgrades with STARTTLS.
	TLSStartTLS
	// TLSDisabled sends everything in plaintext. It is only appropriate for
	// trusted loopback connections.
	TLSDisabled
)

Jump to

Keyboard shortcuts

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