gmail

package
v3.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 18 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 gmail provides a bounded Gmail metadata and label transport.

Index

Constants

View Source
const ModifyScope = "https://www.googleapis.com/auth/gmail.modify"

Variables

View Source
var ErrCredentialsNotFound = errors.New("Gmail credentials were not found in macOS Keychain; connect or explicitly import credentials")
View Source
var ErrKeychainUnavailable = errors.New("Gmail credential storage requires macOS with cgo and the Security framework")

Functions

func HasModifyScope

func HasModifyScope(scope string) bool

func KeychainAvailable

func KeychainAvailable() bool

func StoreCredentials

func StoreCredentials(email string, credentials Credentials) error

Types

type API

type API interface {
	Profile(context.Context) (Profile, error)
	ListLabels(context.Context) ([]Label, error)
	FindMessages(context.Context, string) ([]string, error)
	GetMessage(context.Context, string) (Message, error)
	ModifyLabels(context.Context, string, []string, []string) error
}

type Client

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

func NewClient

func NewClient(client *http.Client, tokens TokenSource, options ...ClientOption) *Client

func NewStoredClient

func NewStoredClient(email string, client *http.Client) (*Client, error)

func (*Client) FindMessages

func (c *Client) FindMessages(ctx context.Context, messageID string) ([]string, error)

FindMessages retrieves every page or returns no candidates and an error. A result is only a candidate: callers must verify the Message-ID header.

func (*Client) GetMessage

func (c *Client) GetMessage(ctx context.Context, id string) (Message, error)

func (*Client) ListLabels

func (c *Client) ListLabels(ctx context.Context) ([]Label, error)

func (*Client) ModifyLabels

func (c *Client) ModifyLabels(ctx context.Context, id string, add, remove []string) error

ModifyLabels reports HTTP acceptance only. Read metadata to verify final labels.

func (*Client) Profile

func (c *Client) Profile(ctx context.Context) (Profile, error)

type ClientOption

type ClientOption func(*Client)

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

type CredentialTokenSource

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

func NewCredentialTokenSource

func NewCredentialTokenSource(credentials Credentials, client *http.Client) *CredentialTokenSource

func (*CredentialTokenSource) Token

type Credentials

type Credentials struct {
	ClientID     string    `json:"client_id"`
	ClientSecret string    `json:"client_secret,omitempty"`
	RefreshToken string    `json:"refresh_token"`
	AccessToken  string    `json:"access_token,omitempty"`
	Expiry       time.Time `json:"expiry,omitempty"`
	Scope        string    `json:"scope"`
}

Credentials is the explicit JSON import format. Expiry is RFC3339. Secret fields are persisted only in macOS Keychain, never a plaintext cache.

func LoadCredentials

func LoadCredentials(email string) (Credentials, error)

func (Credentials) GoString

func (c Credentials) GoString() string

func (Credentials) String

func (c Credentials) String() string
type Header struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type Label

type Label struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Type string `json:"type"`
}

type Message

type Message struct {
	ID           string   `json:"id"`
	ThreadID     string   `json:"threadId"`
	LabelIDs     []string `json:"labelIds"`
	Payload      Payload  `json:"payload"`
	SizeEstimate int64    `json:"sizeEstimate"`
}

type Payload

type Payload struct {
	Headers []Header `json:"headers"`
}

type Profile

type Profile struct {
	EmailAddress string `json:"emailAddress"`
}

func Connect

func Connect(ctx context.Context, clientJSONPath, expectedEmail string, openURL func(string) error, client *http.Client) (Profile, error)

Connect runs installed-client OAuth using a loopback listener, state and PKCE. openURL is supplied by the CLI and receives the consent URL, without secrets.

func ImportCredentials

func ImportCredentials(ctx context.Context, path, expectedEmail string, client *http.Client) (Profile, error)

type RequestError

type RequestError struct {
	Operation  string
	StatusCode int
	Uncertain  bool
}

RequestError never includes response bodies, bearer tokens, or request URLs. Uncertain means a mutation was dispatched and its final outcome needs a read.

func (*RequestError) Error

func (e *RequestError) Error() string

type TokenSource

type TokenSource interface {
	Token(context.Context) (string, error)
}

type TokenSourceFunc

type TokenSourceFunc func(context.Context) (string, error)

func (TokenSourceFunc) Token

func (f TokenSourceFunc) Token(ctx context.Context) (string, error)

Jump to

Keyboard shortcuts

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