ews

package
v0.0.0-...-644995d Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlagStatusNotFlagged = "NotFlagged"
	FlagStatusFlagged    = "Flagged"
	FlagStatusComplete   = "Complete"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	ID          string
	Name        string
	ContentType string
	Size        int64
	IsInline    bool
}

type AttachmentContent

type AttachmentContent struct {
	ID          string
	Name        string
	ContentType string
	Size        int64
	IsInline    bool
	Content     []byte
}

type AttachmentFile

type AttachmentFile struct {
	Name        string
	ContentType string
	Content     []byte // AttachmentFile describes a single file to attach via CreateAttachment.

	IsInline bool
}

type BackoffError

type BackoffError struct {
	Operation    string
	ResponseCode string
	Message      string
	Backoff      time.Duration
}

func (*BackoffError) Error

func (e *BackoffError) Error() string

type CalendarItem

type CalendarItem struct {
	ID                string
	ChangeKey         string
	ParentFolderID    string
	Subject           string
	Body              string
	BodyType          string
	Location          string
	Start             time.Time
	End               time.Time
	IsAllDay          bool
	UID               string
	Organizer         string
	RequiredAttendees []EventAttendee
	OptionalAttendees []EventAttendee
	Recurrence        string
	Status            string
}

type CalendarItemInput

type CalendarItemInput struct {
	Subject           string
	Body              string
	BodyType          string
	Location          string
	Start             time.Time
	End               time.Time
	IsAllDay          bool
	UID               string
	OrganizerEmail    string
	OrganizerName     string
	RequiredAttendees []EventAttendee
	OptionalAttendees []EventAttendee
	Recurrence        string
	SendInvitations   string
}

type CalendarItemUpdate

type CalendarItemUpdate struct {
	Subject           *string
	Body              *string
	BodyType          *string
	Location          *string
	Start             *time.Time
	End               *time.Time
	IsAllDay          *bool
	OrganizerEmail    *string
	RequiredAttendees *[]EventAttendee
	OptionalAttendees *[]EventAttendee
	Recurrence        *string
	SendCancellations string
}

type Client

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

func NewClient

func NewClient(cfg Config) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) CreateAttachment

func (c *Client) CreateAttachment(ctx context.Context, parentID, parentChangeKey string, file AttachmentFile) (string, error)

func (*Client) CreateCalendarItem

func (c *Client) CreateCalendarItem(ctx context.Context, parentFolderID string, item CalendarItemInput, sendInvitations string) (string, string, error)

func (*Client) CreateContactItem

func (c *Client) CreateContactItem(ctx context.Context, parentFolderID string, contact ContactItem) (string, string, error)

CreateContactItem creates a Contact item in the given folder and returns the new EWS item id and change key. A blank parentFolderID defaults to the `contacts` distinguished folder.

func (*Client) CreateDraft

func (c *Client) CreateDraft(ctx context.Context, message DraftMessage) (Message, error)

func (*Client) CreateMeetingResponse

func (c *Client) CreateMeetingResponse(ctx context.Context, referenceItemID, changeKey string, kind MeetingResponseKind, body string) error

func (*Client) CreateMessageInFolder

func (c *Client) CreateMessageInFolder(ctx context.Context, folderID string, mime []byte, markRead bool) (Message, error)

func (*Client) CreateTaskItem

func (c *Client) CreateTaskItem(ctx context.Context, parentFolderID string, item TaskInput) (itemID, changeKey string, err error)

CreateTaskItem inserts a new task into the given folder and returns the server-assigned ItemId and ChangeKey.

func (*Client) CreateTasksFolder

func (c *Client) CreateTasksFolder(ctx context.Context, input TasksFolderInput) (folderID, changeKey string, err error)

CreateTasksFolder creates a new tasks subfolder under the given parent and returns the folder ID and change key.

func (*Client) DeleteCalendarItem

func (c *Client) DeleteCalendarItem(ctx context.Context, itemID string, sendCancellations string) error

func (*Client) DeleteContactItem

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

DeleteContactItem permanently removes a contact via DeleteItem with DeleteType=HardDelete.

func (*Client) DeleteFolder

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

DeleteFolder removes a folder via DeleteFolder with MoveToDeletedItems.

func (*Client) DeleteItems

func (c *Client) DeleteItems(ctx context.Context, ids []string, hardDelete bool) error

func (*Client) DeleteTaskItem

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

