gmail

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildGmailLink(messageID string) string

BuildGmailLink generates a stable Gmail permalink from a message ID The link uses #all/ to work regardless of which label/folder the email is in Example: BuildGmailLink("abc123") -> "https://mail.google.com/mail/u/0/#all/abc123"

func GetFromAddress

func GetFromAddress(from string) string

GetFromAddress extracts just the email address from a "From" header Example: "John Doe <[email protected]>" -> "[email protected]"

func GetFromDomain

func GetFromDomain(email string) string

GetFromDomain extracts the domain from an email address Example: "[email protected]" -> "example.com"

func GetTokenFromWeb

func GetTokenFromWeb(config *oauth2.Config) (*oauth2.Token, error)

GetTokenFromWeb starts the OAuth flow and returns a token

func LoadCredentials

func LoadCredentials(credPath string) (*oauth2.Config, error)

LoadCredentials reads the OAuth credentials from credentials.json

func LoadToken

func LoadToken() (*oauth2.Token, error)

LoadToken loads a previously saved token

func SaveToken

func SaveToken(token *oauth2.Token) error

SaveToken saves the OAuth token to the config directory

func TokenExists

func TokenExists() bool

TokenExists checks if a valid token file exists

Types

type Client

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

Client wraps the Gmail API service with auto-refreshing tokens

func NewClient

func NewClient(token *oauth2.Token, oauthConfig *oauth2.Config) (*Client, error)

NewClient creates a new Gmail API client using the provided OAuth token The client automatically refreshes expired tokens and saves them to disk

func (*Client) GetMessagesAfter

func (c *Client) GetMessagesAfter(afterMessageID string, maxResults int64) ([]*gmail.Message, error)

GetMessagesAfter fetches messages received after a specific message ID

func (*Client) GetRecentMessages

func (c *Client) GetRecentMessages(maxResults int64) ([]*gmail.Message, error)

GetRecentMessages fetches recent messages from the inbox with retry logic maxResults specifies the maximum number of messages to retrieve Defaults to searching only the inbox (in:inbox)

func (*Client) GetRecentMessagesWithQuery

func (c *Client) GetRecentMessagesWithQuery(maxResults int64, searchQuery string) ([]*gmail.Message, error)

GetRecentMessagesWithQuery fetches recent messages with a custom Gmail search query maxResults specifies the maximum number of messages to retrieve searchQuery uses Gmail search syntax (e.g., "in:inbox", "-in:trash", "", etc.)

func (*Client) MarkAsRead

func (c *Client) MarkAsRead(messageID string) error

MarkAsRead marks a message as read

func (*Client) RefreshTokenIfNeeded

func (c *Client) RefreshTokenIfNeeded() error

RefreshTokenIfNeeded manually refreshes the token if it's expired or about to expire

type EmailMessage

type EmailMessage struct {
	ID      string
	From    string
	Subject string
	Snippet string
	Date    string
}

EmailMessage represents a parsed email message

func ParseMessage

func ParseMessage(msg *gmail.Message) *EmailMessage

ParseMessage extracts relevant fields from a Gmail API message

Jump to

Keyboard shortcuts

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