worker

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComposeRFC5322

func ComposeRFC5322(from, to, subject, body string) (string, []byte)

ComposeRFC5322 builds a properly formatted RFC 5322 email message. Returns the message ID and the raw message bytes.

func FolderName

func FolderName(mailboxName string) string

FolderName maps an IMAP mailbox name to a display name.

func ParseEnvelope

func ParseEnvelope(uid uint32, env *imap.Envelope, flags []imap.Flag) email.Message

ParseEnvelope converts an IMAP envelope into an email.Message.

Types

type AttachmentData

type AttachmentData struct {
	Filename string
	Data     []byte
}

AttachmentData holds the raw bytes of an extracted attachment.

func ExtractAttachmentData

func ExtractAttachmentData(data []byte) ([]AttachmentData, error)

ExtractAttachmentData parses a raw RFC 5322 message and returns the binary data for all attachment parts.

type BodyResult

type BodyResult struct {
	Text        string
	HTML        string
	Attachments []email.Attachment
}

BodyResult holds both the plain-text and raw HTML versions of an email body, plus any attachment metadata discovered during parsing.

func ParseBody

func ParseBody(data []byte) (BodyResult, error)

ParseBody extracts text and HTML content from a message. Returns a BodyResult with a displayable Text, the raw HTML (for "open in browser"), and metadata for any attachments found.

type ConnectionStatusMsg

type ConnectionStatusMsg struct {
	Account   string
	Connected bool
	Err       error
}

ConnectionStatusMsg reports the connection state of an account.

type Coordinator

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

Coordinator manages IMAP and SMTP workers for all configured accounts.

func NewCoordinator

func NewCoordinator(cfg config.Config, store *cache.SQLiteStore) *Coordinator

NewCoordinator creates a coordinator for the given config and store.

func (*Coordinator) DeleteFolder

func (c *Coordinator) DeleteFolder(acctEmail, folder string) tea.Cmd

DeleteFolder returns a tea.Cmd that deletes a mailbox on the IMAP server and removes it from cache.

func (*Coordinator) DeleteMessage

func (c *Coordinator) DeleteMessage(acctEmail, folder string, uid uint32) tea.Cmd

DeleteMessage returns a tea.Cmd that moves a message to Trash via IMAP.

func (*Coordinator) DeleteMessages

func (c *Coordinator) DeleteMessages(acctEmail, folder string, uids []uint32) tea.Cmd

DeleteMessages returns a tea.Cmd that moves multiple messages to Trash via IMAP in a single batch. The operation is queued so it can be retried on reconnect.

func (*Coordinator) DisconnectAll

func (c *Coordinator) DisconnectAll()

DisconnectAll cleanly disconnects all workers.

func (*Coordinator) ExportMessages added in v0.9.0

func (c *Coordinator) ExportMessages(acctEmail, folder string, messages []email.Message) tea.Cmd

ExportMessages exports one or more messages to a ZIP file in ~/Downloads. Each message gets a folder with metadata.txt, message.txt, message.html, and attachments.

func (*Coordinator) FetchBody

func (c *Coordinator) FetchBody(acctEmail, folder string, uid uint32) tea.Cmd

FetchBody returns a tea.Cmd that lazily fetches a message body.

func (*Coordinator) MarkRead

func (c *Coordinator) MarkRead(acctEmail, folder string, uid uint32) tea.Cmd

MarkRead returns a tea.Cmd that marks a message as read on the IMAP server. The operation is queued so it can be retried if the connection is lost.

func (*Coordinator) ResolveCredentials

func (c *Coordinator) ResolveCredentials() []error

ResolveCredentials resolves and caches credentials for all accounts. Should be called before SyncAll.

func (*Coordinator) RestoreFromTrash added in v0.9.0

func (c *Coordinator) RestoreFromTrash(acctEmail string, uids []uint32, dstFolder string) tea.Cmd

RestoreFromTrash moves messages from Trash back to the destination folder via IMAP.

func (*Coordinator) RetryPendingOps

func (c *Coordinator) RetryPendingOps() tea.Cmd

RetryPendingOps retries any pending or failed operations from the queue.

func (*Coordinator) SaveAttachments

func (c *Coordinator) SaveAttachments(acctEmail, folder string, uid uint32, attachments []email.Attachment) tea.Cmd

SaveAttachments fetches the raw message and saves the specified attachments to ~/Downloads. Only attachments whose filename matches one in the provided list are saved.

func (*Coordinator) SendAndArchive

func (c *Coordinator) SendAndArchive(acctEmail string, req SendRequest) tea.Cmd

