imap

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package imap provides IMAP client functionality for nmail.

Index

Constants

This section is empty.

Variables

View Source
var ErrIdleUnsupported = errors.New("imap idle unsupported")

ErrIdleUnsupported indicates the IMAP server rejected the IDLE command.

Functions

This section is empty.

Types

type Client

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

Client wraps an IMAP connection.

func Connect

func Connect(account config.Account) (*Client, error)

Connect opens a TLS IMAP connection and logs in.

func (*Client) Close

func (cl *Client) Close() error

Close closes the IMAP connection.

func (*Client) FetchInbox

func (cl *Client) FetchInbox(limit int) ([]Message, error)

FetchInbox returns the latest `limit` messages from INBOX (headers only).

func (*Client) FetchMessage

func (cl *Client) FetchMessage(id uint32) (*Message, error)

FetchMessage returns the full message including body.

func (*Client) SearchMessages

func (cl *Client) SearchMessages(query SearchQuery) ([]Message, error)

SearchMessages returns messages in INBOX matching the provided filters.

func (*Client) Watch

func (cl *Client) Watch(ctx context.Context, fallbackPollInterval time.Duration, onNew func(Message) error) error

Watch watches INBOX for new messages, preferring IMAP IDLE and falling back to polling when IDLE isn't supported.

func (*Client) WatchIDLE

func (cl *Client) WatchIDLE(ctx context.Context, onNew func(Message) error) error

WatchIDLE watches INBOX for new messages using IMAP IDLE.

func (*Client) WatchPoll

func (cl *Client) WatchPoll(ctx context.Context, interval time.Duration, onNew func(Message) error) error

WatchPoll watches INBOX for new messages by polling mailbox UIDNEXT.

type Message

type Message struct {
	ID      uint32    `json:"id"`
	From    string    `json:"from"`
	Subject string    `json:"subject"`
	Date    time.Time `json:"date"`
	Body    string    `json:"body,omitempty"`
	IsRead  bool      `json:"is_read"`
}

Message represents a parsed email message.

type SearchQuery

type SearchQuery struct {
	From    string
	Subject string
	Text    string
	Since   time.Time
	Before  time.Time
	Unseen  bool
	Limit   int
}

SearchQuery represents filters for searching messages.

Jump to

Keyboard shortcuts

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