gmailapi

package
v1.38.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 24 Imported by: 1 module, 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 gmailapi is the Gmail REST API v1 protocol backend (ADR 0037): a backend.Receiver and backend.Sender over https://gmail.googleapis.com.

Index

Constants

View Source
const (
	ReasonAPIDisabled       = "gmailapi.api_disabled"
	ReasonNoCopy            = "gmailapi.no_copy"
	ReasonNoAnswered        = "gmailapi.no_answered"
	ReasonNoDraft           = "gmailapi.no_draft"
	ReasonNoKeywords        = "gmailapi.no_keywords"
	ReasonNoPush            = "gmailapi.no_push"
	ReasonFoldersPending    = "gmailapi.folders_pending"
	ReasonSystemLabelsFixed = "gmailapi.system_labels_fixed"
)

Reason keys, translated by the UI and Wit.

View Source
const AllMailRef backend.FolderRef = "[Gmail]/All Mail"

AllMailRef is the synthetic All Mail folder: Gmail's labels.list has no All Mail entry, while messages.list (without spam/trash) is All Mail. Keeping it as RoleAll aligns archiving, sidebar 归档 and multi-location behavior with Gmail IMAP (backend/imapbackend).

View Source
const DefaultBaseURL = "https://gmail.googleapis.com"

DefaultBaseURL is Google's Gmail REST API host.

Variables

View Source
var ErrAPIDisabled = errors.New(ReasonAPIDisabled)

ErrAPIDisabled means the OAuth client's Google Cloud project has not enabled gmail.googleapis.com (HTTP 403 accessNotConfigured). Its message is ReasonAPIDisabled.

Functions

This section is empty.

Types

type Config

type Config struct {
	// BaseURL is the API origin, "" for DefaultBaseURL; tests point it at httptest.
	BaseURL     string
	Credentials backend.CredentialsFunc
	// Wait waits d out, or until ctx is done, when the server asks to back off.
	// Nil waits in real time; tests pass a fake.
	Wait func(ctx context.Context, d time.Duration) error
}

Config is how to reach a Gmail account over the REST API.

type Receiver

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

Receiver is a Gmail account's receiving backend over the Gmail REST API v1.

func New

func New(cfg Config) *Receiver

New returns a Receiver for the Gmail account cfg reaches.

func (*Receiver) Apply

func (r *Receiver) Apply(ctx context.Context, op backend.Op) (backend.Result, error)

Apply implements backend.Receiver.

func (*Receiver) Check

func (r *Receiver) Check(ctx context.Context) (backend.CheckResult, error)

Check implements backend.Receiver.

func (*Receiver) Close

func (r *Receiver) Close() error

Close implements backend.Receiver.

func (*Receiver) Describe

func (r *Receiver) Describe(ctx context.Context) (backend.Description, error)

Describe implements backend.Receiver. Its first call signs in so refused credentials return ErrAuthFailed and a disabled API returns ErrAPIDisabled.

func (*Receiver) Fetch

Fetch implements backend.Receiver.

func (*Receiver) Find

func (r *Receiver) Find(ctx context.Context, folder backend.FolderRef, messageID string, size int64) ([]backend.MessageRef, error)

Find implements backend.Receiver.

func (*Receiver) Headers

func (r *Receiver) Headers(ctx context.Context, folder backend.FolderRef, refs []backend.MessageRef, fields []string) (map[backend.MessageRef][]byte, error)

Headers implements backend.Receiver.

func (*Receiver) Sync

func (r *Receiver) Sync(ctx context.Context, req backend.SyncRequest, commit func(backend.Page) error) (bool, error)

Sync implements backend.Receiver.

func (*Receiver) Watch

func (r *Receiver) Watch(context.Context, func([]backend.FolderRef)) error

Watch implements backend.Receiver: Gmail API push requires Cloud Pub/Sub, which a desktop client cannot use, so core polls at PollInterval (1m).

type Sender

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

Sender submits mail through Gmail REST API users.messages.send. Gmail automatically stores the sent copy with the SENT label (SavesSent == true).

func NewSender

func NewSender(cfg Config) *Sender

NewSender returns a Sender for the Gmail account cfg reaches.

func (*Sender) SavesSent

func (*Sender) SavesSent() bool

SavesSent implements backend.Sender.

func (*Sender) Send

func (s *Sender) Send(ctx context.Context, _ string, rcpts []string, raw []byte) error

Send implements backend.Sender. Gmail extracts recipients from the MIME headers, so rcpts absent from To and Cc are prepended as Bcc (Gmail strips Bcc before delivering to other recipients).

Directories

Path Synopsis
Package gmailapitest is an in-process fake Gmail REST API v1 server for backend contract tests and coretest end-to-end tests, with zero external network dependency.
Package gmailapitest is an in-process fake Gmail REST API v1 server for backend contract tests and coretest end-to-end tests, with zero external network dependency.

Jump to

Keyboard shortcuts

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