Documentation
¶
Index ¶
- Constants
- Variables
- func ClearRecentMessages() error
- func DeleteMutator(client *Client, item *BatchItem) error
- func IsArchiveAlias(mailboxName string) bool
- func IsNotFound(err error) bool
- func IsSpecialMailboxName(mailboxType, mailboxName string) bool
- func NormalizeThreadSubject(subject string) string
- func ParseMessageTime(value string) (time.Time, bool)
- func RecordRecentMessage(message Message, action string) error
- func RecordRecentSearchResults(messages []Message, query string) error
- func RemoveRecentMessage(account, messageID string) error
- func SenderMatches(rawSender, sender, senderDomain string) bool
- func ThreadArchiveAllowed(thread ThreadSummary) bool
- func UpdateRecentMessageLocation(account, messageID, mailbox, action string) error
- func ValidateRuleInput(input RuleInput) error
- func VerifyMutation(client *Client, opts BatchOptions, item BatchItem) (string, error)
- type Account
- type Attachment
- type AutomationLockTimeoutError
- type AutomationTimeoutError
- type BatchFailedError
- type BatchItem
- type BatchJournal
- type BatchOptions
- type BatchResult
- type CapabilityError
- type CapabilityStatus
- type Client
- func (c *Client) Accounts() ([]Account, error)
- func (c *Client) ArchiveMessage(accountName, mailboxName, messageID string) error
- func (c *Client) ArchiveMessageWithDestination(accountName, mailboxName, messageID string) (string, error)
- func (c *Client) BulkArchiveMessages(requests []struct{ ... }) error
- func (c *Client) BulkDeleteMessages(requests []struct{ ... }) error
- func (c *Client) BulkFlagMessages(requests []struct{ ... }) error
- func (c *Client) BulkMarkMessages(requests []struct{ ... }) error
- func (c *Client) BulkMoveMessages(requests []struct{ ... }) error
- func (c *Client) CheckAccountAccess(timeout time.Duration) (int, error)
- func (c *Client) CheckAutomationAccess(timeout time.Duration) error
- func (c *Client) CheckEnvelopeIndex() error
- func (c *Client) CheckMailBridge() error
- func (c *Client) Context() context.Context
- func (c *Client) CreateDraft(input DraftInput) (*Message, error)
- func (c *Client) CreateRule(input RuleInput) (*Rule, error)
- func (c *Client) DeleteDraft(accountName, draftID string) error
- func (c *Client) DeleteMessage(accountName, mailboxName, messageID string) error
- func (c *Client) DeleteMessageResolved(accountName, mailboxName, messageID string) error
- func (c *Client) DeleteRule(name string) error
- func (c *Client) Done() error
- func (c *Client) FlagMessage(accountName, mailboxName, messageID string, flagged bool) error
- func (c *Client) GetAccounts() ([]Account, error)
- func (c *Client) GetAccountsJSON() ([]Account, error)
- func (c *Client) GetAllMailboxes() ([]Mailbox, error)
- func (c *Client) GetAttachmentsJSON(accountName, mailboxName, messageID string) ([]Attachment, error)
- func (c *Client) GetDraft(accountName, draftID string) (*Message, error)
- func (c *Client) GetMailboxes(accountName string) ([]Mailbox, error)
- func (c *Client) GetMailboxesJSON(accountName string) ([]Mailbox, error)
- func (c *Client) GetMessageDetailsForVerificationJSON(accountName, mailboxName, messageID string) (*Message, error)
- func (c *Client) GetMessageDetailsJSON(accountName, mailboxName, messageID string) (*Message, error)
- func (c *Client) GetMessageStateForVerificationJSON(accountName, mailboxName, messageID string) (*Message, error)
- func (c *Client) GetMessages(accountName, mailboxName string, limit int) ([]Message, error)
- func (c *Client) GetMessagesFromMultipleMailboxes(requests []MailboxListRequest) ([]Message, error)
- func (c *Client) GetMessagesJSON(accountName, mailboxName string, limit, offset int, ...) ([]Message, error)
- func (c *Client) GetMultipleMessageDetails(requests []MessageRef) ([]*Message, error)
- func (c *Client) GetUnifiedMessagesJSON(mailboxType string, limit, offset int, withContent bool) ([]Message, error)
- func (c *Client) GetUnreadCount() (int, error)
- func (c *Client) HasMessageIdentityInMailbox(accountName, mailboxName string, identity StableIdentity) (bool, error)
- func (c *Client) ListMessages(req MailboxListRequest) ([]Message, error)
- func (c *Client) ListRules() ([]Rule, error)
- func (c *Client) ListSignatures(includeContent bool) ([]Signature, error)
- func (c *Client) ListSmartMailboxes() ([]SmartMailbox, error)
- func (c *Client) ListUnified(kind string, limit, offset int) ([]Message, error)
- func (c *Client) LocateMessage(id string) (*MessageLocation, error)
- func (c *Client) LocateMessages(ids []string) (map[string]MessageLocation, error)
- func (c *Client) Mailboxes(account string) ([]Mailbox, error)
- func (c *Client) MarkMessageAsRead(accountName, mailboxName, messageID string, read bool) error
- func (c *Client) MessageDetails(account, mailbox, id string) (*Message, error)
- func (c *Client) MoveMessage(accountName, sourceMailbox, messageID, targetMailbox string) error
- func (c *Client) PrimeAccounts(accounts []Account)
- func (c *Client) ReadSelectedMessages(refs []MessageRef, timeout, budget time.Duration) SelectedReadResult
- func (c *Client) RecordRecentEnvelope(accountName, mailboxName, messageID, action string) error
- func (c *Client) ResetAccountCache()
- func (c *Client) RunLiveProbe(timeout time.Duration) error
- func (c *Client) SaveAttachment(accountName, mailboxName, messageID, attachmentName, savePath string) error
- func (c *Client) SaveAttachmentByIndex(accountName, mailboxName, messageID, attachmentName string, index int, ...) error
- func (c *Client) ScanMessages(req ScanRequest) (ScanResult, error)
- func (c *Client) Search(query, account string, limit int) (SearchResult, error)
- func (c *Client) SearchMessages(query string, limit int) ([]Message, error)
- func (c *Client) SearchMessagesJSON(query string, accountName string, mailboxName string, limit int) ([]Message, error)
- func (c *Client) SearchMessagesJSONSince(query string, accountName string, mailboxName string, limit int, since string) ([]Message, error)
- func (c *Client) SearchMessagesJSONSinceWithOptions(query string, accountName string, mailboxName string, limit int, since string, ...) (SearchResult, error)
- func (c *Client) SendDraft(accountName, draftID string) error
- func (c *Client) SendMessage(accountName, subject, body string, to, cc, bcc, attachments []string) error
- func (c *Client) SetRuleEnabled(name string, enabled bool) error
- func (c *Client) SetWarn(fn func(string))
- func (c *Client) SignatureByName(name string) (*Signature, error)
- func (c *Client) SyncAccount(accountName string) error
- func (c *Client) SyncAllAccounts() error
- func (c *Client) UpdateDraft(accountName, draftID string, input DraftInput) (*Message, error)
- func (c *Client) WithContext(ctx context.Context) *Client
- type DraftInput
- type Mailbox
- type MailboxListRequest
- type Message
- type MessageLocation
- type MessageReadResult
- type MessageRef
- type Mutator
- type NotFoundError
- type PartialSearchError
- type RecentMessage
- type Rule
- type RuleInput
- type ScanCoverage
- type ScanMessage
- type ScanRequest
- type ScanResult
- type SearchMailbox
- type SearchMailboxFailure
- type SearchOptions
- type SearchResult
- type SelectedReadResult
- type Sender
- type Signature
- type SmartMailbox
- type StableIdentity
- type ThreadSummary
Constants ¶
const DoctorProbeTimeout = 3 * time.Second
DoctorProbeTimeout bounds each read-only Mail.app diagnostic. Keeping the probes separate lets doctor report partial diagnostics when one Mail.app API surface is unavailable.
const SchemaVersion = 1
SchemaVersion identifies the JSON shape of every structured value this package emits. Bump it when a field is renamed or removed.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is the sentinel every lookup failure unwraps to, so callers can classify with errors.Is without matching message text.
Warn is the default sink for non-fatal warnings (index fallback, content budget, journal cleanup). A Client can be given its own with SetWarn.
Functions ¶
func ClearRecentMessages ¶
func ClearRecentMessages() error
func DeleteMutator ¶ added in v2.1.0
DeleteMutator moves a message to the trash.
func IsArchiveAlias ¶
IsArchiveAlias reports whether a mailbox name refers to Gmail's All Mail or a generic Archive mailbox.
func IsNotFound ¶
IsNotFound reports whether err is a typed lookup failure or one of the automation bridge's "Error: ... not found" strings.
func IsSpecialMailboxName ¶ added in v2.1.0
IsSpecialMailboxName reports whether a mailbox name is one of the conventional names for the sent, drafts, trash, or junk folder.
func NormalizeThreadSubject ¶ added in v2.1.0
NormalizeThreadSubject strips reply and forward prefixes and collapses whitespace so replies land in the same thread.
func ParseMessageTime ¶ added in v2.1.0
ParseMessageTime parses the timestamp shapes Mail.app and the Envelope Index produce.
func RecordRecentMessage ¶
func RemoveRecentMessage ¶
func SenderMatches ¶ added in v2.1.0
SenderMatches reports whether a raw sender header satisfies the filters.
func ThreadArchiveAllowed ¶ added in v2.1.0
func ThreadArchiveAllowed(thread ThreadSummary) bool
ThreadArchiveAllowed reports whether a thread can be archived as a unit.
func ValidateRuleInput ¶
ValidateRuleInput verifies the complete input contract before a rule is created. Callers should use it for dry runs as well as live rule creation.
func VerifyMutation ¶ added in v2.1.0
func VerifyMutation(client *Client, opts BatchOptions, item BatchItem) (string, error)
VerifyMutation verifies one mutation for library callers. RunBatch uses VerifyMutations so a whole batch can share indexed snapshots and Gmail sync.
Types ¶
type Attachment ¶
type AutomationLockTimeoutError ¶
AutomationLockTimeoutError reports a command that could not enter the serialized automation queue within its bounded wait period.
func (*AutomationLockTimeoutError) Error ¶
func (e *AutomationLockTimeoutError) Error() string
func (*AutomationLockTimeoutError) Unwrap ¶
func (e *AutomationLockTimeoutError) Unwrap() error
type AutomationTimeoutError ¶
AutomationTimeoutError reports a bounded Mail.app automation invocation that did not complete. It unwraps to context.DeadlineExceeded so callers can classify it with errors.Is, and exposes the engine and configured timeout for human-readable diagnostics.
func (*AutomationTimeoutError) Error ¶
func (e *AutomationTimeoutError) Error() string
func (*AutomationTimeoutError) Unwrap ¶
func (e *AutomationTimeoutError) Unwrap() error
type BatchFailedError ¶ added in v2.1.0
BatchFailedError reports mutation failures and requested verifications that remained inconclusive after the mutation was applied.
func (*BatchFailedError) Error ¶ added in v2.1.0
func (e *BatchFailedError) Error() string
type BatchItem ¶ added in v2.1.0
type BatchItem struct {
ID string `json:"id"`
Account string `json:"account"`
SourceMailbox string `json:"sourceMailbox"`
TargetMailbox string `json:"targetMailbox,omitempty"`
Subject string `json:"subject,omitempty"`
Sender string `json:"sender,omitempty"`
DateSent string `json:"dateSent,omitempty"`
MessageSize int `json:"messageSize,omitempty"`
GmailInboxSource bool `json:"gmailInboxSource,omitempty"`
// Identity is captured before a move so verification survives Mail.app
// assigning the logical message a new local ID.
Identity StableIdentity `json:"identity,omitempty"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
MarkedRead bool `json:"markedRead,omitempty"`
VerifyStatus string `json:"verifyStatus,omitempty"`
VerifyError string `json:"verifyError,omitempty"`
}
BatchItem is one message inside a mutation receipt. The same shape is used whether one ID or five hundred were requested.
func VerifyMutations ¶ added in v2.1.3
func VerifyMutations(client *Client, opts BatchOptions, items []BatchItem) []BatchItem
VerifyMutations verifies a completed mutation batch. State-only mutations share one indexed snapshot per account/mailbox instead of enumerating the entire Mail.app mailbox once per item.
type BatchJournal ¶ added in v2.1.1
type BatchJournal struct {
// contains filtered or unexported fields
}
BatchJournal is an append-only, durable mutation receipt. Each line is a complete JSON object so a caller can recover the work completed before an interrupted process lost its normal stdout receipt.
func CreateBatchJournal ¶ added in v2.1.1
func CreateBatchJournal(path string) (*BatchJournal, error)
CreateBatchJournal validates and creates path before any mailbox mutation. The caller owns Close.
func CreateDefaultBatchJournal ¶ added in v2.1.1
func CreateDefaultBatchJournal() (*BatchJournal, error)
CreateDefaultBatchJournal creates a private, persistent receipt outside the working tree. It is the safety net for library and UI callers that do not explicitly configure a receipt path.
func (*BatchJournal) Close ¶ added in v2.1.1
func (j *BatchJournal) Close() error
func (*BatchJournal) Path ¶ added in v2.1.1
func (j *BatchJournal) Path() string
func (*BatchJournal) Record ¶ added in v2.1.1
func (j *BatchJournal) Record(event string, fields map[string]any) error
Record appends and synchronizes one event. Syncing every event exceeds the per-chunk durability guarantee and deliberately favors recoverability over the small overhead of a bulk mutation receipt.
type BatchOptions ¶ added in v2.1.0
type BatchOptions struct {
Action string
TargetMailbox string
DryRun bool
Verify bool
MarkReadBefore bool
ChunkSize int
// ReuseBridge is for built-in JXA mutators, never custom mutators.
ReuseBridge bool
Read bool
Flagged bool
// Journal records each message in the recent-message journal. It costs
// index queries per message, so bulk selections leave it off.
Journal bool
// Progress receives per-chunk and per-message lines when non-nil.
Progress io.Writer
// TrustSource keeps each item's SourceMailbox as given. Otherwise an
// archive looks each message up in the Envelope Index and acts from
// INBOX or the backing mailbox, never from a user label, and skips
// messages that are already archived.
TrustSource bool
// ExplicitSource preserves an explicit non-Gmail source when the Envelope
// Index is unavailable. Gmail remains fail-closed because labels cannot be
// resolved safely without the index.
ExplicitSource bool
// Receipt is an append-only durable journal written before and after every
// mailbox-side phase. It is optional so library callers retain the existing
// in-memory receipt behavior.
Receipt *BatchJournal
}
BatchOptions controls one mutation run.
type BatchResult ¶ added in v2.1.0
type BatchResult struct {
Action string `json:"action"`
DryRun bool `json:"dryRun"`
StartedAt string `json:"startedAt,omitempty"`
EndedAt string `json:"endedAt,omitempty"`
ReceiptPath string `json:"receiptPath,omitempty"`
JournalError string `json:"journalError,omitempty"`
Matched int `json:"matched"`
Attempted int `json:"attempted"`
Succeeded int `json:"succeeded"`
Failed int `json:"failed"`
Unverified int `json:"unverified,omitempty"`
Skipped int `json:"skipped"`
Chunks int `json:"chunks,omitempty"`
Items []BatchItem `json:"items"`
}
BatchResult is the mutation receipt.
func RunBatch ¶ added in v2.1.0
func RunBatch(client *Client, opts BatchOptions, items []BatchItem, mutate Mutator) (result BatchResult, retErr error)
RunBatch applies mutate to every item and returns the receipt. The error is a *BatchFailedError when at least one item failed; the receipt is always complete. Cancelling the client's context stops the run between items.
func (BatchResult) Summary ¶ added in v2.1.0
func (r BatchResult) Summary(opts BatchOptions) string
Summary is the one-line human description of a receipt.
type CapabilityError ¶ added in v2.1.1
type CapabilityError struct {
Capability string
Status CapabilityStatus
Cause error
}
CapabilityError keeps a feature limitation distinct from an empty result. Callers should present this as a capability failure, never as an empty list.
func (*CapabilityError) Error ¶ added in v2.1.1
func (e *CapabilityError) Error() string
func (*CapabilityError) Unwrap ¶ added in v2.1.1
func (e *CapabilityError) Unwrap() error
type CapabilityStatus ¶ added in v2.1.1
type CapabilityStatus string
CapabilityStatus describes whether a Mail feature can be supplied by the backends this CLI is allowed to use.
const ( CapabilityUnsupported CapabilityStatus = "unsupported" )
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to Mail.app through osascript and to Mail's Envelope Index through sqlite3. Every subprocess it starts is bound to its context, so a caller that cancels stops waiting on a queued automation call.
func (*Client) ArchiveMessage ¶
func (*Client) ArchiveMessageWithDestination ¶
func (*Client) BulkArchiveMessages ¶
func (*Client) BulkDeleteMessages ¶
func (*Client) BulkFlagMessages ¶
func (*Client) BulkMarkMessages ¶
func (*Client) BulkMoveMessages ¶
func (*Client) CheckAccountAccess ¶
CheckAccountAccess verifies read access to the account collection and returns only its count, not account names or addresses.
func (*Client) CheckAutomationAccess ¶
CheckAutomationAccess verifies that the automation bridge can read a harmless Mail.app property. It is deliberately separate from the bridge probe because an installed application can still deny automation access.
func (*Client) CheckEnvelopeIndex ¶
func (*Client) CheckMailBridge ¶
CheckMailBridge verifies that the local Mail.app bundle is present without issuing an Apple Event. Automation permission is checked independently so a denied permission cannot be mistaken for a missing Mail installation.
func (*Client) Context ¶ added in v2.1.0
Context is the context the client's subprocesses run under.
func (*Client) CreateDraft ¶
func (c *Client) CreateDraft(input DraftInput) (*Message, error)
func (*Client) DeleteDraft ¶
func (*Client) DeleteMessage ¶
func (*Client) DeleteMessageResolved ¶
func (*Client) DeleteRule ¶
func (*Client) FlagMessage ¶
func (*Client) GetAccounts ¶
func (*Client) GetAccountsJSON ¶
func (*Client) GetAllMailboxes ¶
func (*Client) GetAttachmentsJSON ¶
func (c *Client) GetAttachmentsJSON(accountName, mailboxName, messageID string) ([]Attachment, error)
func (*Client) GetMailboxesJSON ¶
func (*Client) GetMessageDetailsForVerificationJSON ¶
func (c *Client) GetMessageDetailsForVerificationJSON(accountName, mailboxName, messageID string) (*Message, error)
GetMessageDetailsForVerificationJSON reads a message for a post-mutation verification. Unlike GetMessageDetailsJSON, it deliberately lets failures resolving the account, mailbox, or message properties reach osascript. A nil message is therefore proof that the message is absent, rather than a catch-all result for an automation failure.
func (*Client) GetMessageDetailsJSON ¶
func (*Client) GetMessageStateForVerificationJSON ¶ added in v2.1.3
func (c *Client) GetMessageStateForVerificationJSON(accountName, mailboxName, messageID string) (*Message, error)
GetMessageStateForVerificationJSON performs a bounded ID query through Mail.app. It is the verification fallback when the Envelope Index is not available; it never enumerates all IDs in the mailbox.
func (*Client) GetMessages ¶
func (*Client) GetMessagesFromMultipleMailboxes ¶
func (c *Client) GetMessagesFromMultipleMailboxes(requests []MailboxListRequest) ([]Message, error)
func (*Client) GetMessagesJSON ¶
func (*Client) GetMultipleMessageDetails ¶
func (c *Client) GetMultipleMessageDetails(requests []MessageRef) ([]*Message, error)
func (*Client) GetUnifiedMessagesJSON ¶
func (*Client) GetUnreadCount ¶
func (*Client) HasMessageIdentityInMailbox ¶ added in v2.1.1
func (c *Client) HasMessageIdentityInMailbox(accountName, mailboxName string, identity StableIdentity) (bool, error)
HasMessageIdentityInMailbox finds a logical message after a move may have replaced its local Mail.app ID. The Envelope Index has no RFC header column, so a header-only identity is resolved through Mail.app by the caller; the index path intentionally requires the complete guarded fallback.
func (*Client) ListMessages ¶ added in v2.1.0
func (c *Client) ListMessages(req MailboxListRequest) ([]Message, error)
ListMessages lists one mailbox, newest first, from the Envelope Index when it is readable and from Mail.app otherwise.
func (*Client) ListSignatures ¶
func (*Client) ListSmartMailboxes ¶
func (c *Client) ListSmartMailboxes() ([]SmartMailbox, error)
func (*Client) ListUnified ¶ added in v2.1.0
ListUnified lists an inbox-style view (inbox, unread, flagged, sent, drafts, trash, junk) merged across every enabled account.
func (*Client) LocateMessage ¶
func (c *Client) LocateMessage(id string) (*MessageLocation, error)
LocateMessage resolves one ID. It returns a NotFoundError when the index has no live row for it.
func (*Client) LocateMessages ¶
func (c *Client) LocateMessages(ids []string) (map[string]MessageLocation, error)
LocateMessages resolves message IDs to accounts and mailboxes using the Envelope Index. IDs that are not in the index are absent from the result. The error is non-nil only when the index itself could not be queried.
func (*Client) Mailboxes ¶ added in v2.1.0
Mailboxes lists mailboxes for one account, or every account when account is empty.
func (*Client) MarkMessageAsRead ¶
func (*Client) MessageDetails ¶ added in v2.1.0
MessageDetails fetches one message with its body through Mail.app.
func (*Client) MoveMessage ¶
func (*Client) PrimeAccounts ¶
PrimeAccounts seeds the in-process account cache so callers holding a fresh on-disk copy can avoid a Mail.app round trip.
func (*Client) ReadSelectedMessages ¶ added in v2.2.0
func (c *Client) ReadSelectedMessages(refs []MessageRef, timeout, budget time.Duration) SelectedReadResult
ReadSelectedMessages preserves every successful body even when another ID is missing or stalls. A timed-out read is never retried automatically. The next ID gets a fresh bridge; the overall budget bounds all reads and queueing.
func (*Client) RecordRecentEnvelope ¶
func (*Client) ResetAccountCache ¶ added in v2.1.0
func (c *Client) ResetAccountCache()
ResetAccountCache forgets the in-process account list so the next read asks Mail.app again; an explicit refresh uses it.
func (*Client) RunLiveProbe ¶
RunLiveProbe performs a bounded, read-only query against Mail.app. It is intentionally independent of account enumeration so doctor does not infer live bridge health from a cached or index-backed result.
func (*Client) SaveAttachment ¶
func (*Client) SaveAttachmentByIndex ¶
func (*Client) ScanMessages ¶ added in v2.2.0
func (c *Client) ScanMessages(req ScanRequest) (ScanResult, error)
func (*Client) Search ¶ added in v2.1.0
func (c *Client) Search(query, account string, limit int) (SearchResult, error)
Search runs the standard search within an account (every account when empty). Partial results are returned rather than refused; check Complete.
func (*Client) SearchMessages ¶
func (*Client) SearchMessagesJSON ¶
func (*Client) SearchMessagesJSONSince ¶
func (*Client) SearchMessagesJSONSinceWithOptions ¶
func (c *Client) SearchMessagesJSONSinceWithOptions(query string, accountName string, mailboxName string, limit int, since string, options SearchOptions) (SearchResult, error)
SearchMessagesJSONSinceWithOptions searches the requested mailbox scope and records its completeness. Cross-mailbox searches fail closed unless AllowPartial is set.
func (*Client) SendMessage ¶
func (*Client) SetWarn ¶ added in v2.1.0
SetWarn routes this client's warnings (and those of every WithContext copy) to fn instead of the package default.
func (*Client) SyncAccount ¶
func (*Client) SyncAllAccounts ¶
func (*Client) UpdateDraft ¶
func (c *Client) UpdateDraft(accountName, draftID string, input DraftInput) (*Message, error)
type DraftInput ¶
type DraftInput struct {
Account string `json:"account"`
Subject string `json:"subject"`
Body string `json:"body"`
To []string `json:"to"`
Cc []string `json:"cc,omitempty"`
Bcc []string `json:"bcc,omitempty"`
Attachments []string `json:"attachments,omitempty"`
SubjectSet bool `json:"-"`
BodySet bool `json:"-"`
}
type MailboxListRequest ¶ added in v2.1.0
type MailboxListRequest struct {
AccountName string
MailboxName string
Limit int
Offset int
UnreadOnly bool
FlaggedOnly bool
WithContent bool
Since string
}
MailboxListRequest selects messages from one mailbox for a fan-out read.
type Message ¶
type Message struct {
ID string `json:"id"`
// RFCMessageID is the RFC 5322 Message-ID header when Mail.app exposes it.
// It deliberately differs from the numeric local id above.
RFCMessageID string `json:"rfcMessageId,omitempty"`
Subject string `json:"subject"`
Sender string `json:"sender"`
DateSent string `json:"dateSent"`
DateReceived string `json:"dateReceived"`
Read bool `json:"read"`
Flagged bool `json:"flagged"`
Deleted bool `json:"deleted"`
MessageSize int `json:"messageSize"`
Content string `json:"content"`
ContentError string `json:"contentError,omitempty"`
// Snippet is Mail's indexed summary, present on index-backed listings.
Snippet string `json:"snippet,omitempty"`
Mailbox string `json:"mailbox"`
Account string `json:"account"`
ToRecipients []string `json:"toRecipients"`
CcRecipients []string `json:"ccRecipients"`
BccRecipients []string `json:"bccRecipients"`
}
func FilterBySender ¶ added in v2.1.0
FilterBySender keeps messages whose sender matches an exact address or a domain (including subdomains). Empty filters keep everything.
func MessagesForThread ¶ added in v2.1.0
MessagesForThread picks the loaded messages that belong to the thread.
func SearchRecentMessages ¶
func (Message) MarshalJSON ¶
MarshalJSON keeps recipient lists as arrays so consumers can always iterate them; a nil slice would otherwise serialize as null.
type MessageLocation ¶
type MessageLocation struct {
ID string `json:"id"`
Account string `json:"account"`
Mailbox string `json:"mailbox"`
BackingMailbox string `json:"backingMailbox"`
// ArchiveMailbox is where an archive should act from: INBOX when the
// message carries that label, otherwise the backing mailbox. Archiving
// from a user label would strip the label instead of leaving INBOX.
ArchiveMailbox string `json:"archiveMailbox"`
Labels []string `json:"labels"`
IsGmail bool `json:"-"`
Envelope Message `json:"-"`
}
MessageLocation is where a message can be reached through Mail.app's scripting bridge. Mailbox is the mailbox a mutation should target: for a Gmail account that is the INBOX label when the message carries it, because archiving means moving out of INBOX. BackingMailbox is the row the Envelope Index stores the message under (All Mail for labelled Gmail messages).
type MessageReadResult ¶ added in v2.2.0
type MessageRef ¶ added in v2.1.0
MessageRef names one message by account, mailbox, and ID.
type Mutator ¶ added in v2.1.0
Mutator applies one action to one message and may update the item, for example to record the mailbox an archive landed in.
func ArchiveMutator ¶ added in v2.1.0
ArchiveMutator archives through Mail.app and records the destination.
func FlagMutator ¶ added in v2.1.0
FlagMutator sets flagged status.
func MarkMutator ¶ added in v2.1.0
MarkMutator sets read status.
func MoveMutator ¶ added in v2.1.0
MoveMutator moves a message to item.TargetMailbox.
type NotFoundError ¶
NotFoundError names the kind of object that was missing and the selector that was used, for example ("message", "123") or ("account", "Work").
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
func (*NotFoundError) Unwrap ¶
func (e *NotFoundError) Unwrap() error
type PartialSearchError ¶
type PartialSearchError struct {
Result SearchResult
}
PartialSearchError means one or more mailboxes were unavailable. Its Result is populated so callers that deliberately opted in can inspect the precise scope of the incomplete result.
func (*PartialSearchError) Error ¶
func (e *PartialSearchError) Error() string
type RecentMessage ¶
type RecentMessage struct {
ID string `json:"id"`
Account string `json:"account"`
Mailbox string `json:"mailbox"`
OriginalMailbox string `json:"originalMailbox,omitempty"`
Subject string `json:"subject"`
Sender string `json:"sender"`
DateReceived string `json:"dateReceived"`
DateSent string `json:"dateSent"`
Read bool `json:"read"`
Flagged bool `json:"flagged"`
Deleted bool `json:"deleted,omitempty"`
MessageSize int `json:"messageSize"`
SearchTerms []string `json:"searchTerms,omitempty"`
LastAction string `json:"lastAction"`
LastSeenAt string `json:"lastSeenAt"`
}
func ResolveRecentMessage ¶
func ResolveRecentMessage(selector, accountName, mailboxName string) (*RecentMessage, error)
type RuleInput ¶
type RuleInput struct {
Name string `json:"name"`
Account string `json:"account,omitempty"`
FromDomain string `json:"fromDomain,omitempty"`
MoveTo string `json:"moveTo"`
Enabled bool `json:"enabled"`
SubjectContains []string `json:"subjectContains,omitempty"`
MarkRead bool `json:"markRead,omitempty"`
}
type ScanCoverage ¶ added in v2.2.0
type ScanCoverage struct {
SearchMailbox
Count int `json:"count"`
Truncated bool `json:"truncated"`
Error string `json:"error,omitempty"`
}
type ScanMessage ¶ added in v2.2.0
func (ScanMessage) MarshalJSON ¶ added in v2.2.0
func (m ScanMessage) MarshalJSON() ([]byte, error)
Message has its own marshaler; explicitly merge membership so embedding it does not silently drop the scan-only field.
type ScanRequest ¶ added in v2.2.0
type ScanRequest struct {
Scopes []SearchMailbox
Query string
Since string
Limit int // per mailbox; zero means unlimited
Unread bool
}
ScanRequest names every mailbox explicitly. A scan always reads live state; its observations are sequential, not an atomic snapshot of Mail.app.
type ScanResult ¶ added in v2.2.0
type ScanResult struct {
Messages []ScanMessage `json:"messages"`
Coverage []ScanCoverage `json:"coverage"`
Complete bool `json:"complete"`
StartedAt string `json:"startedAt"`
EndedAt string `json:"endedAt"`
}
type SearchMailbox ¶
SearchMailbox identifies a mailbox included in a search attempt.
type SearchMailboxFailure ¶
type SearchMailboxFailure struct {
Account string `json:"account"`
Mailbox string `json:"mailbox"`
Error string `json:"error"`
}
SearchMailboxFailure records a mailbox that could not be searched. Error is diagnostic metadata rather than a machine-stable error code.
type SearchOptions ¶
type SearchOptions struct {
AllowPartial bool
}
SearchOptions controls the safety contract for searches that span multiple mailboxes. A partial result is unsafe for workflows such as duplicate detection, so callers must explicitly opt in before receiving one.
type SearchResult ¶
type SearchResult struct {
Messages []Message `json:"messages"`
Complete bool `json:"complete"`
SearchedMailboxes []SearchMailbox `json:"searchedMailboxes"`
FailedMailboxes []SearchMailboxFailure `json:"failedMailboxes"`
}
SearchResult is the structured search contract. Complete is false whenever at least one requested mailbox failed to return a result.
type SelectedReadResult ¶ added in v2.2.0
type SelectedReadResult struct {
Items []MessageReadResult `json:"items"`
Complete bool `json:"complete"`
}
type Sender ¶ added in v2.1.0
Sender is a parsed From header.
func ParseSender ¶ added in v2.1.0
ParseSender splits "Name <addr@host>" into its parts, lower-casing the address. Name keeps its case for display.
type SmartMailbox ¶
type StableIdentity ¶ added in v2.1.1
type StableIdentity struct {
RFCMessageID string `json:"rfcMessageId,omitempty"`
Sender string `json:"sender,omitempty"`
Subject string `json:"subject,omitempty"`
DateSent string `json:"dateSent,omitempty"`
MessageSize int `json:"messageSize,omitempty"`
}
StableIdentity identifies a logical message across Mail.app local-ID changes. RFCMessageID is used only when it is an actual RFC header; the fallback is deliberately all-or-nothing to avoid matching a nearby mail.
func StableIdentityFromMessage ¶ added in v2.1.1
func StableIdentityFromMessage(message Message) StableIdentity
type ThreadSummary ¶ added in v2.1.0
type ThreadSummary struct {
ID string `json:"id"`
Subject string `json:"subject"`
Synthetic bool `json:"synthetic"`
Count int `json:"count"`
UnreadCount int `json:"unreadCount"`
LatestDate string `json:"latestDate"`
Participants []string `json:"participants"`
MessageIDs []string `json:"messageIds"`
Messages []Message `json:"messages,omitempty"`
}
ThreadSummary groups messages that share a normalized subject. Synthetic is true for every subject-derived group; only single-message groups are safe to act on as a unit.
func GroupThreads ¶ added in v2.1.0
func GroupThreads(messages []Message) []ThreadSummary
GroupThreads buckets messages by normalized subject, newest thread first.
Source Files
¶
- accounts.go
- attachments.go
- automation.go
- automation_session.go
- batch.go
- batch_journal.go
- bulk.go
- capability.go
- client.go
- drafts.go
- envelope_index.go
- errors.go
- filter.go
- health.go
- list.go
- locate.go
- mailboxes.go
- message_actions.go
- message_content.go
- messages.go
- models.go
- mutation_verification.go
- read_selected.go
- recent.go
- rules.go
- scan.go
- search.go
- send.go
- signatures.go
- smart_mailboxes.go
- sync.go
- threads.go
- unified.go
- warn.go