DeleteTaskItem permanently removes a task via DeleteItem with MoveToDeletedItems.

func (*Client) FindFolderByName

func (c *Client) FindFolderByName(ctx context.Context, name string) (*Folder, error)

func (*Client) FindMessages

func (c *Client) FindMessages(ctx context.Context, folderID string, offset, max int) (FindItemsResult, error)

func (*Client) FindMessagesByQuery

func (c *Client) FindMessagesByQuery(ctx context.Context, folderID string, offset, max int, queryString string, deep bool) (FindItemsResult, error)

FindMessagesByQuery searches a folder using EWS Advanced Query Syntax (AQS) via the <QueryString> element. AQS is the indexed full-text search engine the Outlook client uses, so this returns hits in milliseconds across arbitrary mailbox sizes — unlike Restriction-based scans it does not require downloading every item to filter client-side. Pass Traversal="Deep" via MsgFolderRoot at the call site if you want a whole-mailbox sweep.

func (*Client) FindMessagesRestricted

func (c *Client) FindMessagesRestricted(ctx context.Context, folderID string, offset, max int, restriction FindRestriction) (FindItemsResult, error)

func (*Client) GetAttachment

func (c *Client) GetAttachment(ctx context.Context, attachmentID string) (AttachmentContent, error)

func (*Client) GetCalendarEvents

func (c *Client) GetCalendarEvents(ctx context.Context, folderID string, offset, max int) ([]Event, error)

func (*Client) GetCalendarItem

func (c *Client) GetCalendarItem(ctx context.Context, itemID string) (CalendarItem, error)

func (*Client) GetContactItem

func (c *Client) GetContactItem(ctx context.Context, itemID string) (ContactItem, error)

GetContactItem fetches a single contact by id and returns its parsed fields. Used by the contacts EWS adapter to implement GetContact against the shared EWS client.

func (*Client) GetContacts

func (c *Client) GetContacts(ctx context.Context, folderID string, offset, max int) ([]Contact, error)

func (*Client) GetDelegate

func (c *Client) GetDelegate(ctx context.Context, mailbox string) ([]DelegateUser, error)

GetDelegate invokes the EWS `GetDelegate` SOAP operation for the given mailbox SMTP address and returns the delegate users Exchange reports. The request includes IncludePermissions="true" so each delegate carries its per-folder permission levels.

func (*Client) GetInboxRules

func (c *Client) GetInboxRules(ctx context.Context) ([]Rule, error)

func (*Client) GetMessageMIME

func (c *Client) GetMessageMIME(ctx context.Context, id string) ([]byte, error)

func (*Client) GetMessageSummaries

func (c *Client) GetMessageSummaries(ctx context.Context, ids []string) ([]Message, error)

func (*Client) GetMessages

func (c *Client) GetMessages(ctx context.Context, ids []string) ([]Message, error)

func (*Client) GetTaskItem

func (c *Client) GetTaskItem(ctx context.Context, itemID string) (Task, error)

GetTaskItem fetches a single task item by its ItemId.

func (*Client) GetTasks

func (c *Client) GetTasks(ctx context.Context, folderID string, offset, max int) ([]Task, error)

func (*Client) GetUserOofSettings

func (c *Client) GetUserOofSettings(ctx context.Context, mailbox string) (OofSettings, error)

GetUserOofSettings invokes the EWS `GetUserOofSettings` SOAP operation for the given mailbox SMTP address.

func (*Client) ListCalendarItems

func (c *Client) ListCalendarItems(ctx context.Context, folderID string, rng TimeRange) ([]CalendarItem, error)

func (*Client) ListContactItems

func (c *Client) ListContactItems(ctx context.Context, folderID string, offset, max int) ([]ContactItem, error)

ListContactItems enumerates contacts in the given folder with all properties populated. Empty folderID defaults to the distinguished `contacts` folder. The returned slice preserves server order. offset/max map to FindItem paging; pass max<=0 for the client's configured batch size.

func (*Client) ListFolders

func (c *Client) ListFolders(ctx context.Context) ([]Folder, error)

func (*Client) ListTasksFolders

func (c *Client) ListTasksFolders(ctx context.Context) ([]Folder, error)

ListTasksFolders enumerates all tasks folders under the distinguished tasks folder, including the primary tasks folder itself and any subfolders.

func (*Client) MoveItems

func (c *Client) MoveItems(ctx context.Context, ids []string, folderID string) ([]string, error)

