provider

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

Functions

func Capabilities

func Capabilities(p Provider) []string

Capabilities lists the capability names a provider implements.

Types

type Address

type Address struct {
	Name  string `json:"name,omitempty"`
	Email string `json:"email"`
}

func (Address) Domain

func (a Address) Domain() string

Domain returns the lower-cased domain part of the address.

func (Address) String

func (a Address) String() string

type Attachment

type Attachment struct {
	AttachmentMeta
	Data []byte `json:"-"`
}

type AttachmentFile

type AttachmentFile struct {
	Name string
	MIME string
	Data []byte
}

AttachmentFile is a local file to attach to a draft.

type AttachmentMeta

type AttachmentMeta struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Size   int64  `json:"size"`
	MIME   string `json:"mime,omitempty"`
	Inline bool   `json:"inline"`
}

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 Flags

type Flags struct {
	Unread         bool `json:"unread"`
	Draft          bool `json:"draft"`
	Flagged        bool `json:"flagged"`
	HasAttachments bool `json:"has_attachments"`
}

type ForwardInput

type ForwardInput struct {
	MessageID string
	To        []Address
	Body      string
}

type GetOptions

type GetOptions struct {
	IncludeHTML bool
	Headers     bool
}

type ListOptions

type ListOptions struct {
	Label  string
	Unread bool
	Since  time.Time
	Limit  int
	Cursor string
}

type MarkOptions

type MarkOptions struct {
	Read    *bool
	Flagged *bool
}

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 Mover

type Mover interface {
	Move(ctx context.Context, id, dest string) (*Message, error)
	Relabel(ctx context.Context, id string, add, remove []string) (*Message, error)
	Mark(ctx context.Context, id string, opts MarkOptions) (*Message, error)
}

type Page

type Page struct {
	Messages   []Message `json:"messages"`
	NextCursor string    `json:"next_cursor,omitempty"`
}

func (Page) MarshalJSON

func (p Page) MarshalJSON() ([]byte, error)

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 RawRequest struct {
	Method string
	Path   string
	Body   []byte
}

type RawResponse

type RawResponse struct {
	Status int
	Body   []byte
}

type Reader

type Reader interface {
	List(ctx context.Context, opts ListOptions) (*Page, error)
	Get(ctx context.Context, id string, opts GetOptions) (*Message, error)
	Thread(ctx context.Context, threadID string, limit int) ([]Message, error)
}

type ReplyInput

type ReplyInput struct {
	MessageID   string
	All         bool
	Body        string
	Attachments []AttachmentFile
}

type SearchOptions

type SearchOptions struct {
	Query  string // provider-native: KQL for Graph $search, q= for Gmail
	Limit  int
	Cursor string
}

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 SyncOptions struct {
	Label string
	State string // opaque cursor from the previous run; "" on first run
}

type SyncResult

type SyncResult struct {
	Messages []Message
	State    string
	// Initialized is true when State was empty and the provider only
	// established a baseline without returning existing mail.
	Initialized bool
}

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.

Jump to

Keyboard shortcuts

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