Documentation
¶
Overview ¶
Package gmail provides a client for the Gmail API.
Index ¶
- type Attachment
- type Client
- func (c *Client) CreateDraft(ctx context.Context, msg DraftMessage) (*DraftResult, error)
- func (c *Client) DownloadAttachment(ctx context.Context, messageID string, attachmentID string) ([]byte, error)
- func (c *Client) DownloadInlineAttachment(ctx context.Context, messageID string, partID string) ([]byte, error)
- func (c *Client) FetchLabels(ctx context.Context) error
- func (c *Client) GetAttachments(ctx context.Context, messageID string) ([]*Attachment, error)
- func (c *Client) GetLabelID(ctx context.Context, name string) (string, error)
- func (c *Client) GetLabelName(labelID string) string
- func (c *Client) GetLabels() []*gmail.Label
- func (c *Client) GetMessage(ctx context.Context, messageID string, includeBody bool) (*Message, error)
- func (c *Client) GetProfile(ctx context.Context) (*Profile, error)
- func (c *Client) GetThread(ctx context.Context, id string) ([]*Message, error)
- func (c *Client) ModifyMessages(ctx context.Context, ids []string, addLabels, removeLabels []string) error
- func (c *Client) SearchMessageIDs(ctx context.Context, query string, maxResults int64) ([]string, error)
- func (c *Client) SearchMessages(ctx context.Context, query string, maxResults int64) ([]*Message, int, error)
- type DraftAttachment
- type DraftBodyKind
- type DraftMessage
- type DraftResult
- type LabelResolver
- type Message
- type Profile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
type Attachment struct {
Filename string `json:"filename"`
MimeType string `json:"mimeType"`
Size int64 `json:"size"`
AttachmentID string `json:"attachmentId,omitempty"`
PartID string `json:"partId"`
IsInline bool `json:"isInline"`
}
Attachment represents metadata about an email attachment
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the Gmail API service
func (*Client) CreateDraft ¶ added in v1.0.41
func (c *Client) CreateDraft(ctx context.Context, msg DraftMessage) (*DraftResult, error)
CreateDraft assembles a MIME message and POSTs to users.drafts.create. The CLI never calls drafts.send — drafts sit in the user's Drafts folder for explicit human review.
func (*Client) DownloadAttachment ¶
func (c *Client) DownloadAttachment(ctx context.Context, messageID string, attachmentID string) ([]byte, error)
DownloadAttachment downloads a single attachment by message ID and attachment ID
func (*Client) DownloadInlineAttachment ¶
func (c *Client) DownloadInlineAttachment(ctx context.Context, messageID string, partID string) ([]byte, error)
DownloadInlineAttachment downloads an attachment that has inline data
func (*Client) FetchLabels ¶
FetchLabels retrieves and caches all labels from the Gmail account
func (*Client) GetAttachments ¶
GetAttachments retrieves attachment metadata for a message
func (*Client) GetLabelID ¶ added in v1.0.35
GetLabelID resolves a label display name to its ID. Calls FetchLabels if needed.
func (*Client) GetLabelName ¶
GetLabelName resolves a label ID to its display name
func (*Client) GetMessage ¶
func (c *Client) GetMessage(ctx context.Context, messageID string, includeBody bool) (*Message, error)
GetMessage retrieves a single message by ID
func (*Client) GetProfile ¶ added in v1.0.30
GetProfile retrieves the authenticated user's profile
func (*Client) GetThread ¶
GetThread retrieves all messages in a thread. The id parameter can be either a thread ID or a message ID. If a message ID is provided, the thread ID is resolved automatically.
func (*Client) ModifyMessages ¶ added in v1.0.35
func (c *Client) ModifyMessages(ctx context.Context, ids []string, addLabels, removeLabels []string) error
ModifyMessages modifies labels on one or more messages. Uses Messages.Modify for a single message; Messages.BatchModify for multiple. Gmail limits batch operations to 1000 IDs, so this method chunks automatically.
func (*Client) SearchMessageIDs ¶ added in v1.0.35
func (c *Client) SearchMessageIDs(ctx context.Context, query string, maxResults int64) ([]string, error)
SearchMessageIDs returns only message IDs matching the query (no metadata fetch). This is more efficient than SearchMessages when only IDs are needed. Note: returns a single page of results (up to ~100 when maxResults is 0). This matches SearchMessages behavior. For very large result sets, use a more specific query to narrow results.
type DraftAttachment ¶ added in v1.0.41
DraftAttachment is one attachment. Filename should be a basename; the gmail package re-applies filepath.Base defensively.
type DraftBodyKind ¶ added in v1.0.41
type DraftBodyKind int
DraftBodyKind selects the Content-Type for the body part.
const ( // DraftBodyPlainText sends the body as text/plain; charset=UTF-8. // This is the zero value: a DraftMessage{} with an unset BodyKind // defaults to plain text, which is the safer interpretation when // callers construct DraftMessage directly without going through the CLI. DraftBodyPlainText DraftBodyKind = iota // DraftBodyHTML sends the body as text/html; charset=UTF-8. DraftBodyHTML )
type DraftMessage ¶ added in v1.0.41
type DraftMessage struct {
From string // optional; send-as alias
To []string // required; ≥1
Cc []string
Bcc []string
Subject string
Body []byte
BodyKind DraftBodyKind
Attachments []DraftAttachment
// ThreadID, when non-empty, threads the draft into an existing Gmail
// conversation via Draft.Message.ThreadId. Empty = new thread.
ThreadID string
// InReplyTo, when non-empty, is emitted as the RFC 5322 In-Reply-To
// header (typically the source message's Message-Id, brackets included).
InReplyTo string
// References, when non-empty, is emitted as the RFC 5322 References
// header (space-joined Message-Ids per §3.6.4).
References []string
}
DraftMessage describes a draft to be created. The command layer constructs this and hands it to (*Client).CreateDraft. The gmail package owns MIME assembly and the raw API call.
type DraftResult ¶ added in v1.0.41
type DraftResult struct {
ID string `json:"id"`
MessageID string `json:"messageId"`
ThreadID string `json:"threadId,omitempty"`
}
DraftResult is the response after creating a draft.
type LabelResolver ¶
LabelResolver is a function that resolves a label ID to its display name
type Message ¶
type Message struct {
ID string `json:"id"`
ThreadID string `json:"threadId"`
Subject string `json:"subject"`
From string `json:"from"`
To string `json:"to"`
Date string `json:"date"`
Snippet string `json:"snippet"`
Body string `json:"body,omitempty"`
// BodyIsHTML reports that Body came from the message's text/html part
// (no text/plain alternative). Internal routing bit for reply quoting;
// intentionally excluded from the public --json output surface.
BodyIsHTML bool `json:"-"`
Attachments []*Attachment `json:"attachments,omitempty"`
Labels []string `json:"labels,omitempty"`
Categories []string `json:"categories,omitempty"`
// Cc carries the raw "Cc" header value (comma-separated address list).
Cc string `json:"cc,omitempty"`
// RFCMessageID is the RFC 5322 Message-Id header, distinct from ID
// (Gmail's internal message id). Used by reply derivation to populate
// In-Reply-To and References on outgoing drafts.
RFCMessageID string `json:"rfcMessageId,omitempty"`
// References is the raw "References" header value (whitespace-separated
// chain of Message-Ids).
References string `json:"references,omitempty"`
// InReplyTo is the raw "In-Reply-To" header value.
InReplyTo string `json:"inReplyTo,omitempty"`
}
Message represents a simplified email message