gmail

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractHTML

func ExtractHTML(msg *gmail.Message) string

ExtractHTML extracts HTML content from a Gmail message

func ExtractPlainText

func ExtractPlainText(msg *gmail.Message) string

ExtractPlainText extracts plain text content from a Gmail message

Types

type Client

type Client struct {
	Service *gmail.Service
	// contains filtered or unexported fields
}

Client wraps the gmail.Service and provides convenience methods

func NewClient

func NewClient(service *gmail.Service) *Client

NewClient creates a new Gmail client

func (*Client) ActiveAccountEmail

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

ActiveAccountEmail returns the authenticated user's email address. Uses Gmail Users.GetProfile("me"). The value is cached for subsequent calls.

func (*Client) ApplyLabel

func (c *Client) ApplyLabel(messageID, labelID string) error

ApplyLabel applies a label to a message

func (*Client) ArchiveMessage

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

ArchiveMessage archives a message

func (*Client) CreateDraft

func (c *Client) CreateDraft(to, subject, body string, cc []string) (string, error)

CreateDraft creates a new draft message

func (*Client) CreateLabel

func (c *Client) CreateLabel(name string) (*gmail.Label, error)

CreateLabel creates a new label

func (*Client) CreateMessageFromRaw added in v1.0.1

func (c *Client) CreateMessageFromRaw(rawMsg *gmail.Message) *Message

CreateMessageFromRaw creates a gmail.Message wrapper from a raw gmail API message This is used to convert preloader cached messages to the expected format without additional API calls

func (*Client) DeleteDraft

func (c *Client) DeleteDraft(draftID string) error

DeleteDraft deletes a draft message

func (*Client) DeleteLabel

func (c *Client) DeleteLabel(labelID string) error

DeleteLabel removes a label permanently

func (*Client) ExtractDate

func (c *Client) ExtractDate(msg *gmail.Message) time.Time

ExtractDate extracts the date from a message

func (*Client) ExtractHeader

func (c *Client) ExtractHeader(msg *gmail.Message, name string) string

ExtractHeader extracts a header value from a message

func (*Client) ExtractLabels

func (c *Client) ExtractLabels(msg *gmail.Message) []string

ExtractLabels extracts labels from a message

func (*Client) GetAttachment

func (c *Client) GetAttachment(messageID, attachmentID string) ([]byte, string, error)

GetAttachment downloads an attachment

func (*Client) GetDraft

func (c *Client) GetDraft(draftID string) (*gmail.Draft, error)

GetDraft returns a specific draft by ID with full content

func (*Client) GetMessage

func (c *Client) GetMessage(id string) (*gmail.Message, error)

GetMessage retrieves a specific message by ID

func (*Client) GetMessageMetadata added in v1.0.1

func (c *Client) GetMessageMetadata(id string) (*gmail.Message, error)

GetMessageMetadata retrieves only message metadata (headers, labels) for efficient list display This is significantly faster and uses less bandwidth than GetMessage() for list operations

func (*Client) GetMessageWithContent

func (c *Client) GetMessageWithContent(id string) (*Message, error)

GetMessageWithContent retrieves a message and extracts its content

func (*Client) GetMessagesMetadataParallel added in v1.0.1

func (c *Client) GetMessagesMetadataParallel(messageIDs []string, maxWorkers int) ([]*gmail.Message, error)

GetMessagesMetadataParallel fetches multiple message metadata concurrently for efficient list display Uses format=metadata to reduce bandwidth and improve performance compared to GetMessagesParallel Returns results in the same order as input IDs, with nil for failed fetches

func (*Client) GetMessagesParallel added in v1.0.1

func (c *Client) GetMessagesParallel(messageIDs []string, maxWorkers int) ([]*gmail.Message, error)

GetMessagesParallel fetches multiple messages concurrently using a worker pool Returns results in the same order as input IDs, with nil for failed fetches

func (*Client) ListDrafts

func (c *Client) ListDrafts(maxResults int64) ([]*gmail.Draft, error)

ListDrafts returns draft messages with full message content

func (*Client) ListLabels

func (c *Client) ListLabels() ([]*gmail.Label, error)

ListLabels returns all labels

func (*Client) ListMessages

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

ListMessages returns first page of inbox messages (backward-compatible)

func (*Client) ListMessagesPage

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

ListMessagesPage returns a page of inbox messages and the nextPageToken

func (*Client) MarkAsRead

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

MarkAsRead marks a message as read

func (*Client) MarkAsUnread

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

MarkAsUnread marks a message as unread

func (*Client) RemoveLabel

func (c *Client) RemoveLabel(messageID, labelID string) error

RemoveLabel removes a label from a message

func (*Client) RenameLabel

func (c *Client) RenameLabel(labelID, newName string) (*gmail.Label, error)

RenameLabel updates the name of an existing label

func (*Client) ReplyMessage

func (c *Client) ReplyMessage(originalMsgID, replyBody string, send bool, cc []string) (string, error)

ReplyMessage creates a reply to an existing message

func (*Client) SearchMessages

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

SearchMessages searches for messages using Gmail query syntax

func (*Client) SearchMessagesPage

func (c *Client) SearchMessagesPage(query string, maxResults int64, pageToken string) ([]*gmail.Message, string, error)

SearchMessagesPage searches with Gmail query and supports pagination

func (*Client) SendMessage

func (c *Client) SendMessage(from, to, subject, body string, cc, bcc []string) (string, error)

SendMessage sends a message

func (*Client) SendRawMIME

func (c *Client) SendRawMIME(raw string) (string, error)

SendRawMIME sends a fully-formed MIME message (raw content). Caller is responsible for providing correct headers, MIME-Version, boundaries, and payloads. The raw string will be base64url encoded as required by Gmail API.

func (*Client) TrashMessage

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

TrashMessage moves a message to trash

func (*Client) UpdateDraft

func (c *Client) UpdateDraft(draftID, to, subject, body string, cc []string) error

UpdateDraft updates an existing draft message

type Message

type Message struct {
	*gmail.Message
	PlainText string
	HTML      string
	Subject   string
	From      string
	To        string
	Cc        string
	Date      time.Time
	Labels    []string
}

Message represents a Gmail message with extracted content

type MessageResult added in v1.0.1

type MessageResult struct {
	Message *gmail.Message
	Index   int // Original index in the input slice
	Error   error
}

MessageResult represents the result of fetching a message