gmail

package
v1.0.22 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 9 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 Deprecated: Use auth.ExchangeAuthCode() instead

func GetAuthURL

func GetAuthURL(config *oauth2.Config) string

GetAuthURL returns the OAuth authorization URL Deprecated: Use auth.GetAuthURL() instead

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir returns the configuration directory path Deprecated: Use auth.GetConfigDir() instead

func GetCredentialsPath

func GetCredentialsPath() (string, error)

GetCredentialsPath returns the path to credentials.json Deprecated: Use auth.GetCredentialsPath() instead

func GetOAuthConfig

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

GetOAuthConfig loads OAuth config from credentials file Deprecated: Use auth.GetOAuthConfig() instead

func ShortenPath added in v1.0.19

func ShortenPath(path string) string

ShortenPath replaces the home directory prefix with ~ for display purposes. Deprecated: Use auth.ShortenPath() instead

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 GmailClientInterface added in v1.0.19

type GmailClientInterface interface {
	// GetMessage retrieves a single message by ID
	GetMessage(messageID string, includeBody bool) (*Message, error)

	// SearchMessages searches for messages matching the query
	SearchMessages(query string, maxResults int64) ([]*Message, int, error)

	// GetThread retrieves all messages in a thread
	GetThread(id string) ([]*Message, error)

	// FetchLabels retrieves and caches all labels from the Gmail account
	FetchLabels() error

	// GetLabelName resolves a label ID to its display name
	GetLabelName(labelID string) string

	// GetLabels returns all cached labels
	GetLabels() []*gmail.Label

	// GetAttachments retrieves attachment metadata for a message
	GetAttachments(messageID string) ([]*Attachment, error)

	// DownloadAttachment downloads a single attachment by message ID and attachment ID
	DownloadAttachment(messageID string, attachmentID string) ([]byte, error)

	// DownloadInlineAttachment downloads an attachment that has inline data
	DownloadInlineAttachment(messageID string, partID string) ([]byte, error)
}

GmailClientInterface defines the interface for Gmail client operations. This enables unit testing through mock implementations.

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