Documentation
¶
Index ¶
- Variables
- func ComposeMessage(req SendRequest, opt ComposeOptions) (string, []byte, error)
- func ComposeRFC5322(from, to, subject, body string) (string, []byte)
- func ExtractCalendar(data []byte) []byte
- func FolderName(mailboxName string) string
- func NewMessageID(from string) string
- func ParseDraftMessage(raw []byte) (email.Draft, error)
- func ParseDraftMessagePGP(raw []byte, client *pgp.Client) (email.Draft, error)
- func ParseEnvelope(uid uint32, env *imap.Envelope, flags []imap.Flag) email.Message
- type AccountCheck
- type AttachmentData
- type BodyResult
- type CalendarPart
- type ComposeOptions
- type ConnectionStatusMsg
- type Coordinator
- func (c *Coordinator) ArchiveMessagesNow(acctEmail, source string, uids []uint32) OperationResult
- func (c *Coordinator) DeleteFolder(acctEmail, folder string) tea.Cmd
- func (c *Coordinator) DeleteMessage(acctEmail, folder string, uid uint32) tea.Cmd
- func (c *Coordinator) DeleteMessages(acctEmail, folder string, uids []uint32) tea.Cmd
- func (c *Coordinator) DisconnectAll()
- func (c *Coordinator) ExportMessages(acctEmail, folder string, messages []email.Message) tea.Cmd
- func (c *Coordinator) FetchBody(acctEmail, folder string, uid uint32) tea.Cmd
- func (c *Coordinator) FetchBodyNow(acctEmail, folder string, uid uint32) (BodyResult, error)
- func (c *Coordinator) FlushDraftOps(account string) tea.Cmd
- func (c *Coordinator) FlushDraftOpsNow(account string) error
- func (c *Coordinator) MarkAllRead(acctEmail, folder string) tea.Cmd
- func (c *Coordinator) MarkAllReadNow(acctEmail, folder string) MarkReadResult
- func (c *Coordinator) MarkRead(acctEmail, folder string, uid uint32) tea.Cmd
- func (c *Coordinator) MarkReadMessages(acctEmail, folder string, uids []uint32) tea.Cmd
- func (c *Coordinator) MarkReadMessagesNow(acctEmail, folder string, uids []uint32) MarkReadResult
- func (c *Coordinator) MarkUnreadMessages(acctEmail, folder string, uids []uint32) tea.Cmd
- func (c *Coordinator) MarkUnreadMessagesNow(acctEmail, folder string, uids []uint32) OperationResult
- func (c *Coordinator) MoveMessages(acctEmail, source, destination string, uids []uint32) tea.Cmd
- func (c *Coordinator) MoveMessagesNow(acctEmail, source, destination string, uids []uint32) OperationResult
- func (c *Coordinator) PGP() *pgp.Client
- func (c *Coordinator) PeekBodyNow(acctEmail, folder string, uid uint32) (BodyResult, error)
- func (c *Coordinator) ResolveCredentials() []error
- func (c *Coordinator) RespondToInvitation(acctEmail, folder string, uid uint32, status string) tea.Cmd
- func (c *Coordinator) RespondToInvitationNow(acctEmail, folder string, uid uint32, status string) InvitationReply
- func (c *Coordinator) RestoreFromTrash(acctEmail string, uids []uint32, dstFolder string) tea.Cmd
- func (c *Coordinator) RetryPendingOps() tea.Cmd
- func (c *Coordinator) SaveAttachments(acctEmail, folder string, uid uint32, attachments []email.Attachment) tea.Cmd
- func (c *Coordinator) SearchServerNow(acctEmail, query string, limit int) ServerSearchResult
- func (c *Coordinator) SendAndArchive(acctEmail string, req SendRequest) tea.Cmd
- func (c *Coordinator) SendNow(acctEmail string, req SendRequest) SendResult
- func (c *Coordinator) SetFlaggedMessages(acctEmail, folder string, uids []uint32, flagged bool) tea.Cmd
- func (c *Coordinator) SetFlaggedMessagesNow(acctEmail, folder string, uids []uint32, flagged bool) OperationResult
- func (c *Coordinator) SetPGP(client *pgp.Client)
- func (c *Coordinator) SetProgram(p *tea.Program)
- func (c *Coordinator) SourceAttachments(account, folder string, uid uint32) ([]email.DraftAttachment, error)
- func (c *Coordinator) SyncAccountFullNow(acctEmail string) (int, error)
- func (c *Coordinator) SyncAccountNow(acctEmail string) (int, error)
- func (c *Coordinator) SyncAll() tea.Cmd
- func (c *Coordinator) SyncFolder(acctEmail, folder string) tea.Cmd
- func (c *Coordinator) SyncFolderFullNow(acctEmail, folder string) (int, error)
- func (c *Coordinator) SyncFolderIfIdle(acctEmail, folder string) tea.Cmd
- func (c *Coordinator) SyncFolderNow(acctEmail, folder string) (int, error)
- func (c *Coordinator) VerifyAll(full bool) tea.Cmd
- func (c *Coordinator) VerifyFolder(acctEmail, folder string, full bool) tea.Cmd
- func (c *Coordinator) VerifyFolderNow(acctEmail, folder string, full bool) VerifyResult
- func (c *Coordinator) VerifyFoldersNow(acctEmail string, folders []string, full bool) []VerifyResult
- type DeleteProgressMsg
- type DeleteResult
- type ExportProgressMsg
- type FetchBodyRequest
- type FetchBodyResult
- type FolderListResult
- type IMAPWorker
- func (w *IMAPWorker) AddFlag(folder string, uids []uint32, flag, messageID string) error
- func (w *IMAPWorker) AppendToFolder(folder string, message []byte, flags []imap.Flag) error
- func (w *IMAPWorker) AppendWithUID(folder string, message []byte, flags []imap.Flag) (uint32, error)
- func (w *IMAPWorker) BackfillHeaders(folder string) (int, error)
- func (w *IMAPWorker) Connect() error
- func (w *IMAPWorker) DeleteByMessageIDs(folder string, ids []string) error
- func (w *IMAPWorker) DeleteMailbox(folder string) error
- func (w *IMAPWorker) Disconnect()
- func (w *IMAPWorker) FetchBody(folder string, uid uint32) (BodyResult, error)
- func (w *IMAPWorker) FetchBodyDirect(folder string, uid uint32) (BodyResult, error)
- func (w *IMAPWorker) FetchHeaders(folder string, uids []uint32) error
- func (w *IMAPWorker) FetchRawMessage(folder string, uid uint32) ([]byte, error)
- func (w *IMAPWorker) FolderStatus(folder string) (uidNext uint32, uidValidity uint32, err error)
- func (w *IMAPWorker) Idle(folder string, timeout time.Duration) (bool, error)
- func (w *IMAPWorker) IsConnected() bool
- func (w *IMAPWorker) ListMailboxes() ([]string, error)
- func (w *IMAPWorker) MarkAllRead(folder string) error
- func (w *IMAPWorker) MarkRead(folder string, uid uint32) error
- func (w *IMAPWorker) MarkReadBatch(folder string, uids []uint32) error
- func (w *IMAPWorker) MarkUnreadBatch(folder string, uids []uint32) error
- func (w *IMAPWorker) MoveToFolder(srcFolder string, uid uint32, dstFolder string) error
- func (w *IMAPWorker) MoveToFolderBatch(srcFolder string, uids []uint32, dstFolder string) error
- func (w *IMAPWorker) MoveToFolderBatchWithUIDs(srcFolder string, uids []uint32, dstFolder string) ([]UIDMove, error)
- func (w *IMAPWorker) MoveToTrash(folder string, uid uint32) error
- func (w *IMAPWorker) MoveToTrashBatch(folder string, uids []uint32, onProgress func(done, total int)) error
- func (w *IMAPWorker) PeekBodyDirect(folder string, uid uint32) (BodyResult, error)
- func (w *IMAPWorker) PeekRawMessage(folder string, uid uint32) ([]byte, error)
- func (w *IMAPWorker) Ping() bool
- func (w *IMAPWorker) SearchFolder(folder, query string) ([]uint32, error)
- func (w *IMAPWorker) SetFlaggedBatch(folder string, uids []uint32, flagged bool) error
- func (w *IMAPWorker) SetWantedFetchUID(uid uint32)
- func (w *IMAPWorker) SyncFolder(folder string, onProgress ...func(fetched int)) (int, error)
- func (w *IMAPWorker) SyncFolderFull(folder string, onProgress ...func(fetched int)) (int, error)
- func (w *IMAPWorker) VerifyFolder(folder string) (VerifyResult, error)
- type InvitationReply
- type MarkReadResult
- type NewMailMsg
- type OperationResult
- type RestoreResult
- type SMTPWorker
- type SendRequest
- type SendResult
- type ServerSearchResult
- type SyncAccountCompleteMsg
- type SyncAccountLateCompleteMsg
- type SyncAllCompleteMsg
- type SyncProgressMsg
- type SyncRequest
- type SyncResult
- type UIDMove
- type VerifyCompleteMsg
- type VerifyResult
Constants ¶
This section is empty.
Variables ¶
var ErrFetchSuperseded = errors.New("fetch superseded")
ErrFetchSuperseded reports that a body fetch was skipped because the user selected another message first. It is expected while scrolling, not a failure.
var ErrSyncLocked = errors.New("account sync is locked by another process")
ErrSyncLocked reports that another process currently owns the account sync. Callers must not treat this as a successful zero-message sync.
Functions ¶
func ComposeMessage ¶ added in v0.17.0
func ComposeMessage(req SendRequest, opt ComposeOptions) (string, []byte, error)
ComposeMessage serializes req as an RFC 5322 message: text/plain alone, or multipart/mixed with attachments. Recipients must already be validated (email.NormalizeAddresses); header values are sanitized again here because they may come from queued payloads or MCP arguments, and a CR/LF would let the caller inject headers.
func ComposeRFC5322 ¶
ComposeRFC5322 builds a plain-text message. Returns the Message-ID (without angle brackets) and the raw message bytes.
func ExtractCalendar ¶ added in v0.18.0
ExtractCalendar returns the first calendar part of a message (a text/calendar part, or an .ics attachment), or nil.
func FolderName ¶
FolderName maps an IMAP mailbox name to a display name.
func NewMessageID ¶ added in v0.17.0
NewMessageID returns a fresh Message-ID (without brackets) whose domain part is taken from the sender address.
func ParseDraftMessage ¶ added in v0.17.0
ParseDraftMessage turns a message from the server Drafts folder into a draft: recipients (including Bcc, which drafts keep), subject, plain-text body, threading headers, source and attachment content. The content was written by whatever client saved the draft, so every field is sanitized.
func ParseDraftMessagePGP ¶ added in v0.18.0
ParseDraftMessagePGP is ParseDraftMessage for a draft that may be encrypted (to its author): its content is decrypted with the client. An encrypted draft that cannot be decrypted is an error, never an empty draft.
Types ¶
type AccountCheck ¶ added in v0.18.0
type AccountCheck struct {
// Folders maps the display name of every folder to its server name
// (roles resolved as during sync), e.g. "Sent" → "[Gmail]/Gesendet".
Folders map[string]string
IMAPErr error
SMTPErr error
}
AccountCheck is the result of testing an account's settings.
func CheckAccount ¶ added in v0.18.0
func CheckAccount(acct config.AccountConfig, creds *auth.Credentials) AccountCheck
CheckAccount logs in to the account's IMAP and SMTP servers with the given credentials and lists its folders. Nothing is cached, synced or sent.
func (AccountCheck) OK ¶ added in v0.18.0
func (c AccountCheck) OK() bool
OK reports whether both servers accepted the login.
type AttachmentData ¶
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
// Security is the outcome of OpenPGP processing ("" for ordinary mail):
// whether the message was encrypted, and what its signature check said.
// It is kept apart from Text so a message cannot fake it.
Security string
// Decrypted marks Text as the plaintext of an encrypted message.
Decrypted bool
// Plain is the text/plain part as written ("" when there is none); Text
// prefers a conversion of the HTML part.
Plain 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.
func ParseBodyPGP ¶ added in v0.18.0
func ParseBodyPGP(data []byte, c *pgp.Client) (BodyResult, error)
ParseBodyPGP is ParseBody for accounts with PGP enabled: an encrypted message is decrypted, a signature is checked, and the result says so in Security.
type CalendarPart ¶ added in v0.18.0
CalendarPart is a calendar object sent with a message.
type ComposeOptions ¶ added in v0.17.0
type ComposeOptions struct {
// IncludeBcc writes the Bcc header. Only for copies the user keeps
// (Sent, Drafts): the transmitted message must never carry it, or every
// recipient learns who was blind-copied.
IncludeBcc bool
// MessageID and Date, when set, are used instead of fresh values so a
// retried send and its Sent copy carry the same identity.
MessageID string
Date time.Time
// PGP signs and encrypts messages that ask for it; nil when PGP is off.
PGP *pgp.Client
// DraftCopy encrypts to the sender alone (the copy in the Drafts folder).
DraftCopy bool
// Extra headers (name → value), e.g. X-Vimail-Source on drafts.
Extra map[string]string
// contains filtered or unexported fields
}
ComposeOptions controls how a message is serialized.
type ConnectionStatusMsg ¶
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) ArchiveMessagesNow ¶ added in v0.18.0
func (c *Coordinator) ArchiveMessagesNow(acctEmail, source string, uids []uint32) OperationResult
ArchiveMessagesNow archives messages: the cache is updated at once and the server move goes through the operation queue, so it works offline.
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
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. It must be called from the bubbletea Update loop: creating the command records uid as the account's wanted message, superseding earlier selections.
func (*Coordinator) FetchBodyNow ¶ added in v0.11.0
func (c *Coordinator) FetchBodyNow(acctEmail, folder string, uid uint32) (BodyResult, error)
FetchBodyNow synchronously fetches and caches one message body, connecting lazily when this coordinator has not synced the account yet. This is the non-Bubble Tea seam used by MCP batch reads.
func (*Coordinator) FlushDraftOps ¶ added in v0.17.0
func (c *Coordinator) FlushDraftOps(account string) tea.Cmd
FlushDraftOps is FlushDraftOpsNow as a tea.Cmd for the TUI.
func (*Coordinator) FlushDraftOpsNow ¶ added in v0.17.0
func (c *Coordinator) FlushDraftOpsNow(account string) error
FlushDraftOpsNow runs the account's queued draft uploads/deletes and flag ops immediately. It returns the first delivery error; failed ops stay queued and retry on the next sync.
func (*Coordinator) MarkAllRead ¶ added in v0.12.0
func (c *Coordinator) MarkAllRead(acctEmail, folder string) tea.Cmd
MarkAllRead returns the TUI command form of the authoritative whole-folder operation.
func (*Coordinator) MarkAllReadNow ¶ added in v0.12.0
func (c *Coordinator) MarkAllReadNow(acctEmail, folder string) MarkReadResult
MarkAllReadNow queues one authoritative whole-folder IMAP operation. Unlike UID batches, it also covers messages absent from a stale local cache.
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.
It is the TUI's per-selection path: the op is queued durably right away, but delivery is deferred by markReadFlushDelay so scrolling through many messages sends one batched STORE per folder instead of one IMAP round trip (plus a connection check) per message, which used to starve sync and body fetches on the shared connection.
func (*Coordinator) MarkReadMessages ¶ added in v0.11.0
func (c *Coordinator) MarkReadMessages(acctEmail, folder string, uids []uint32) tea.Cmd
MarkReadMessages queues and executes one batched mark-read operation.
func (*Coordinator) MarkReadMessagesNow ¶ added in v0.12.0
func (c *Coordinator) MarkReadMessagesNow(acctEmail, folder string, uids []uint32) MarkReadResult
MarkReadMessagesNow is the synchronous seam used by MCP. It keeps the same durable queue semantics as the TUI command while returning delivery state.
func (*Coordinator) MarkUnreadMessages ¶ added in v0.13.0
func (c *Coordinator) MarkUnreadMessages(acctEmail, folder string, uids []uint32) tea.Cmd
func (*Coordinator) MarkUnreadMessagesNow ¶ added in v0.13.0
func (c *Coordinator) MarkUnreadMessagesNow(acctEmail, folder string, uids []uint32) OperationResult
func (*Coordinator) MoveMessages ¶ added in v0.13.0
func (c *Coordinator) MoveMessages(acctEmail, source, destination string, uids []uint32) tea.Cmd
func (*Coordinator) MoveMessagesNow ¶ added in v0.13.0
func (c *Coordinator) MoveMessagesNow(acctEmail, source, destination string, uids []uint32) OperationResult
func (*Coordinator) PGP ¶ added in v0.18.0
func (c *Coordinator) PGP() *pgp.Client
PGP returns the coordinator's OpenPGP client (nil when PGP is off).
func (*Coordinator) PeekBodyNow ¶ added in v0.11.0
func (c *Coordinator) PeekBodyNow(acctEmail, folder string, uid uint32) (BodyResult, error)
PeekBodyNow synchronously fetches and caches one message body without setting its IMAP \Seen flag. MCP review uses this path to remain read-only.
func (*Coordinator) ResolveCredentials ¶
func (c *Coordinator) ResolveCredentials() []error
ResolveCredentials resolves and caches credentials for all accounts. Should be called before SyncAll.
func (*Coordinator) RespondToInvitation ¶ added in v0.18.0
func (c *Coordinator) RespondToInvitation(acctEmail, folder string, uid uint32, status string) tea.Cmd
RespondToInvitation is RespondToInvitationNow as a tea.Cmd.
func (*Coordinator) RespondToInvitationNow ¶ added in v0.18.0
func (c *Coordinator) RespondToInvitationNow(acctEmail, folder string, uid uint32, status string) InvitationReply
RespondToInvitationNow answers the invitation in a message: it sends the organizer a calendar REPLY with the user's participation status, from the address that was invited. The message is read without marking it read.
func (*Coordinator) RestoreFromTrash ¶ added in v0.9.0
RestoreFromTrash queues and attempts a server-first restore. Cache rows stay in Trash until IMAP confirms the move, then they are reconciled using the destination UIDs returned by MOVE/COPYUID.
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) SearchServerNow ¶ added in v0.18.0
func (c *Coordinator) SearchServerNow(acctEmail, query string, limit int) ServerSearchResult
SearchServerNow searches an account's folders on the server (headers and bodies, including mail whose body was never downloaded) and returns the matching messages from the cache, fetching headers for hits it does not hold. Label copies of one message are returned once. Trash, Spam and Drafts are not searched.
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) SendNow ¶ added in v0.11.0
func (c *Coordinator) SendNow(acctEmail string, req SendRequest) SendResult
SendNow synchronously sends an email through the queued SendAndArchive path, creating the SMTP worker (and, best-effort, the IMAP worker for the Sent append) if needed. For callers without a bubbletea loop (the MCP server). The queued op keeps a failed send retryable, and op claiming guarantees it executes at most once across processes.
func (*Coordinator) SetFlaggedMessages ¶ added in v0.13.0
func (*Coordinator) SetFlaggedMessagesNow ¶ added in v0.13.0
func (c *Coordinator) SetFlaggedMessagesNow(acctEmail, folder string, uids []uint32, flagged bool) OperationResult
func (*Coordinator) SetPGP ¶ added in v0.18.0
func (c *Coordinator) SetPGP(client *pgp.Client)
SetPGP replaces the OpenPGP client (tests use a throwaway keyring). Connected workers switch to it as well.
func (*Coordinator) SetProgram ¶
func (c *Coordinator) SetProgram(p *tea.Program)
SetProgram sets the bubbletea program reference for sending async progress messages.
func (*Coordinator) SourceAttachments ¶ added in v0.17.0
func (c *Coordinator) SourceAttachments(account, folder string, uid uint32) ([]email.DraftAttachment, error)
SourceAttachments fetches the attachments of a message being forwarded, without marking it read.
func (*Coordinator) SyncAccountFullNow ¶ added in v0.12.0
func (c *Coordinator) SyncAccountFullNow(acctEmail string) (int, error)
SyncAccountFullNow synchronously rebuilds every server folder in the local cache. Use this explicit recovery path when incremental UID watermarks can no longer reconcile moved or removed messages.
func (*Coordinator) SyncAccountNow ¶ added in v0.11.0
func (c *Coordinator) SyncAccountNow(acctEmail string) (int, error)
SyncAccountNow synchronously connects (if needed), drains the account's queued ops, and syncs all its folders, returning the number of newly fetched messages. For callers without a bubbletea loop (the MCP server).
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.
func (*Coordinator) SyncFolderFullNow ¶ added in v0.12.0
func (c *Coordinator) SyncFolderFullNow(acctEmail, folder string) (int, error)
SyncFolderFullNow replaces one cached folder with an authoritative snapshot fetched from IMAP. The remote fetch completes before existing rows are removed, so a network failure leaves the old cache intact.
func (*Coordinator) SyncFolderIfIdle ¶ added in v0.11.0
func (c *Coordinator) SyncFolderIfIdle(acctEmail, folder string) tea.Cmd
SyncFolderIfIdle returns a tea.Cmd that syncs the folder, or nil if a coalesced sync for the same account/folder pair is already in flight. Stale-UID recovery uses this so a rapid burst of missing-message errors triggers exactly one folder sync instead of one per UID. The in-flight mark is claimed synchronously (before the returned cmd runs) and released when the sync finishes, whether it succeeds or fails.
func (*Coordinator) SyncFolderNow ¶ added in v0.11.0
func (c *Coordinator) SyncFolderNow(acctEmail, folder string) (int, error)
SyncFolderNow synchronously syncs a single folder, connecting if needed, and returns the number of newly fetched messages. It honors the same cross-process sync lock as full account syncs.
func (*Coordinator) VerifyFolder ¶ added in v0.13.0
func (c *Coordinator) VerifyFolder(acctEmail, folder string, full bool) tea.Cmd
func (*Coordinator) VerifyFolderNow ¶ added in v0.13.0
func (c *Coordinator) VerifyFolderNow(acctEmail, folder string, full bool) VerifyResult
func (*Coordinator) VerifyFoldersNow ¶ added in v0.13.0
func (c *Coordinator) VerifyFoldersNow(acctEmail string, folders []string, full bool) []VerifyResult
VerifyFoldersNow verifies several folders of one account, running the cache-wide SQLite checks once instead of per folder.
type DeleteProgressMsg ¶
DeleteProgressMsg reports incremental progress during batch deletion.
type DeleteResult ¶
DeleteResult is the result of deleting a message via IMAP.
type ExportProgressMsg ¶ added in v0.9.0
ExportProgressMsg reports incremental progress during batch export.
type FetchBodyRequest ¶
FetchBodyRequest requests lazy-loading a message body.
type FetchBodyResult ¶
type FetchBodyResult struct {
Account string
Folder string
UID uint32
Body string
// Security is the outcome of OpenPGP processing ("" for ordinary mail).
Security string
HTMLBody string
Attachments []email.Attachment
Err error
}
FetchBodyResult is the result of fetching a message body.
type FolderListResult ¶
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) AddFlag ¶ added in v0.17.0
func (w *IMAPWorker) AddFlag(folder string, uids []uint32, flag, messageID string) error
AddFlag adds a flag to messages, after checking (when messageID is given) that the UIDs still hold that message.
func (*IMAPWorker) AppendToFolder ¶
AppendToFolder appends a message to a server folder (e.g. Sent).
func (*IMAPWorker) AppendWithUID ¶ added in v0.17.0
func (w *IMAPWorker) AppendWithUID(folder string, message []byte, flags []imap.Flag) (uint32, error)
AppendWithUID appends a message and returns the UID the server assigned (0 when the server does not support UIDPLUS).
func (*IMAPWorker) BackfillHeaders ¶ added in v0.17.0
func (w *IMAPWorker) BackfillHeaders(folder string) (int, error)
BackfillHeaders refetches headers (not bodies) for cached rows older than cache.HeadersVersion, filling cc, reply-to, full To and threading headers. It returns how many rows were updated.
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) DeleteByMessageIDs ¶ added in v0.17.0
func (w *IMAPWorker) DeleteByMessageIDs(folder string, ids []string) error
DeleteByMessageIDs permanently removes the messages in folder whose Message-ID header matches one of ids. Used for superseded and deleted drafts, where a UID may be unknown or stale but the Message-ID is ours.
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) FetchHeaders ¶ added in v0.18.0
func (w *IMAPWorker) FetchHeaders(folder string, uids []uint32) error
FetchHeaders caches the headers of the given UIDs (used for search hits the cache does not hold yet).
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 ¶
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) MarkAllRead ¶ added in v0.12.0
func (w *IMAPWorker) MarkAllRead(folder string) error
MarkAllRead marks every message in a folder read without enumerating UIDs. The UID range also covers messages that the local cache has not seen yet.
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) MarkUnreadBatch ¶ added in v0.13.0
func (w *IMAPWorker) MarkUnreadBatch(folder string, uids []uint32) error
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) MoveToFolderBatchWithUIDs ¶ added in v0.12.0
func (w *IMAPWorker) MoveToFolderBatchWithUIDs(srcFolder string, uids []uint32, dstFolder string) ([]UIDMove, error)
MoveToFolderBatchWithUIDs moves messages with native IMAP MOVE (or the library's UID-safe fallback) and returns destination UID mappings when the server advertises UIDPLUS/IMAP4rev2.
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) PeekBodyDirect ¶ added in v0.11.0
func (w *IMAPWorker) PeekBodyDirect(folder string, uid uint32) (BodyResult, error)
PeekBodyDirect fetches and caches a message body without setting the IMAP \Seen flag. It is used for background/MCP review where reading must not change mailbox state.
func (*IMAPWorker) PeekRawMessage ¶ added in v0.17.0
func (w *IMAPWorker) PeekRawMessage(folder string, uid uint32) ([]byte, error)
PeekRawMessage fetches a whole message without setting \Seen.
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) SearchFolder ¶ added in v0.18.0
func (w *IMAPWorker) SearchFolder(folder, query string) ([]uint32, error)
SearchFolder asks the server which messages in a folder contain the text anywhere (headers or body) and returns their UIDs, newest first.
func (*IMAPWorker) SetFlaggedBatch ¶ added in v0.13.0
func (w *IMAPWorker) SetFlaggedBatch(folder string, uids []uint32, flagged bool) error
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.
func (*IMAPWorker) SyncFolderFull ¶ added in v0.12.0
func (w *IMAPWorker) SyncFolderFull(folder string, onProgress ...func(fetched int)) (int, error)
SyncFolderFull fetches an authoritative folder snapshot and only then replaces the cached headers. This reconciles server-side moves and deletes that incremental UID fetching cannot observe.
func (*IMAPWorker) VerifyFolder ¶ added in v0.13.0
func (w *IMAPWorker) VerifyFolder(folder string) (VerifyResult, error)
VerifyFolder reconciles cached UIDs and mutable flags with the server while preserving UIDs covered by queued optimistic writes.
type InvitationReply ¶ added in v0.18.0
type InvitationReply struct {
Organizer string // where the answer went
Summary string
Status string
Err error
}
InvitationReply is the outcome of answering an invitation.
type MarkReadResult ¶ added in v0.12.0
MarkReadResult reports whether a queued mark-read operation reached IMAP or remains durable for retry.
type NewMailMsg ¶
NewMailMsg signals that new mail arrived via IDLE.
type OperationResult ¶ added in v0.13.0
type RestoreResult ¶ added in v0.9.0
type RestoreResult struct {
Account string
DstFolder string
Count int
Remaining []uint32
OpID int64
Delivered bool
Cached bool
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) Check ¶ added in v0.18.0
func (w *SMTPWorker) Check() error
Check logs in to the SMTP server and disconnects, without sending anything. Account setup uses it to test settings before saving them.
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 to keep in Sent (with Bcc). The transmitted bytes never contain Bcc.
type SendRequest ¶
type SendRequest struct {
From string // header From: the account address or one of its identities
// To is a comma-separated recipient string (legacy callers); ToList
// holds one address per entry. Both are sent to.
To string
ToList []string
Cc []string
Bcc []string // envelope only; never in the transmitted headers
Subject string
Body string
// Markdown sends the body with a rendered text/html alternative.
Markdown bool
// Sign and Encrypt ask for OpenPGP (PGP/MIME) with the sender's key and
// the recipients' keys.
Sign bool
Encrypt bool
// Calendar adds a calendar object as an alternative of the body (the
// answer to an invitation).
Calendar *CalendarPart
InReplyTo string
References []string
Attachments []email.DraftAttachment
// Source is the replied-to or forwarded original; after a successful send
// it is flagged \Answered or $Forwarded.
Source *email.DraftSource
// MessageID and Date pin the message identity across retries.
MessageID string
Date time.Time
}
SendRequest is a request to send an email via SMTP.
func DraftSendRequest ¶ added in v0.17.0
func DraftSendRequest(d email.Draft, defaultFrom string) SendRequest
DraftSendRequest converts a draft into the request that sends it.
type SendResult ¶
SendResult is the result of sending an email.
type ServerSearchResult ¶ added in v0.18.0
type ServerSearchResult struct {
Messages []email.Message
// Errors holds per-folder failures; the other folders' hits are kept.
Errors []error
}
ServerSearchResult is the outcome of searching an account on the server.
type SyncAccountCompleteMsg ¶
SyncAccountCompleteMsg signals that a single account finished syncing.
type SyncAccountLateCompleteMsg ¶ added in v0.14.1
SyncAccountLateCompleteMsg reports the result of an account sync that outlived the TUI's wait and finished in the background.
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 ¶
SyncRequest requests syncing a specific folder.
type SyncResult ¶
SyncResult is the result of a folder sync.
type UIDMove ¶ added in v0.12.0
UIDMove maps a source mailbox UID to the UID assigned in the destination mailbox by IMAP MOVE/COPYUID. Destination is zero when the server did not report one.
type VerifyCompleteMsg ¶ added in v0.13.0
type VerifyCompleteMsg struct{ Results []VerifyResult }