func (*Client) ResolveNames

func (c *Client) ResolveNames(ctx context.Context, unresolved string, includeFullContactData bool) ([]ResolvedContact, error)

ResolveNames invokes the EWS `ResolveNames` operation. It matches against the user's contacts and, when permitted, the Global Address List, and returns every resolution the server found. When includeFullContactData is true each resolution may carry a populated Contact element.

func (*Client) SendDraft

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

func (*Client) SetCategories

func (c *Client) SetCategories(ctx context.Context, ids []string,

	categories []string) error

func (*Client) SetFlag

func (c *Client) SetFlag(ctx context.Context, ids []string,

	status string, dueAt time.Time) error

func (*Client) SetReadState

func (c *Client) SetReadState(ctx context.Context, ids []string, isRead bool) error

func (*Client) SetUserOofSettings

func (c *Client) SetUserOofSettings(ctx context.Context, mailbox string, settings OofSettings) error

SetUserOofSettings invokes the EWS `SetUserOofSettings` SOAP operation for the given mailbox SMTP address. State==Disabled clears the responder; the Duration window is only emitted when State==Scheduled and both endpoints are set, matching the EWS schema requirement.

func (*Client) SyncFolderItems

func (c *Client) SyncFolderItems(ctx context.Context, folderID, syncState string, maxChanges int) (SyncItemsResult, error)

func (*Client) UpdateCalendarItem

func (c *Client) UpdateCalendarItem(ctx context.Context, itemID, changeKey string, updates CalendarItemUpdate, sendInvitationsOrCancellations string) (string, error)

func (*Client) UpdateContactItem

func (c *Client) UpdateContactItem(ctx context.Context, itemID, changeKey string, updates ContactUpdate) (string, error)

UpdateContactItem issues an UpdateItem SOAP call against an existing contact. It returns the new change key. Non-nil fields in updates are translated into SetItemField or DeleteItemField changes per the EWS schema.

func (*Client) UpdateDraft

func (c *Client) UpdateDraft(ctx context.Context, itemID string, message DraftMessage) (Message, error)

func (*Client) UpdateInboxRules

func (c *Client) UpdateInboxRules(ctx context.Context, operations []RuleOperation) error

func (*Client) UpdateTaskItem

func (c *Client) UpdateTaskItem(ctx context.Context, itemID, changeKey string, updates TaskUpdate) (newChangeKey string, err error)

UpdateTaskItem applies field-level updates to an existing task. It returns the new ChangeKey. Nil fields in updates are left untouched; empty-string pointers clear the field via DeleteItemField.

func (*Client) Watch

func (c *Client) Watch(ctx context.Context, opts WatchOptions, onEvents func(StreamBatch) error) error

type Config

type Config struct {
	Endpoint      string
	Username      string
	Password      string
	ServerVersion string
	BatchSize     int
	InsecureTLS   bool
}

type Contact

type Contact struct {
	ID             string
	ChangeKey      string
	ParentFolderID string
	DisplayName    string
	CompanyName    string
	Email          string
	Phones         []string
}

type ContactEmail

type ContactEmail struct {
	Key   string
	Value string
}

ContactEmail is one entry in the EWS `EmailAddresses` collection. Key must be one of EmailAddress1, EmailAddress2, or EmailAddress3.

type ContactItem

type ContactItem struct {
	ID                string
	ChangeKey         string
	ParentFolderID    string
	DisplayName       string
	GivenName         string
	Surname           string
	CompanyName       string
	JobTitle          string
	Department        string
	Notes             string
	EmailAddresses    []ContactEmail
	PhoneNumbers      []ContactPhone
	PhysicalAddresses []ContactPhysicalAddress
	Birthday          *time.Time
}

ContactItem is the EWS-side representation of a contact used by create/read/update paths. It mirrors the fields of the SOAP `Contact` element that the adapter in `internal/contacts` maps to providerdata.Contact.

type ContactPhone

type ContactPhone struct {
	Key   string
	Value string
}

ContactPhone is one entry in the EWS `PhoneNumbers` collection. Key follows the EWS `PhoneNumberKeyType` vocabulary (BusinessPhone, HomePhone, MobilePhone, OtherTelephone, ...).

type ContactPhysicalAddress

type ContactPhysicalAddress struct {
	Key             string
	Street          string
	City            string
	State           string
	PostalCode      string
	CountryOrRegion string
}

