gmail

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExchangeAuthCode

func ExchangeAuthCode(ctx context.Context, config *oauth2.Config, code string) (*oauth2.Token, error)

ExchangeAuthCode exchanges an authorization code for a token

func GetAuthURL

func GetAuthURL(config *oauth2.Config) string

GetAuthURL returns the OAuth authorization URL

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir returns the configuration directory path

func GetCredentialsPath

func GetCredentialsPath() (string, error)

GetCredentialsPath returns the path to credentials.json

func GetOAuthConfig

func GetOAuthConfig() (*oauth2.Config, error)

GetOAuthConfig loads OAuth config from credentials file

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 {
	Service *gmail.Service
	UserID  string
	// 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(messageID string, attachmentID string) ([]byte, error)

DownloadAttachment downloads a single attachment by message ID and attachment ID

func (*Client) DownloadInlineAttachment

func (c *Client) DownloadInlineAttachment(messageID string, partID string) ([]byte, error)

DownloadInlineAttachment downloads an attachment that has inline data

func (*Client) FetchLabels

func (c *Client) FetchLabels() error

FetchLabels retrieves and caches all labels from the Gmail account

func (*Client) GetAttachments

func (c *Client) GetAttachments(messageID string) ([]*Attachment, error)

GetAttachments retrieves attachment metadata for a message

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(messageID string, includeBody bool) (*Message, error)

GetMessage retrieves a single message by ID

func (*Client) GetThread

func (c *Client) GetThread(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) SearchMessages

func (c *Client) SearchMessages(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

Jump to

Keyboard shortcuts

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