mail

package
v1.100.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package mail is a client for the Microsoft Graph mail API of Exchange Online mailboxes: messages, their attachments, folders and the mailbox's categories. Every call addresses a mailbox by its user's id -- an object id, or a user principal name -- since an app's own token has no "me".

Every request asks for immutable ids, so that a message keeps its id when it is moved between folders, archiving included.

Index

Constants

View Source
const (
	FolderInbox        = "inbox"
	FolderArchive      = "archive"
	FolderSentItems    = "sentitems"
	FolderDrafts       = "drafts"
	FolderDeletedItems = "deleteditems"
	FolderJunkEmail    = "junkemail"
)

The well-known names of a mailbox's folders, taken wherever a folder id is.

Variables

View Source
var (
	// ErrForeignNextLink is a next link that is not one of the client's Graph for the mailbox asked
	// about. A next link is a whole URL, which the client sends its credential to: one from anywhere
	// else is refused.
	ErrForeignNextLink = errors.New("next link not of this mailbox")
	// ErrSearchWithFilter is a search given a filter or an order as well, which Graph does not take
	// together for messages.
	ErrSearchWithFilter = errors.New("a search takes no filter or order")
)

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(options ...mail_config.Option) *Client
func (c *Client) CheckNextLink(userId string, nextLink string) error

CheckNextLink refuses a next link that is not of the client's Graph, under its version, for the mailbox of userId: Graph writes a mailbox into a link as /users/<id>/ or /users('<id>')/.

func (*Client) GetAttachment

func (c *Client) GetAttachment(
	ctx context.Context,
	userId string,
	messageId string,
	attachmentId string,
	options ...get_attachment_config.Option,
) (*message.Attachment, error)

GetAttachment retrieves the attachment's properties, and a file's content unless Select leaves it out.

func (*Client) GetMailFolder

func (c *Client) GetMailFolder(
	ctx context.Context,
	userId string,
	folderId string,
	options ...fetch_config.Option,
) (*mail_folder.MailFolder, error)

GetMailFolder retrieves the folder folderId, an id or a well-known name.

func (*Client) GetMessage

func (c *Client) GetMessage(
	ctx context.Context,
	userId string,
	messageId string,
	options ...get_message_config.Option,
) (*message.Message, error)

GetMessage retrieves the message identified by messageId.

func (*Client) ListMasterCategories

func (c *Client) ListMasterCategories(
	ctx context.Context,
	userId string,
	options ...fetch_config.Option,
) ([]*outlook_category.Category, error)

ListMasterCategories lists the mailbox's categories: the ones Outlook offers, with their colours. A message may carry others, which Outlook shows uncoloured.

func (*Client) ListMessagesPage

func (c *Client) ListMessagesPage(
	ctx context.Context,
	userId string,
	options ...list_messages_config.Option,
) (*page.Page[*message.Message], error)

ListMessagesPage lists one page of the mailbox's messages, as list_messages_config says. A next link from an earlier page asks for the one after it; Select and the rest are carried in the link.

func (*Client) MoveMessage

func (c *Client) MoveMessage(
	ctx context.Context,
	userId string,
	messageId string,
	destinationId string,
	options ...fetch_config.Option,
) (*message.Message, error)

MoveMessage moves the message into the folder destinationId, an id or a well-known name (FolderArchive archives it), and returns it as it is there. With immutable ids, its id stays.

func (*Client) OpenAttachmentContent

func (c *Client) OpenAttachmentContent(
	ctx context.Context,
	userId string,
	messageId string,
	attachmentId string,
	options ...fetch_config.Option,
) (*attachment_content.Content, error)

OpenAttachmentContent opens the attachment's content, unread: a file's bytes, or an item's MIME. The caller reads the content's body and closes it. A reference attachment has none, and Graph refuses it.

func (*Client) UpdateMessage

func (c *Client) UpdateMessage(
	ctx context.Context,
	userId string,
	messageId string,
	update *message_update.Update,
	options ...fetch_config.Option,
) (*message.Message, error)

UpdateMessage changes what the update names of the message, and returns the message as it is now.

Jump to

Keyboard shortcuts

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