msgraph

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package msgraph implements the provider interfaces on Microsoft Graph (Microsoft 365 / Exchange Online) with delegated, device-code auth.

Index

Constants

View Source
const (
	Name          = "msgraph"
	DefaultTenant = "organizations" // work/school accounts only; never "common"

)
View Source
const (
	FlowAuthCode = "auth-code" // authorization code + PKCE (default)
	FlowDevice   = "device"    // device code; blocked by Entra Security Defaults
)

Login flows.

View Source
const DefaultBaseURL = "https://graph.microsoft.com/v1.0"
View Source
const MaxSimpleAttachment = 3 << 20

MaxSimpleAttachment is the largest attachment sent in one POST. Larger files would need an upload session, which is not implemented.

Variables

This section is empty.

Functions

func Scopes

func Scopes(m policy.Mode) []string

Scopes returns the delegated scopes requested at login for a mode.

Types

type Config

type Config struct {
	Alias           string
	Username        string // locked UPN; `api` may also address /users/<this>
	BaseURL         string // default DefaultBaseURL
	HTTP            *http.Client
	Tokens          TokenSource
	UserAgent       string
	FolderCachePath string // "" = in memory only
}

type DeviceCodeInfo

type DeviceCodeInfo struct {
	VerificationURI string `json:"verification_uri"`
	UserCode        string `json:"user_code"`
	ExpiresIn       int    `json:"expires_in"`
	Message         string `json:"message"`
}

DeviceCodeInfo is what the human needs to complete login.

type LoginParams

type LoginParams struct {
	Store     *auth.Store
	Account   *auth.Account // Alias, Mode, TenantID, ClientID set
	HTTP      *http.Client
	BaseURL   string // Graph base, for /me
	UserAgent string

	Flow string // FlowAuthCode (default) or FlowDevice

	// Auth code flow.
	Manual      bool      // print the URL, read the pasted redirect URL from Stdin
	Stdin       io.Reader // for Manual
	OnPrompt    func(oauthflow.Prompt) error
	OpenBrowser func(string) error // loopback only

	// Device code flow: called once the code is available, before blocking.
	OnDeviceCode func(DeviceCodeInfo) error
}

type LoginResult

type LoginResult struct {
	Username      string
	HomeAccountID string
	Granted       []string
	Warnings      []string
}

func Login

func Login(ctx context.Context, p LoginParams) (*LoginResult, error)

Login signs the user in (auth code + PKCE by default, device code on request), then locks the account to the mailbox returned by /me. The previous token cache for the alias is discarded.

type Provider

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

func New

func New(cfg Config) (*Provider, error)

func (*Provider) CreateDraft

func (p *Provider) CreateDraft(ctx context.Context, in provider.DraftInput) (*provider.Message, error)

func (*Provider) CreateForwardDraft

func (p *Provider) CreateForwardDraft(ctx context.Context, in provider.ForwardInput) (*provider.Message, error)

func (*Provider) CreateReplyDraft

func (p *Provider) CreateReplyDraft(ctx context.Context, in provider.ReplyInput) (*provider.Message, error)

CreateReplyDraft uses createReply/createReplyAll so Exchange sets In-Reply-To/References and quotes the original. The agent's text goes in `comment`, which Graph places above the quote; a separate PATCH of the body would replace the quote and could leave an empty draft behind if it failed.

func (*Provider) DeleteDraft

func (p *Provider) DeleteDraft(ctx context.Context, id string) error

func (*Provider) Get

Get fetches one message with its body in the stored content type. HTML is returned as HTML on purpose: the service derives text from it locally so hidden text is stripped (Graph's own text conversion keeps hidden text).

func (*Provider) GetAttachment

func (p *Provider) GetAttachment(ctx context.Context, id, aid string) (*provider.Attachment, error)

func (*Provider) List

List lists a folder newest first. A label that is not a folder is treated as an Outlook category.

Graph rejects $filter + $orderby ("InefficientFilter") unless the $orderby property also leads the $filter, so receivedDateTime always comes first.

func (*Provider) ListAttachments

func (p *Provider) ListAttachments(ctx context.Context, id string) ([]provider.AttachmentMeta, error)

func (*Provider) ListDrafts

func (p *Provider) ListDrafts(ctx context.Context, o provider.ListOptions) (*provider.Page, error)

func (*Provider) Mark

func (*Provider) Move

func (p *Provider) Move(ctx context.Context, id, dest string) (*provider.Message, error)

Move is a real folder move; Graph returns the message with a new id.

func (*Provider) Name

func (p *Provider) Name() string

func (*Provider) Raw

Raw allows only paths under /me or /users/<locked account>; the policy layer has already checked the method against the mode.

func (*Provider) Relabel

func (p *Provider) Relabel(ctx context.Context, id string, add, remove []string) (*provider.Message, error)

Relabel edits Outlook categories. Reserved labels are folders: use move.

func (*Provider) Search

Search uses $search (KQL). Graph forbids combining it with $filter or $orderby; results come back by relevance/date as Graph decides.

func (*Provider) Send

func (p *Provider) Send(ctx context.Context, id string) (*provider.SendResult, error)

Send sends an existing draft. Graph answers 202 with no body and the sent copy gets a new id, so the result carries the draft's internetMessageId (assigned when the draft was created) instead.

func (*Provider) Sync

Sync uses messages/delta on the folder. The first run asks for mail received from now on (so the baseline is cheap) and returns nothing. Delta also reports read/flag changes on older mail; only messages received after the watermark count as new.

func (*Provider) Thread

func (p *Provider) Thread(ctx context.Context, threadID string, limit int) ([]provider.Message, error)

Thread returns a conversation oldest first. Graph rejects $orderby with a conversationId filter, so sorting is local.

func (*Provider) UpdateDraft

func (p *Provider) UpdateDraft(ctx context.Context, id string, u provider.DraftUpdate) (*provider.Message, error)

UpdateDraft PATCHes the given fields. A new body replaces the whole body, including any quoted text from a reply.

type TokenSource

type TokenSource interface {
	Token(ctx context.Context) (string, error)
}

TokenSource returns a valid access token for Graph.

func NewTokenSource

func NewTokenSource(store *auth.Store, acct *auth.Account, h *http.Client) (TokenSource, error)

NewTokenSource returns a TokenSource for a logged-in msgraph account.

func StaticToken

func StaticToken(tok string) TokenSource

StaticToken is a TokenSource for tests.

Jump to

Keyboard shortcuts

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