SendAndArchive returns a tea.Cmd that sends an email via SMTP and appends it to the Sent folder via IMAP. The operation is queued so it can be retried on reconnect.

func (*Coordinator) SetProgram

func (c *Coordinator) SetProgram(p *tea.Program)

SetProgram sets the bubbletea program reference for sending async progress messages.

func (*Coordinator) SyncAll

func (c *Coordinator) SyncAll() tea.Cmd

SyncAll returns a tea.Cmd that syncs all accounts concurrently. Each account reports its own completion via SyncAccountCompleteMsg, and a final SyncAllCompleteMsg is sent when all are done.

func (*Coordinator) SyncFolder

func (c *Coordinator) SyncFolder(acctEmail, folder string) tea.Cmd

SyncFolder returns a tea.Cmd that syncs a specific folder.

type DeleteProgressMsg

type DeleteProgressMsg struct {
	Account string
	Folder  string
	Done    int
	Total   int
}

DeleteProgressMsg reports incremental progress during batch deletion.

type DeleteResult

type DeleteResult struct {
	Account string
	Folder  string
	UID     uint32
	Err     error
}

DeleteResult is the result of deleting a message via IMAP.

type ExportProgressMsg added in v0.9.0

type ExportProgressMsg struct {
	Done  int
	Total int
}

ExportProgressMsg reports incremental progress during batch export.

type FetchBodyRequest

type FetchBodyRequest struct {
	Account string
	Folder  string
	UID     uint32
}

FetchBodyRequest requests lazy-loading a message body.

type FetchBodyResult

type FetchBodyResult struct {
	Account     string
	Folder      string
	UID         uint32
	Body        string
	HTMLBody    string
	Attachments []email.Attachment
	Err         error
}

FetchBodyResult is the result of fetching a message body.

type FolderListResult

type FolderListResult struct {
	Account string
	Folders []email.Folder
}

FolderListResult holds the folders discovered for an account.

type IMAPWorker

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

IMAPWorker manages a single IMAP connection for one account.

func NewIMAPWorker

func NewIMAPWorker(acct config.AccountConfig, creds *auth.Credentials, store *cache.SQLiteStore) *IMAPWorker

NewIMAPWorker creates a new IMAP worker for the given account.

func (*IMAPWorker) AppendToFolder

func (w *IMAPWorker) AppendToFolder(folder string, message []byte, flags []imap.Flag) error

AppendToFolder appends a message to a server folder (e.g. Sent).

func (*IMAPWorker) Connect

func (w *IMAPWorker) Connect() error

Connect establishes a connection to the IMAP server and authenticates. Also opens a second connection dedicated to body fetches.

func (*IMAPWorker) DeleteMailbox

func (w *IMAPWorker) DeleteMailbox(folder string) error

DeleteMailbox deletes a mailbox on the IMAP server.

func (*IMAPWorker) Disconnect

func (w *IMAPWorker) Disconnect()

Disconnect closes the IMAP connection gracefully if idle, or forcefully if an operation is in flight. This never blocks indefinitely, preventing deadlocks when the network is down and a cmd.Wait() is stuck.

func (*IMAPWorker) FetchBody

func (w *IMAPWorker) FetchBody(folder string, uid uint32) (BodyResult, error)

FetchBody fetches the full body of a specific message by UID.

func (*IMAPWorker) FetchBodyDirect added in v0.10.0

func (w *IMAPWorker) FetchBodyDirect(folder string, uid uint32) (BodyResult, error)

FetchBodyDirect fetches a message body using the dedicated fetch connection, bypassing the main opMu so it doesn't block behind sync operations. Falls back to the main connection if the fetch client is unavailable. If a newer fetch has been requested (wantedFetchUID changed), this fetch returns early to avoid blocking the one the user actually wants.

func (*IMAPWorker) FetchRawMessage

func (w *IMAPWorker) FetchRawMessage(folder string, uid uint32) ([]byte, error)

FetchRawMessage fetches the full RFC 5322 message bytes for a UID.

func (*IMAPWorker) FolderStatus

func (w *IMAPWorker) FolderStatus(folder string) (uidNext uint32, uidValidity uint32, err error)

FolderStatus returns UIDNEXT and UIDVALIDITY for a folder via STATUS (no SELECT needed).

func (*IMAPWorker) Idle

func (w *IMAPWorker) Idle(folder string, timeout time.Duration) (bool, error)

Idle starts IMAP IDLE on the given folder and blocks until new mail arrives or the timeout is reached. Returns true if new mail arrived.

func (*IMAPWorker) IsConnected

func (w *IMAPWorker) IsConnected() bool

IsConnected returns true if the IMAP client exists.

