Documentation
¶
Overview ¶
Package gmail provides a bounded Gmail metadata and label transport.
Index ¶
- Constants
- Variables
- func HasModifyScope(scope string) bool
- func KeychainAvailable() bool
- func StoreCredentials(email string, credentials Credentials) error
- type API
- type AddressStatus
- type AuthStatus
- type Client
- func (c *Client) FindMessages(ctx context.Context, messageID string) ([]string, error)
- func (c *Client) GetMessage(ctx context.Context, id string) (Message, error)
- func (c *Client) ListLabels(ctx context.Context) ([]Label, error)
- func (c *Client) ModifyLabels(ctx context.Context, id string, add, remove []string) error
- func (c *Client) Profile(ctx context.Context) (Profile, error)
- type ClientOption
- type CredentialTokenSource
- type Credentials
- type Header
- type KeychainError
- type Label
- type Message
- type Payload
- type Profile
- type RequestError
- type TokenError
- type TokenSource
- type TokenSourceFunc
Constants ¶
const ModifyScope = "https://www.googleapis.com/auth/gmail.modify"
Variables ¶
var ErrCredentialsInvalid = errors.New("Gmail credentials are invalid")
ErrCredentialsInvalid marks stored or imported credentials that cannot be used. Errors that match it keep their own message text.
var ErrCredentialsNotFound = errors.New("Gmail credentials were not found in macOS Keychain; connect or explicitly import credentials")
var ErrScopeInsufficient = errors.New("Gmail credentials require gmail.modify or full-mail OAuth scope")
ErrScopeInsufficient means the credentials do not grant gmail.modify or full-mail scope.
Functions ¶
func HasModifyScope ¶
func KeychainAvailable ¶
func KeychainAvailable() bool
func StoreCredentials ¶
func StoreCredentials(email string, credentials Credentials) error
Types ¶
type AddressStatus ¶ added in v3.2.2
type AddressStatus struct {
Email string `json:"email"`
Status AuthStatus `json:"status"`
Detail string `json:"detail,omitempty"`
Hint string `json:"hint,omitempty"`
ProviderEmail string `json:"providerEmail,omitempty"`
}
AddressStatus is the result of probing the stored credentials for one address.
func ProbeStoredCredentials ¶ added in v3.2.2
ProbeStoredCredentials loads the Keychain credentials for email, exchanges the refresh token for a new access token and reads the Gmail profile. Rotated credentials are saved as in normal use. It never returns secrets.
type AuthStatus ¶ added in v3.2.2
type AuthStatus string
AuthStatus is the Gmail authorization state of one address.
const ( AuthConnected AuthStatus = "connected" AuthCredentialsMissing AuthStatus = "credentials_missing" AuthKeychainAccess AuthStatus = "keychain_access" AuthCredentialsInvalid AuthStatus = "credentials_invalid" AuthScopeInsufficient AuthStatus = "scope_insufficient" AuthTokenRejected AuthStatus = "token_rejected" AuthClientRejected AuthStatus = "client_rejected" AuthAccessDenied AuthStatus = "access_denied" AuthNetwork AuthStatus = "network" AuthProviderError AuthStatus = "provider_error" AuthAccountMismatch AuthStatus = "account_mismatch" AuthUnknown AuthStatus = "unknown" )
func AuthStatuses ¶ added in v3.2.2
func AuthStatuses() []AuthStatus
AuthStatuses lists every status in documentation order.
func ClassifyAuthError ¶ added in v3.2.2
func ClassifyAuthError(err error) AuthStatus
ClassifyAuthError maps an error from credential loading, token exchange or a Gmail API call to a status. A nil error is connected.
func (AuthStatus) Hint ¶ added in v3.2.2
func (s AuthStatus) Hint() string
Hint returns one recovery step for the status. Connected has none.
func (AuthStatus) StopsSelection ¶ added in v3.2.2
func (s AuthStatus) StopsSelection() bool
StopsSelection reports a failure to read or accept stored credentials. Operational commands fail the whole account on it, even when another address has working credentials.
func (AuthStatus) Stored ¶ added in v3.2.2
func (s AuthStatus) Stored() bool
Stored reports that the address has a credential entry in Keychain, working or not. Operational credential selection counts these addresses: more than one makes the account ambiguous.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(client *http.Client, tokens TokenSource, options ...ClientOption) *Client
func (*Client) FindMessages ¶
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 (*Client) ModifyLabels ¶
ModifyLabels reports HTTP acceptance only. Read metadata to verify final labels.
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) InvalidateAccessToken ¶ added in v3.2.2
func (s *CredentialTokenSource) InvalidateAccessToken()
InvalidateAccessToken drops any cached access token so the next Token call exchanges the refresh token. Pending persistence is kept.
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 KeychainError ¶ added in v3.2.2
KeychainError is a macOS Security framework failure for one Keychain operation.
func (*KeychainError) Error ¶ added in v3.2.2
func (e *KeychainError) Error() string
func (*KeychainError) InteractionRequired ¶ added in v3.2.2
func (e *KeychainError) InteractionRequired() bool
InteractionRequired reports a status that needs a user prompt or an unlocked Keychain.
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.
type RequestError ¶
RequestError never includes response bodies, bearer tokens, or request URLs. Uncertain means a mutation was dispatched and its final outcome needs a read. Transport means no HTTP response was received.
func (*RequestError) Error ¶
func (e *RequestError) Error() string
type TokenError ¶ added in v3.2.2
TokenError is a failed OAuth token exchange. Code is Google's OAuth error code when it is a short lowercase identifier. The response description, body, tokens and client secrets are never kept.
func (*TokenError) Error ¶ added in v3.2.2
func (e *TokenError) Error() string