Documentation
¶
Overview ¶
Package ews is the EWS protocol backend (Exchange Web Services, on-premises Exchange 2016 and later; ADR 0037): a backend.Receiver over an account's EWS URL, through the thin SOAP layer in this package.
Index ¶
- Constants
- Variables
- func Discover(ctx context.Context, cfg DiscoverConfig) (string, error)
- type Config
- type ConfirmError
- type DiscoverConfig
- type Net
- type Receiver
- func (r *Receiver) Apply(ctx context.Context, op backend.Op) (backend.Result, error)
- func (r *Receiver) Check(ctx context.Context) (backend.CheckResult, error)
- func (r *Receiver) Close() error
- func (r *Receiver) Describe(ctx context.Context) (backend.Description, error)
- func (r *Receiver) Fetch(ctx context.Context, req backend.ContentRequest) (io.ReadCloser, error)
- func (r *Receiver) Find(ctx context.Context, folder backend.FolderRef, messageID string, size int64) ([]backend.MessageRef, error)
- func (r *Receiver) Headers(ctx context.Context, _ backend.FolderRef, refs []backend.MessageRef, ...) (map[backend.MessageRef][]byte, error)
- func (r *Receiver) Sync(ctx context.Context, req backend.SyncRequest, commit func(backend.Page) error) (bool, error)
- func (r *Receiver) Watch(ctx context.Context, wake func(folders []backend.FolderRef)) error
- type ResponseError
- type Sender
Constants ¶
const ReasonExtendedProtection = "ews.extended_protection"
ReasonExtendedProtection is the add-account check's refusal of a server that requires Extended Protection (NTLM bound to the TLS channel), which the client does not do.
const ReasonNoAutodiscover = "ews.no_autodiscover"
ReasonNoAutodiscover is the add-account check's word for Autodiscover finding no EWS URL: the user types it in.
const ReasonServerTooOld = "ews.server_too_old"
ReasonServerTooOld is the add-account check's refusal of a server older than Exchange 2016.
Variables ¶
var ErrExtendedProtection = errors.New(ReasonExtendedProtection)
ErrExtendedProtection is a sign-in the server refused over NTLM but took over Basic: NTLM without channel binding is what it refuses. Its message is ReasonExtendedProtection.
var ErrNoAutodiscover = errors.New(ReasonNoAutodiscover)
ErrNoAutodiscover is Autodiscover finding no EWS URL. Its message is ReasonNoAutodiscover.
var ErrServerTooOld = errors.New(ReasonServerTooOld)
ErrServerTooOld is Check on a server older than Exchange 2016. Its message is ReasonServerTooOld.
Functions ¶
func Discover ¶
func Discover(ctx context.Context, cfg DiscoverConfig) (string, error)
Discover finds the EWS URL of cfg.Email by Autodiscover, trying in turn https://<domain>, https://autodiscover.<domain>, the redirect of an unauthenticated plain-HTTP GET of autodiscover.<domain> and the _autodiscover._tcp SRV record; each SOAP first, then POX. The credentials go over HTTPS only, and to a host outside the address's registrable domain only once confirmed: before that it returns a *ConfirmError naming it. The EWS URL it returns is held to the same rule, loopback aside. Redirects within the domain are followed.
Types ¶
type Config ¶
type Config struct {
// URL is the EWS endpoint, such as https://mail.corp.example/EWS/Exchange.asmx.
URL string
// Address is the account's email address, the mailbox a subscription
// anchors on (X-AnchorMailbox).
Address string
Credentials backend.CredentialsFunc
// Wait waits d out, or until ctx is done, when the server asks to back
// off. Nil waits in real time; tests pass a fake.
Wait func(ctx context.Context, d time.Duration) error
}
Config is how to reach an account.
type ConfirmError ¶
type ConfirmError struct{ Host string }
ConfirmError stops Discover before the credentials go to Host, outside the address's registrable domain: run it again with Host confirmed.
func (*ConfirmError) Error ¶
func (e *ConfirmError) Error() string
type DiscoverConfig ¶
type DiscoverConfig struct {
Email string
Credentials backend.CredentialsFunc
// Confirmed are hosts outside Email's registrable domain the user agreed
// to send the credentials to.
Confirmed []string
Net Net
}
DiscoverConfig is what Discover looks an EWS URL up with.
type Net ¶
type Net struct {
Dial func(ctx context.Context, network, addr string) (net.Conn, error)
RootCAs *x509.CertPool
LookupSRV func(ctx context.Context, service, proto, name string) (string, []*net.SRV, error)
}
Net is how Discover reaches the network; zero fields are the system's. Tests point it at a fake.
type Receiver ¶
type Receiver struct {
// contains filtered or unexported fields
}
Receiver is an EWS account's receiving backend. A folder's FolderRef is its FolderId, a message's MessageRef its ItemId (no ChangeKey), and a folder's cursor its SyncFolderItems SyncState.
func (*Receiver) Apply ¶
Apply implements backend.Receiver. SetFlags updates the item's flags; Move and Copy ask for the new ItemId (a move changes it), Done with it or Unlocated without; Delete moves to Deleted Items; Purge deletes for good once Confirm agrees; Append saves the MIME message with its flags.
func (*Receiver) Check ¶
Check implements backend.Receiver: signing in, Exchange 2016 or later, and listing the folders. A refused sign-in the server takes over Basic is ErrExtendedProtection.
func (*Receiver) Describe ¶
Describe implements backend.Receiver. Its first call signs in, so refused credentials are ErrAuthFailed here.
func (*Receiver) Fetch ¶
func (r *Receiver) Fetch(ctx context.Context, req backend.ContentRequest) (io.ReadCloser, error)
Fetch implements backend.Receiver. The sync gives whole messages, which local storage parses, so a part is named by its IMAP part path ("1.2") and cut from the whole message, still transfer-encoded as IMAP gives it.
func (*Receiver) Find ¶
func (r *Receiver) Find(ctx context.Context, folder backend.FolderRef, messageID string, size int64) ([]backend.MessageRef, error)
Find implements backend.Receiver: FindItem on InternetMessageId; a size is the MIME message's, as the sync stores it, so it is compared on the MIME content of the items found.
func (*Receiver) Headers ¶
func (r *Receiver) Headers(ctx context.Context, _ backend.FolderRef, refs []backend.MessageRef, fields []string) (map[backend.MessageRef][]byte, error)
Headers implements backend.Receiver: GetItem with the MIME content, the fields cut from it.
func (*Receiver) Sync ¶
func (r *Receiver) Sync(ctx context.Context, req backend.SyncRequest, commit func(backend.Page) error) (bool, error)
Sync implements backend.Receiver: the folders, when they changed since the account cursor, then each folder's SyncFolderItems pages from its cursor. A folder's first sync reports its mail in the window as backfill, mail created after it as new arrivals if received in the window (mail moved in keeps its older time); an Update or ReadFlagChange is the item's flags, a Delete its location gone. A folder whose SyncState the server voided is reset and synced from nothing, local storage claiming its mail again. Older takes what the window left out instead. shortcut: a window grown after the first sync brings in nothing more, only 加载更早 does; scan the folder with FindItem down to the new cutoff (tracked in Filled) if users miss it. shortcut: the sync downloads whole messages; take their structure from Attachments and fetch parts with GetAttachment if large mail slows it.
func (*Receiver) Watch ¶
Watch implements backend.Receiver over a streaming subscription to all folders, kept for the account across Watch calls: each notification wakes for the folders its events name. A connection that reached its 30 minutes is opened again on the same subscription; a subscription the server lost is made again, with a wake for what it missed. A failed connection ends Watch, and core polls; so does a server that refuses to subscribe.
type ResponseError ¶
type ResponseError struct {
Code string // ResponseCode, such as ErrorItemNotFound
Text string // MessageText, as the server sent it
}
ResponseError is the server's refusal of one item of a request.
func (*ResponseError) Error ¶
func (e *ResponseError) Error() string
type Sender ¶
type Sender struct {
// contains filtered or unexported fields
}
Sender is an EWS account's sending backend: CreateItem with the MIME message and SendAndSaveCopy, so Exchange files the sent copy in Sent Items.
func (*Sender) SavesSent ¶
SavesSent implements backend.Sender: Exchange files what it sends in Sent Items.
func (*Sender) Send ¶
Send implements backend.Sender. Exchange takes the recipients from the MIME's To and Cc; rcpts they do not name go as BccRecipients, so they are never written into the message. A request written whole without an answer is ErrUncertain; the server refusing the message is a *RejectedError; ErrorServerBusy, a SOAP fault or an HTTP error is a plain error, tried again.