func (*IMAPWorker) ListMailboxes

func (w *IMAPWorker) ListMailboxes() ([]string, error)

ListMailboxes fetches the list of mailboxes and syncs them to the cache.

func (*IMAPWorker) MarkRead

func (w *IMAPWorker) MarkRead(folder string, uid uint32) error

MarkRead sets the \Seen flag on a message by UID.

func (*IMAPWorker) MarkReadBatch added in v0.7.0

func (w *IMAPWorker) MarkReadBatch(folder string, uids []uint32) error

MarkReadBatch marks multiple messages as read in a single IMAP operation.

func (*IMAPWorker) MoveToFolder added in v0.9.0

func (w *IMAPWorker) MoveToFolder(srcFolder string, uid uint32, dstFolder string) error

MoveToFolder moves a message from one folder to another via IMAP (COPY + STORE \Deleted + EXPUNGE).

func (*IMAPWorker) MoveToFolderBatch added in v0.9.0

func (w *IMAPWorker) MoveToFolderBatch(srcFolder string, uids []uint32, dstFolder string) error

MoveToFolderBatch moves multiple messages from one folder to another via IMAP.

func (*IMAPWorker) MoveToTrash

func (w *IMAPWorker) MoveToTrash(folder string, uid uint32) error

MoveToTrash moves a message to the Trash folder via IMAP (COPY + STORE \Deleted + EXPUNGE).

func (*IMAPWorker) MoveToTrashBatch

func (w *IMAPWorker) MoveToTrashBatch(folder string, uids []uint32, onProgress func(done, total int)) error

MoveToTrashBatch moves multiple messages to the Trash folder via IMAP. Processes UIDs in chunks to avoid server-side limits and timeouts. If onProgress is non-nil, it is called after each chunk with (done, total).

func (*IMAPWorker) Ping added in v0.10.4

func (w *IMAPWorker) Ping() bool

Ping checks if the IMAP connection is alive by issuing a NOOP command. Returns true if the connection is healthy.

func (*IMAPWorker) SetWantedFetchUID added in v0.10.1

func (w *IMAPWorker) SetWantedFetchUID(uid uint32)

SetWantedFetchUID records which UID the user currently wants fetched. Stale fetches (for a different UID) will skip after acquiring the lock.

func (*IMAPWorker) SyncFolder

func (w *IMAPWorker) SyncFolder(folder string, onProgress ...func(fetched int)) (int, error)

SyncFolder syncs a single folder via IMAP FETCH. If onProgress is non-nil, it is called periodically with the number of new messages fetched so far.

type NewMailMsg

type NewMailMsg struct {
	Account string
	Folder  string
	Count   int
}

NewMailMsg signals that new mail arrived via IDLE.

type RestoreResult added in v0.9.0

type RestoreResult struct {
	Account   string
	DstFolder string
	Count     int
	Err       error
}

RestoreResult is the result of restoring messages from Trash via IMAP.

type SMTPWorker

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

SMTPWorker handles sending email via SMTP.

func NewSMTPWorker

func NewSMTPWorker(acct config.AccountConfig, creds *auth.Credentials) *SMTPWorker

NewSMTPWorker creates a new SMTP worker.

func (*SMTPWorker) Send

func (w *SMTPWorker) Send(req SendRequest) (string, []byte, error)

Send sends an email and returns the message ID and the raw message bytes (for IMAP APPEND to Sent folder).

type SendRequest

type SendRequest struct {
	From    string
	To      string
	Subject string
	Body    string
}

SendRequest is a request to send an email via SMTP.

type SendResult

type SendResult struct {
	MessageID string
	Err       error
}

SendResult is the result of sending an email.

type SyncAccountCompleteMsg

type SyncAccountCompleteMsg struct {
	Account string
	Err     error
}

SyncAccountCompleteMsg signals that a single account finished syncing.

type SyncAllCompleteMsg

type SyncAllCompleteMsg struct {
	Errors []error
}

SyncAllCompleteMsg signals that initial sync of all accounts is done.

type SyncProgressMsg

type SyncProgressMsg struct {
	Account  string
	Folder   string
	Done     int // folders completed so far
	Total    int // total folders
	Messages int // messages fetched in current folder (0 = just started)
}

SyncProgressMsg reports per-folder progress during account sync.

type SyncRequest

type SyncRequest struct {
	Account string
	Folder  string
}

SyncRequest requests syncing a specific folder.

type SyncResult

type SyncResult struct {
	Account  string
	Folder   string
	NewCount int
	Err      error
}

SyncResult is the result of a folder sync.

Jump to

Keyboard shortcuts

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