gmail

package
v1.0.35 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package gmail provides a client for the Gmail API.

Index

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 NewClient

func NewClient(ctx context.Context) (*Client, error)

NewClient creates a new Gmail client with OAuth2 authentication

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

func (c *Client) FetchLabels(ctx context.Context) error

FetchLabels retrieves and caches all labels from the Gmail account

func (*Client) GetAttachments

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

GetAttachments retrieves attachment metadata for a message

func (*Client) GetLabelID added in v1.0.35

func (c *Client) GetLabelID(ctx context.Context, name string) (string, error)

GetLabelID resolves a label display name to its ID. Calls FetchLabels if needed.

func (*Client) GetLabelName

func (c *Client) GetLabelName(labelID string) string

GetLabelName resolves a label ID to its display name

func (*Client) GetLabels

func (c *Client) GetLabels() []*gmail.Label

GetLabels returns all cached labels

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

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

GetProfile retrieves the authenticated user's profile

func (*Client) GetThread

func (c *Client) GetThread(ctx context.Context, id string) ([]*Message, error)

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.

func (*Client) SearchMessages

func (c *Client) SearchMessages(ctx context.Context, query string, maxResults int64) ([]*Message, int, error)

SearchMessages searches for messages matching the query. Returns messages, the count of messages that failed to fetch, and any error.

type LabelResolver

type LabelResolver func(labelID string) string

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"`
	Attachments []*Attachment `json:"attachments,omitempty"`
	Labels      []string      `json:"labels,omitempty"`
	Categories  []string      `json:"categories,omitempty"`
}

Message represents a simplified email message

type Profile added in v1.0.30

type Profile struct {
	EmailAddress  string
	MessagesTotal int64
	ThreadsTotal  int64
}

Profile represents a Gmail user profile.

Jump to

Keyboard shortcuts

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