ContactPhysicalAddress is one entry in the EWS `PhysicalAddresses` collection. Key is Home, Business, or Other.

type ContactUpdate

type ContactUpdate struct {
	DisplayName       *string
	GivenName         *string
	Surname           *string
	CompanyName       *string
	JobTitle          *string
	Department        *string
	Notes             *string
	Birthday          *time.Time
	ClearBirthday     bool
	EmailAddresses    *[]ContactEmail
	PhoneNumbers      *[]ContactPhone
	PhysicalAddresses *[]ContactPhysicalAddress
}

ContactUpdate describes a partial write against an existing contact item. Non-nil scalar pointers replace the matching EWS property; an empty string clears it via DeleteItemField. Nil scalars are left untouched. Collection pointers follow the same rule: nil skips, non-nil replaces the whole collection (an empty slice clears it).

type DelegatePermissions

type DelegatePermissions struct {
	CalendarFolder string
	TasksFolder    string
	InboxFolder    string
	ContactsFolder string
	NotesFolder    string
	JournalFolder  string
}

DelegatePermissions mirrors the EWS DelegatePermissions element. Each field is the raw permission-level string per Exchange folder; an empty value means the server omitted that folder (commonly "None").

type DelegateUser

type DelegateUser struct {
	PrimarySmtpAddress string
	DisplayName        string
	Permissions        DelegatePermissions
	ViewPrivateItems   bool
	ReceiveCopiesOfMR  bool
}

DelegateUser is one entry returned by GetDelegate, carrying the delegate's identity and per-folder permission levels. Exchange reports permissions as enumerated strings (None, Reviewer, Author, Editor, Custom, ...); callers should treat them as opaque tokens suitable for display.

type DraftMessage

type DraftMessage struct {
	Subject    string
	MIME       []byte
	ThreadID   string
	InReplyTo  string
	References []string
}

type Event

type Event struct {
	ID             string
	ChangeKey      string
	ParentFolderID string
	Subject        string
	Body           string
	BodyType       string
	Location       string
	Start          time.Time
	End            time.Time
	IsAllDay       bool
	UID            string
	Organizer      string
	Attendees      []EventAttendee
	Recurrence     string
	Status         string
}

type EventAttendee

type EventAttendee struct {
	Email    string
	Name     string
	Response string
	Required bool
}

type FindItemsResult

type FindItemsResult struct {
	ItemIDs          []string
	NextOffset       int
	TotalItemsInView int
	IncludesLastPage bool
}

type FindRestriction

type FindRestriction struct {
	From          string
	HasAttachment *bool
	After         time.Time
	Before        time.Time
}

type Folder

type Folder struct {
	ID               string
	ChangeKey        string
	Name             string
	Kind             FolderKind
	TotalCount       int
	ChildFolderCount int
	UnreadCount      int
}

type FolderKind

type FolderKind string
const (
	FolderKindGeneric  FolderKind = "folder"
	FolderKindCalendar FolderKind = "calendar"
	FolderKindContacts FolderKind = "contacts"
	FolderKindTasks    FolderKind = "tasks"
)

type Mailbox

type Mailbox struct {
	Name        string
	Email       string
	RoutingType string
	MailboxType string
}

type MeetingResponseKind

type MeetingResponseKind string
const (
	MeetingAccept            MeetingResponseKind = "accept"
	MeetingTentativelyAccept MeetingResponseKind = "tentative"
	MeetingDecline           MeetingResponseKind = "decline"
)

type Message

type Message struct {
	ID                string
	ChangeKey         string
	ParentFolderID    string
	ConversationID    string
	ConversationTopic string
	InternetMessageID string
	Subject           string
	Body              string
	BodyType          string
	From              Mailbox
	Sender            Mailbox
	To                []Mailbox
	Cc                []Mailbox
	DisplayTo         string
	DisplayCc         string
	WebLink           string
	IsRead            bool
	IsDraft           bool
	HasAttachments    bool
	ReceivedAt        time.Time
	SentAt            time.Time
	CreatedAt         time.Time
	FlagStatus        string
	FlagDueAt         time.Time
	Attachments       []Attachment
}

type OofExternalAudience

type OofExternalAudience string

OofExternalAudience mirrors the EWS `ExternalAudience` enumeration. None only replies to internal senders, Known replies to contacts, All replies to every external sender.

