Documentation
¶
Overview ¶
Package provider defines the unified mail model and the capability interfaces that each backend (msgraph, gmail, imap, fake) implements.
Interfaces are split by capability so that a backend only exposes what it actually supports; `email capabilities` is derived from type assertions.
Index ¶
- Constants
- Variables
- func Capabilities(p Provider) []string
- type Address
- type Attachment
- type AttachmentFile
- type AttachmentMeta
- type AttachmentReader
- type DraftInput
- type DraftUpdate
- type Drafter
- type Flags
- type ForwardInput
- type GetOptions
- type ListOptions
- type MarkOptions
- type Message
- type Mover
- type Page
- type Provider
- type RawAPI
- type RawRequest
- type RawResponse
- type Reader
- type ReplyInput
- type SearchOptions
- type Searcher
- type SendResult
- type Sender
- type SyncOptions
- type SyncResult
- type Syncer
Constants ¶
const ( LabelInbox = "inbox" LabelArchive = "archive" LabelSent = "sent" LabelDrafts = "drafts" LabelTrash = "trash" LabelSpam = "spam" )
Reserved label names. Every provider maps these onto its own folders/labels.
Variables ¶
var ReservedLabels = []string{LabelInbox, LabelArchive, LabelSent, LabelDrafts, LabelTrash, LabelSpam}
Functions ¶
func Capabilities ¶
Capabilities lists the capability names a provider implements.
Types ¶
type Attachment ¶
type Attachment struct {
AttachmentMeta
Data []byte `json:"-"`
}
type AttachmentFile ¶
AttachmentFile is a local file to attach to a draft.
type AttachmentMeta ¶
type AttachmentReader ¶
type AttachmentReader interface {
ListAttachments(ctx context.Context, messageID string) ([]AttachmentMeta, error)
GetAttachment(ctx context.Context, messageID, attachmentID string) (*Attachment, error)
}
type DraftInput ¶
type DraftInput struct {
To, Cc, Bcc []Address
Subject string
Body string
Attachments []AttachmentFile
}
type DraftUpdate ¶
type DraftUpdate struct {
To, Cc, Bcc *[]Address
Subject *string
Body *string
Attachments []AttachmentFile // appended
}
DraftUpdate changes only the non-nil fields.
type Drafter ¶
type Drafter interface {
CreateDraft(ctx context.Context, in DraftInput) (*Message, error)
CreateReplyDraft(ctx context.Context, in ReplyInput) (*Message, error)
CreateForwardDraft(ctx context.Context, in ForwardInput) (*Message, error)
UpdateDraft(ctx context.Context, id string, upd DraftUpdate) (*Message, error)
ListDrafts(ctx context.Context, opts ListOptions) (*Page, error)
DeleteDraft(ctx context.Context, id string) error
}
type ForwardInput ¶
type GetOptions ¶
type ListOptions ¶
type MarkOptions ¶
type Message ¶
type Message struct {
ID string `json:"id"`
ThreadID string `json:"thread_id,omitempty"`
Provider string `json:"provider"`
Account string `json:"account"`
From Address `json:"from"`
To []Address `json:"to,omitempty"`
Cc []Address `json:"cc,omitempty"`
Bcc []Address `json:"bcc,omitempty"`
ReplyTo []Address `json:"reply_to,omitempty"`
Date time.Time `json:"date"`
Subject string `json:"subject"`
Snippet string `json:"snippet,omitempty"`
BodyText string `json:"body_text,omitempty"`
BodyHTML string `json:"body_html,omitempty"`
Attachments []AttachmentMeta `json:"attachments,omitempty"`
Labels []string `json:"labels,omitempty"`
Flags Flags `json:"flags"`
Headers map[string]string `json:"headers,omitempty"`
// WebLink opens the message in the provider's web client (for a draft,
// in the compose/edit view). Empty when the provider has none.
WebLink string `json:"web_link,omitempty"`
// Set by the service layer.
BodyHiddenTextRemoved bool `json:"body_hidden_text_removed,omitempty"`
BodyTruncated bool `json:"body_truncated,omitempty"`
BodyLength int `json:"body_length,omitempty"` // full length in characters, set when truncated
}
Message is the unified message model. IDs are the provider's native IDs, passed through untouched.
Providers fill BodyText and/or BodyHTML with what the server returned; the service layer turns HTML into sanitized text (stripping hidden text) before anything reaches the caller.
type Page ¶
type Page struct {
Messages []Message `json:"messages"`
NextCursor string `json:"next_cursor,omitempty"`
}
func (Page) MarshalJSON ¶
MarshalJSON adds has_more so a caller that asked for N messages and got N can tell whether more exist without inspecting next_cursor.
type Provider ¶
type Provider interface {
Name() string
}
Provider is the minimum every backend implements.
type RawAPI ¶
type RawAPI interface {
Raw(ctx context.Context, req RawRequest) (*RawResponse, error)
}
type RawRequest ¶
type RawResponse ¶
type ReplyInput ¶
type ReplyInput struct {
MessageID string
All bool
Body string
Attachments []AttachmentFile
}
type SearchOptions ¶
type Searcher ¶
type Searcher interface {
Search(ctx context.Context, opts SearchOptions) (*Page, error)
}
type SendResult ¶
type SendResult struct {
MessageID string `json:"message_id,omitempty"`
InternetMessageID string `json:"internet_message_id,omitempty"`
ThreadID string `json:"thread_id,omitempty"`
SentAt time.Time `json:"sent_at"`
}
SendResult describes a sent draft. MessageID is the provider's id of the sent message when the provider returns one (Gmail does; Graph does not, because the sent copy gets a new id). InternetMessageID is the RFC 5322 Message-ID when known.
type Sender ¶
type Sender interface {
Send(ctx context.Context, draftID string) (*SendResult, error)
}
type SyncOptions ¶
type SyncResult ¶
type Syncer ¶
type Syncer interface {
Sync(ctx context.Context, opts SyncOptions) (*SyncResult, error)
}
Directories
¶
| Path | Synopsis |
|---|---|
|
Package fake is an in-memory provider for tests and for trying the CLI without a real mailbox.
|
Package fake is an in-memory provider for tests and for trying the CLI without a real mailbox. |
|
Package gmail implements the provider interfaces on the Gmail REST API (Google Workspace accounts), with OAuth auth code + PKCE login.
|
Package gmail implements the provider interfaces on the Gmail REST API (Google Workspace accounts), with OAuth auth code + PKCE login. |
|
Package imap is the provider for mailboxes reached over IMAP and SMTP with a password: personal Gmail with an app password, or any IMAP server.
|
Package imap is the provider for mailboxes reached over IMAP and SMTP with a password: personal Gmail with an app password, or any IMAP server. |
|
Package msgraph implements the provider interfaces on Microsoft Graph (Microsoft 365 / Exchange Online) with delegated, device-code auth.
|
Package msgraph implements the provider interfaces on Microsoft Graph (Microsoft 365 / Exchange Online) with delegated, device-code auth. |