const (
	OofAudienceNone  OofExternalAudience = "None"
	OofAudienceKnown OofExternalAudience = "Known"
	OofAudienceAll   OofExternalAudience = "All"
)

type OofSettings

type OofSettings struct {
	State            OofState
	ExternalAudience OofExternalAudience
	Start            time.Time
	End              time.Time
	InternalReply    string
	ExternalReply    string
}

OofSettings is the canonical EWS-side representation of the user's out-of-office configuration. The mailboxsettings package converts it to and from providerdata.OOFSettings.

type OofState

type OofState string

OofState mirrors the EWS `OofState` enumeration. Disabled means no auto-reply, Enabled means always-on, Scheduled means active only inside the optional Duration window.

const (
	OofStateDisabled  OofState = "Disabled"
	OofStateEnabled   OofState = "Enabled"
	OofStateScheduled OofState = "Scheduled"
)

type ResolvedContact

type ResolvedContact struct {
	Mailbox Mailbox
	Contact ContactItem
}

ResolvedContact pairs a mailbox with the optional Contact element that ResolveNames returns when IncludeFullContactData is set.

type Rule

type Rule struct {
	ID         string
	Name       string
	Priority   int
	Enabled    bool
	Conditions RuleConditions
	Exceptions RuleConditions
	Actions    RuleActions
}

type RuleActions

type RuleActions struct {
	Delete               bool
	MarkAsRead           bool
	StopProcessingRules  bool
	MoveToFolderID       string
	RedirectToRecipients []Mailbox
}

type RuleConditions

type RuleConditions struct {
	ContainsSenderStrings  []string
	ContainsSubjectStrings []string
	FromAddresses          []Mailbox
	SentToAddresses        []Mailbox
	NotSentToMe            bool
	SentCcMe               bool
}

type RuleOperation

type RuleOperation struct {
	Kind RuleOperationKind
	Rule Rule
}

type RuleOperationKind

type RuleOperationKind string
const (
	RuleOperationCreate RuleOperationKind = "create"
	RuleOperationSet    RuleOperationKind = "set"
	RuleOperationDelete RuleOperationKind = "delete"
)

type SOAPFaultError

type SOAPFaultError struct {
	Operation    string
	StatusCode   int
	FaultCode    string
	ResponseCode string
	Message      string
}

func (*SOAPFaultError) Error

func (e *SOAPFaultError) Error() string

type StreamBatch

type StreamBatch struct {
	SubscriptionID    string
	PreviousWatermark string
	MoreEvents        bool
	Events            []StreamEvent
}

type StreamEvent

type StreamEvent struct {
	Type              string
	ItemID            string
	OldItemID         string
	FolderID          string
	ParentFolderID    string
	OldParentFolderID string
	Watermark         string
}

type SyncItemsResult

type SyncItemsResult struct {
	SyncState        string
	ItemIDs          []string
	DeletedItemIDs   []string
	IncludesLastItem bool
}

type Task

type Task struct {
	ID             string
	ChangeKey      string
	ParentFolderID string
	Subject        string
	Body           string
	BodyType       string
	Status         string
	StartDate      *time.Time
	DueDate        *time.Time
	CompleteDate   *time.Time
	IsComplete     bool
}

type TaskInput

type TaskInput struct {
	Subject       string
	Body          string
	BodyType      string
	StartDate     *time.Time
	DueDate       *time.Time
	Status        string
	Importance    string
	ReminderSet   bool
	ReminderDueBy *time.Time
}

TaskInput carries the fields needed to create a new EWS Task item.

type TaskUpdate

type TaskUpdate struct {
	Subject       *string
	Body          *string
	BodyType      *string
	StartDate     *time.Time
	DueDate       *time.Time
	Status        *string
	Importance    *string
	IsComplete    *bool
	CompleteDate  *time.Time
	ReminderSet   *bool
	ReminderDueBy *time.Time
}

TaskUpdate carries the optional fields for updating an existing EWS Task item. A nil pointer means "leave the field unchanged"; an empty string means "clear it".

type TasksFolderInput

type TasksFolderInput struct {
	ParentFolderID string
	DisplayName    string
}

TasksFolderInput carries the fields needed to create a new tasks folder.

type TimeRange

type TimeRange struct {
	Start time.Time
	End   time.Time
}

type WatchOptions

type WatchOptions struct {
	SubscribeToAllFolders bool
	FolderIDs             []string
	ConnectionTimeout     time.Duration
}

Jump to

Keyboard shortcuts

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