testmail

package
v1.39.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 48 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 testmail provides in-memory IMAP and SMTP servers for tests.

Index

Constants

View Source
const (
	GmailAllMail = "[Gmail]/All Mail"
	GmailSent    = "[Gmail]/Sent Mail"
	GmailDrafts  = "[Gmail]/Drafts"
	GmailTrash   = "[Gmail]/Trash"
	GmailSpam    = "[Gmail]/Spam"
)

Gmail's folders, which a Gmail server starts with besides INBOX.

View Source
const DefaultSeed int64 = 716

DefaultSeed is the fixed PRNG seed benchmarks use so every run builds the same mailboxes.

Variables

View Source
var (
	ScaleSmall  = Scale{Name: "small", Accounts: 1, Folders: 5, Messages: 50}
	ScaleMedium = Scale{Name: "medium", Accounts: 2, Folders: 12, Messages: 200}
	ScaleLarge  = Scale{Name: "large", Accounts: 3, Folders: 24, Messages: 400}
)

Functions

func AutodiscoverRoots added in v1.35.0

func AutodiscoverRoots() *x509.CertPool

AutodiscoverRoots trusts the certificate every Autodiscover presents.

func CardDAVCert added in v1.36.0

func CardDAVCert() tls.Certificate

CardDAVCert returns the shared TLS certificate presented by fake CardDAV servers.

func CardDAVRoots added in v1.36.0

func CardDAVRoots() *x509.CertPool

CardDAVRoots returns a CertPool trusting both Autodiscover and CardDAV test servers.

func PopulateMailbox added in v1.36.0

func PopulateMailbox(tb testing.TB, im *IMAP, email string, seed int64, folders, messages int)

PopulateMailbox creates extra project folders up to folders (>= 4) on im and appends messages deterministic RFC 5322 messages driven by seed.

Types

type Autodiscover added in v1.35.0

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

Autodiscover is a fake Autodiscover service for an EWS server's mailbox. It answers as the hosts it is told to, each in its own way: with the EWS URL (Serve, ServeSOAP, ServePOX), or by sending the client on (RedirectURL, RedirectAddr, Moved, RedirectGET, SRV), to the same domain or another. Both forms are spoken: SOAP (GetUserSettings at autodiscover.svc) and POX (autodiscover.xml). Hosts are reached through Net, over HTTPS with a certificate for example.com, example.net, example.org and their subdomains; only RedirectGET's hosts answer plain HTTP, and a request carrying credentials there fails the test.

func (*Autodiscover) AnswerEWSURL added in v1.35.0

func (a *Autodiscover) AnswerEWSURL(u string)

AnswerEWSURL makes every host answer u as the EWS URL instead of the EWS server's own.

func (*Autodiscover) Credentialed added in v1.35.0

func (a *Autodiscover) Credentialed(host string) bool

Credentialed reports whether a request carrying credentials reached host.

func (*Autodiscover) Dial added in v1.35.0

func (a *Autodiscover) Dial(ctx context.Context, network, addr string) (net.Conn, error)

Dial connects to host:443 of a host the fake answers as, or host:80 of a RedirectGET host; any other address does not resolve.

func (*Autodiscover) LookupSRV added in v1.35.0

func (a *Autodiscover) LookupSRV(_ context.Context, service, proto, name string) (string, []*net.SRV, error)

LookupSRV answers _autodiscover._tcp lookups SRV published.

func (*Autodiscover) Moved added in v1.35.0

func (a *Autodiscover) Moved(host, to string)

Moved makes host answer its POSTs with an HTTP 302 to the same path on to.

func (*Autodiscover) Net added in v1.35.0

func (a *Autodiscover) Net() ews.Net

Net reaches the fake's hosts (and nothing else) and its DNS.

func (*Autodiscover) RedirectAddr added in v1.35.0

func (a *Autodiscover) RedirectAddr(host, email string)

RedirectAddr makes host answer both forms by sending the client to start over with the address email.

func (*Autodiscover) RedirectGET added in v1.35.0

func (a *Autodiscover) RedirectGET(host, to string)

RedirectGET makes host answer the unauthenticated plain-HTTP GET of autodiscover.xml with a 302 to it on https://to.

func (*Autodiscover) RedirectURL added in v1.35.0

func (a *Autodiscover) RedirectURL(host, to string)

RedirectURL makes host answer both forms by sending the client to the same form on host to.

func (*Autodiscover) SRV added in v1.35.0

func (a *Autodiscover) SRV(domain, target string)

SRV publishes _autodiscover._tcp.domain pointing at target:443.

func (*Autodiscover) Serve added in v1.35.0

func (a *Autodiscover) Serve(host string)

Serve makes host answer both forms with the EWS URL.

func (*Autodiscover) ServePOX added in v1.35.0

func (a *Autodiscover) ServePOX(host string)

ServePOX makes host answer POX only, as Exchange 2007 did; SOAP is 404.

func (*Autodiscover) ServeSOAP added in v1.35.0

func (a *Autodiscover) ServeSOAP(host string)

ServeSOAP makes host answer SOAP only, as Exchange Online does; POX is 404.

type CardDAV added in v1.36.0

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

CardDAV is an in-process HTTPS CardDAV server for tests, supporting /.well-known/carddav discovery, PROPFIND, sync-collection (RFC 6578), addressbook-multiget (RFC 6352), Basic/OAuth auth, external HTTPS PHOTO assets, and fault injection.

func StartCardDAV added in v1.36.0

func StartCardDAV(t testing.TB) *CardDAV

StartCardDAV starts a fake HTTPS CardDAV server with default Basic credentials alice/secret.

func (*CardDAV) CollectionURL added in v1.36.0

func (s *CardDAV) CollectionURL(slug string) string

func (*CardDAV) DeleteCard added in v1.36.0

func (s *CardDAV) DeleteCard(collectionSlug, name string)

func (*CardDAV) DisableSyncCollection added in v1.36.0

func (s *CardDAV) DisableSyncCollection(off bool)

func (*CardDAV) FailRequests added in v1.36.0

func (s *CardDAV) FailRequests(status int)

func (*CardDAV) HomeSetURL added in v1.36.0

func (s *CardDAV) HomeSetURL() string

func (*CardDAV) InvalidateSyncTokens added in v1.36.0

func (s *CardDAV) InvalidateSyncTokens()

func (*CardDAV) PhotoHits added in v1.36.0

func (s *CardDAV) PhotoHits(name string) int

func (*CardDAV) PrincipalURL added in v1.36.0

func (s *CardDAV) PrincipalURL() string

func (*CardDAV) PutCard added in v1.36.0

func (s *CardDAV) PutCard(collectionSlug, name, vcard string) (href, etag string)

func (*CardDAV) PutCollection added in v1.36.0

func (s *CardDAV) PutCollection(slug, displayName string)

func (*CardDAV) RejectAuth added in v1.36.0

func (s *CardDAV) RejectAuth(reject bool)

func (*CardDAV) RemoveCollection added in v1.36.0

func (s *CardDAV) RemoveCollection(slug string)

func (*CardDAV) Requests added in v1.36.0

func (s *CardDAV) Requests() []CardDAVRequest

func (*CardDAV) ResetRequests added in v1.36.0

func (s *CardDAV) ResetRequests()

func (*CardDAV) ServePhoto added in v1.36.0

func (s *CardDAV) ServePhoto(name, contentType string, data []byte) string

func (*CardDAV) SetBasicAuth added in v1.36.0

func (s *CardDAV) SetBasicAuth(user, pass string)

func (*CardDAV) SetCollectionPropfindHook added in v1.36.0

func (s *CardDAV) SetCollectionPropfindHook(fn func(slug string) string)

SetCollectionPropfindHook overrides the <D:response> XML emitted for a given collection slug during a home-set PROPFIND when fn returns a non-empty string.

func (*CardDAV) SetHomeSetURL added in v1.36.0

func (s *CardDAV) SetHomeSetURL(u string)

func (*CardDAV) SetMultigetHook added in v1.36.0

func (s *CardDAV) SetMultigetHook(fn func(href string) int)

SetMultigetHook installs an optional callback invoked per requested href in addressbook-multiget without holding the server mutex. Returning an HTTP status >= 400 emits a failing propstat for that href.

func (*CardDAV) SetNoCollections added in v1.36.0

func (s *CardDAV) SetNoCollections(empty bool)

func (*CardDAV) SetOAuthValidator added in v1.36.0

func (s *CardDAV) SetOAuthValidator(fn func(token string) bool)

func (*CardDAV) SetPhotoStatus added in v1.36.0

func (s *CardDAV) SetPhotoStatus(name string, status int)

SetPhotoStatus injects an HTTP failure status (0 = normal 200 OK) for a named asset previously registered with ServePhoto.

func (*CardDAV) SetPrincipalOnlyURL added in v1.36.0

func (s *CardDAV) SetPrincipalOnlyURL(u string)

func (*CardDAV) SetWellKnownRedirect added in v1.36.0

func (s *CardDAV) SetWellKnownRedirect(target string)

func (*CardDAV) URL added in v1.36.0

func (s *CardDAV) URL() string

type CardDAVRequest added in v1.36.0

type CardDAVRequest struct {
	Method     string
	Path       string
	ReportKind string
	HasAuth    bool
}

CardDAVRequest records one HTTP request to the fake CardDAV server.

type DKIMFixture added in v1.21.0

type DKIMFixture struct {
	Records map[string][]string
	// contains filtered or unexported fields
}

DKIMFixture signs real message bytes and serves only deterministic public DNS test records. No real mailbox, key or external DNS service is used.

func NewDKIMFixture added in v1.21.0

func NewDKIMFixture(t testing.TB) *DKIMFixture

func (*DKIMFixture) LookupTXT added in v1.21.0

func (f *DKIMFixture) LookupTXT(ctx context.Context, name string) ([]string, error)

func (*DKIMFixture) Sign added in v1.21.0

func (f *DKIMFixture) Sign(t testing.TB, from, domain string, options ...func(*dkim.SignOptions)) []byte

type EWS added in v1.35.0

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

EWS is a running fake EWS server (Exchange Web Services) with one mailbox, alice/secret over HTTP Basic (or NTLM: UseNTLM), that starts with the distinguished mail folders and a calendar. It speaks GetFolder, SyncFolderHierarchy, SyncFolderItems, GetItem, FindItem, UpdateItem, CreateItem sending a message, the write-back operations (ews_writeback.go), and Subscribe and GetStreamingEvents (ews_push.go); an operation it does not know fails the test. Its responses spell the namespace prefixes differently from operation to operation, as servers do. Hooks change the mailbox as another client would (MarkRead, MarkFlagged, MarkAnswered, Remove, RenameFolder, RemoveFolder) or inject faults (RejectAuth, SetVersion, Reset, Busy, Refuse, LoseVerdict, GarbleVerdict, RejectNextSendAuth, DropNextChallenge, OmitNewItemIds, LoseMoveVerdict, LoseSubscriptions, DropStreams, Advance).

Every change takes the next sequence number, and deleted items and folders stay as tombstones, so a SyncState, the sequence number it was given at, says what changed since.

func StartEWS added in v1.35.0

func StartEWS(t testing.TB) *EWS

StartEWS starts an EWS server answering as Exchange 2019, closed when t ends.

func (*EWS) Advance added in v1.35.0

func (s *EWS) Advance(d time.Duration)

Advance moves the server's clock on by d: streaming connections whose ConnectionTimeout it passes are closed.

func (*EWS) Affinity added in v1.35.0

func (s *EWS) Affinity() []EWSAffinity

Affinity is what each signed-in request carried for affinity, in order.

func (*EWS) Busy added in v1.35.0

func (s *EWS) Busy(n int, backOff time.Duration, fault bool)

Busy makes the server refuse the next n requests with ErrorServerBusy asking to wait backOff, as a SOAP fault with HTTP 500 when fault, else as the operation's response message with HTTP 503.

func (*EWS) Count added in v1.35.0

func (s *EWS) Count(name string) int

Count is how many items the top-level folder name holds.

func (*EWS) Deliver added in v1.35.0

func (s *EWS) Deliver(path string, raw []byte) string

Deliver puts raw into the folder at path, as mail arriving, and returns its ItemId. Path segments name folders from the root ("Inbox/Projects"), created if need be; "INBOX" is the inbox.

func (*EWS) DeliverAt added in v1.35.0

func (s *EWS) DeliverAt(path string, raw []byte, received time.Time) string

DeliverAt is Deliver of mail received at received: mail moved in from another folder or mailbox keeps the time it first arrived.

func (*EWS) DropNextChallenge added in v1.35.0

func (s *EWS) DropNextChallenge()

DropNextChallenge makes the server read the whole next NTLM NEGOTIATE request and close the connection instead of challenging it: the request went out, but nothing was sent.

func (*EWS) DropStreams added in v1.35.0

func (s *EWS) DropStreams()

DropStreams breaks the open streaming connections mid-response.

func (*EWS) FailItem added in v1.35.0

func (s *EWS) FailItem(id, code string)

FailItem makes GetItem answer the item id with the error code, as Exchange does for an item it cannot render (say ErrorMimeContentConversionFailed); the folder's sync still lists it.

func (*EWS) FailSend added in v1.35.0

func (s *EWS) FailSend(code string)

FailSend makes the server answer the next CreateItem with ResponseCode code, such as ErrorInternalServerTransientError, and send nothing.

func (*EWS) GarbleVerdict added in v1.35.0

func (s *EWS) GarbleVerdict(body string)

GarbleVerdict makes the server send the next CreateItem and answer it with HTTP 200 and body, such as an empty or cut-off one.

func (*EWS) GatewayVerdict added in v1.35.0

func (s *EWS) GatewayVerdict(status int, body string)

GatewayVerdict makes the server send the next CreateItem and answer it with HTTP status and body, as a reverse proxy does that gave up waiting (502, 504) after it forwarded the request.

func (*EWS) Items added in v1.35.0

func (s *EWS) Items(path string) []string

Items is the ItemIds of the mail in the folder at path, in order.

func (*EWS) LimitFindItem added in v1.35.0

func (s *EWS) LimitFindItem(n int)

LimitFindItem makes a FindItem page hold at most n items, whatever the client asks for, as a server's throttling policy does.

func (*EWS) LoseMoveVerdict added in v1.37.0

func (s *EWS) LoseMoveVerdict()

LoseMoveVerdict makes the server do the next MoveItem and close the connection without answering.

func (*EWS) LoseSubscriptions added in v1.35.0

func (s *EWS) LoseSubscriptions()

LoseSubscriptions drops every subscription, as a mailbox server that restarted does: open connections end with ErrorSubscriptionNotFound.

func (*EWS) LoseVerdict added in v1.35.0

func (s *EWS) LoseVerdict()

LoseVerdict makes the server read the whole next CreateItem, send it, and close the connection without answering.

func (*EWS) MarkAnswered added in v1.35.0

func (s *EWS) MarkAnswered(id string)

MarkAnswered records a reply to the item id (PidTagLastVerbExecuted 102).

func (*EWS) MarkFlagged added in v1.35.0

func (s *EWS) MarkFlagged(id string, flagged bool)

MarkFlagged flags or unflags the item id.

func (*EWS) MarkRead added in v1.35.0

func (s *EWS) MarkRead(id string, read bool)

MarkRead marks the item id read or unread.

func (*EWS) MaxConcurrent added in v1.35.0

func (s *EWS) MaxConcurrent() int

MaxConcurrent is the most requests the server has had in hand at once.

func (*EWS) OmitNewItemIds added in v1.35.0

func (s *EWS) OmitNewItemIds()

OmitNewItemIds makes MoveItem and CopyItem answer without the new ItemIds, as Exchange does for a move to another mailbox.

func (*EWS) Password added in v1.35.0

func (s *EWS) Password() string

Password is the password a client should use: "secret", or a wrong one after RejectAuth.

func (*EWS) Read added in v1.35.0

func (s *EWS) Read(id string) bool

Read reports whether the item id is read.

func (*EWS) Refuse added in v1.35.0

func (s *EWS) Refuse(rcpt string)

Refuse makes the server refuse every message to rcpt.

func (*EWS) RefuseSubscribe added in v1.35.0

func (s *EWS) RefuseSubscribe(code string)

RefuseSubscribe makes the server answer every Subscribe with ResponseCode code, such as ErrorExceededSubscriptionCount when other clients hold the account's subscriptions.

func (*EWS) RejectAuth added in v1.35.0

func (s *EWS) RejectAuth()

RejectAuth makes Password wrong from now on, so the server refuses it.

func (*EWS) RejectNextSendAuth added in v1.35.0

func (s *EWS) RejectNextSendAuth()

RejectNextSendAuth makes the server refuse the credentials of the next CreateItem only, as when the password changes between a sync's sign-in and its send.

func (*EWS) Remove added in v1.35.0

func (s *EWS) Remove(id string)

Remove deletes the item id for good.

func (*EWS) RemoveFolder added in v1.35.0

func (s *EWS) RemoveFolder(path string)

RemoveFolder deletes the folder at path with its mail.

func (*EWS) RenameFolder added in v1.35.0

func (s *EWS) RenameFolder(path, name string)

RenameFolder renames the folder at path to name; its FolderId stays.

func (*EWS) Requests added in v1.35.0

func (s *EWS) Requests() int

Requests is how many signed-in requests the server has answered.

func (*EWS) RequireExtendedProtection added in v1.35.0

func (s *EWS) RequireExtendedProtection()

RequireExtendedProtection makes the server also offer Basic and refuse every NTLM sign-in that does not bind the TLS channel, as IIS does when Extended Protection is Required. shortcut: refuses every NTLM sign-in, since the client sends no channel binding; check MsvAvChannelBindings when it does.

func (*EWS) Reset added in v1.35.0

func (s *EWS) Reset(path string)

Reset voids every SyncState given for the folder at path, as a server that lost its synchronization state does: the next SyncFolderItems from one is ErrorInvalidSyncStateData. ItemIds stay, as on Exchange.

func (*EWS) Sent added in v1.35.0

func (s *EWS) Sent() []EWSSent

Sent is every message the server has sent, in order.

func (*EWS) SetLatency added in v1.35.0

func (s *EWS) SetLatency(d time.Duration)

SetLatency makes each request take d before the server answers it, so requests sent at once overlap.

func (*EWS) SetVersion added in v1.35.0

func (s *EWS) SetVersion(major, minor int)

SetVersion makes the server say it is Exchange major.minor (15.0 is 2013, 15.1 2016, 15.2 2019).

func (*EWS) StartAutodiscover added in v1.35.0

func (s *EWS) StartAutodiscover() *Autodiscover

StartAutodiscover starts Autodiscover for s, giving s.URL() as the EWS URL. It signs in as s does; it is closed when the test ends.

func (*EWS) Streams added in v1.35.0

func (s *EWS) Streams() int

Streams is how many GetStreamingEvents connections have been opened.

func (*EWS) Subscriptions added in v1.35.0

func (s *EWS) Subscriptions() int

Subscriptions is how many subscriptions the server holds.

func (*EWS) URL added in v1.35.0

func (s *EWS) URL() string

URL is the EWS endpoint.

func (*EWS) Unsent added in v1.35.0

func (s *EWS) Unsent(id string) bool

Unsent reports that the item id was saved as a draft.

func (*EWS) UseNTLM added in v1.35.0

func (s *EWS) UseNTLM()

UseNTLM makes the server offer Negotiate and NTLM (NTLMv2) instead of Basic, as Exchange's EWS directory does by default. It takes alice as EXAMPLE\alice, alice (no domain) or alice@example.com.

func (*EWS) WaitStreams added in v1.35.0

func (s *EWS) WaitStreams(t testing.TB, n int)

WaitStreams waits until n GetStreamingEvents connections have been opened.

type EWSAffinity added in v1.35.0

type EWSAffinity struct {
	Op     string
	Anchor string // X-AnchorMailbox
	Prefer string // X-PreferServerAffinity
	Cookie string // the X-BackEndOverrideCookie cookie
}

EWSAffinity is what a signed-in request carried for subscription affinity.

type EWSSent added in v1.35.0

type EWSSent struct {
	Rcpts []string
	Raw   []byte
}

EWSSent is a message the server sent: its recipients and MIME as it got them.

type GmailMessage added in v1.30.0

type GmailMessage struct {
	ID uint64 // X-GM-MSGID
	// contains filtered or unexported fields
}

GmailMessage is one Gmail message, in the folders it has a UID in.

func (*GmailMessage) Folders added in v1.30.0

func (m *GmailMessage) Folders() []string

Folders lists the folders the message is in, sorted.

func (*GmailMessage) Label added in v1.30.0

func (m *GmailMessage) Label(folder string)

Label adds the message to folder, as another client does: a new UID there, with the message's flags.

func (*GmailMessage) UID added in v1.30.0

func (m *GmailMessage) UID(folder string) imap.UID

UID is the message's UID in folder, 0 when it is not there.

func (*GmailMessage) Unlabel added in v1.30.0

func (m *GmailMessage) Unlabel(folder string)

Unlabel takes the message out of folder, as archiving or removing a label does in another client.

type Graph added in v1.35.0

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

Graph is an in-process fake Microsoft Graph v1.0 server with one mailbox (alice@outlook.com) that starts with the standard Outlook mail folders. It speaks /me, /me/mailFolders (listing, childFolders, well-known names, delta), /me/mailFolders/{id}/messages (listing, $filter, delta), /me/messages/{id} (GET, PATCH, DELETE, /$value, /move, /copy), POST /me/messages (MIME upload), and POST /me/sendMail.

func StartGraph added in v1.35.0

func StartGraph(t testing.TB) *Graph

StartGraph starts an in-process fake Microsoft Graph server, closed when t ends.

func (*Graph) AllowToken added in v1.35.0

func (s *Graph) AllowToken(tok string)

AllowToken sets the accepted Bearer token and clears RejectAuth.

func (*Graph) Deliver added in v1.35.0

func (s *Graph) Deliver(folder string, raw []byte) string

Deliver adds raw to folder (creating it if needed) at the server's next monotonic arrival timestamp and returns its ImmutableId.

func (*Graph) DeliverAt added in v1.35.0

func (s *Graph) DeliverAt(folder string, raw []byte, received time.Time) string

DeliverAt adds raw to folder with the given receivedDateTime (or the next monotonic server arrival time when zero) and returns its ImmutableId.

func (*Graph) Folder added in v1.35.0

func (s *Graph) Folder(name string) string

Folder returns the id of folder name (creating nested segments on "/" if missing). "INBOX" resolves to the Inbox folder.

func (*Graph) HostURL added in v1.35.0

func (s *Graph) HostURL() string

HostURL is the server's origin without /v1.0.

func (*Graph) MarkFlagged added in v1.35.0

func (s *Graph) MarkFlagged(immutableID string, flagged bool)

MarkFlagged updates a message's flag state as another client would.

func (*Graph) MarkRead added in v1.35.0

func (s *Graph) MarkRead(immutableID string, read bool)

MarkRead updates a message's isRead state as another client would.

func (*Graph) MaxInFlight added in v1.35.0

func (s *Graph) MaxInFlight() int

MaxInFlight returns the maximum concurrent in-flight requests observed.

func (*Graph) MessageState added in v1.35.0

func (s *Graph) MessageState(immutableID string) (folderID string, read, flagged bool, categories []string, ok bool)

MessageState returns the server-side folder ID, read/flagged state and categories of immutableID.

func (*Graph) MoveMessage added in v1.35.0

func (s *Graph) MoveMessage(immutableID, dstFolder string)

MoveMessage moves immutableID into dstFolder on the server as another client would.

func (*Graph) NonImmutableRequests added in v1.35.0

func (s *Graph) NonImmutableRequests() int

NonImmutableRequests returns how many authenticated requests lacked Prefer: IdType="ImmutableId".

func (*Graph) RejectAuth added in v1.35.0

func (s *Graph) RejectAuth()

RejectAuth causes future requests with Token() or the old token to fail with 401.

func (*Graph) Remove added in v1.35.0

func (s *Graph) Remove(immutableID string)

Remove deletes a message on the server as another client would.

func (*Graph) RenameFolder added in v1.35.0

func (s *Graph) RenameFolder(folderID, newName string)

RenameFolder renames a folder on the server as another client would.

func (*Graph) Reset added in v1.35.0

func (s *Graph) Reset(folder string)

Reset invalidates deltaLinks for folder with HTTP 410 Gone.

func (*Graph) ResetWith added in v1.35.0

func (s *Graph) ResetWith(folder string, status int, inner bool)

ResetWith invalidates deltaLinks for folder using status (e.g. 410 or 400) and optionally nesting syncStateNotFound inside error.innerError.code.

func (*Graph) SendURL added in v1.35.0

func (s *Graph) SendURL() string

SendURL is the Graph v1.0 sendMail endpoint URL.

func (*Graph) Sent added in v1.35.0

func (s *Graph) Sent() []GraphSent

Sent returns copies of all messages submitted via /me/sendMail.

func (*Graph) SetAfterFolderDelta added in v1.35.0

func (s *Graph) SetAfterFolderDelta(fn func(folderName string))

SetAfterFolderDelta registers a hook invoked after a folder's final delta page is written, allowing tests to inject mid-round server mutations.

func (*Graph) SetAfterFolderList added in v1.35.0

func (s *Graph) SetAfterFolderList(fn func())

SetAfterFolderList registers a hook invoked right after GET /me/mailFolders completes, allowing tests to simulate folder changes racing hierarchy setup.

func (*Graph) SetCategories added in v1.35.0

func (s *Graph) SetCategories(immutableID string, cats []string)

SetCategories sets a message's categories as another client would.

func (*Graph) SetDeltaPageSize added in v1.35.0

func (s *Graph) SetDeltaPageSize(n int)

SetDeltaPageSize limits how many entries each delta response page carries.

func (*Graph) SetLatency added in v1.35.0

func (s *Graph) SetLatency(d time.Duration)

SetLatency delays each request so concurrency tests can observe overlap.

func (*Graph) SetListPageSize added in v1.35.0

func (s *Graph) SetListPageSize(n int)

SetListPageSize limits how many folders/messages a non-delta page carries.

func (*Graph) SetOmitWellKnownNames added in v1.35.0

func (s *Graph) SetOmitWellKnownNames(on bool)

SetOmitWellKnownNames omits wellKnownName in folder list responses so the client must fall back to probing well-known folder paths.

func (*Graph) SetPartialFlagDeltas added in v1.35.0

func (s *Graph) SetPartialFlagDeltas(on bool)

SetPartialFlagDeltas makes delta responses omit unchanged flag fields on a read-only update, exercising Receiver's full-flags fallback.

func (*Graph) SetTokenValidator added in v1.35.0

func (s *Graph) SetTokenValidator(fn func(string) bool)

SetTokenValidator checks Bearer tokens with fn (such as testoauth.Server.ValidAccess) when non-nil, and clears RejectAuth.

func (*Graph) Throttle added in v1.35.0

func (s *Graph) Throttle(n, status int, retryAfter string)

Throttle makes the next n requests answer with status (429 or 503) and Retry-After header retryAfter.

func (*Graph) Token added in v1.35.0

func (s *Graph) Token() string

Token returns the valid Bearer token, or a rejected one after RejectAuth.

func (*Graph) URL added in v1.35.0

func (s *Graph) URL() string

URL is the Graph v1.0 root URL.

type GraphSent added in v1.35.0

type GraphSent struct {
	Raw []byte
}

GraphSent is a message submitted through /me/sendMail.

type IMAP

type IMAP struct {
	Addr string
	User *imapmemserver.User
	// contains filtered or unexported fields
}

IMAP is a running in-memory IMAP server with one user, alice/secret.

func StartIMAP

func StartIMAP(t testing.TB, opts ...Option) *IMAP

StartIMAP starts a server on 127.0.0.1:0 with INBOX, Sent, Trash and Archive (with Gmail, INBOX and the Gmail folders).

func (*IMAP) AddGmail added in v1.30.0

func (s *IMAP) AddGmail(raw string, flags []imap.Flag, folders ...string) *GmailMessage

AddGmail adds a new Gmail message with flags to folders, which must exist.

func (*IMAP) BlockLogin

func (s *IMAP) BlockLogin() (entered <-chan struct{}, release func())

BlockLogin is BlockLoginAfter(0).

func (*IMAP) BlockLoginAfter

func (s *IMAP) BlockLoginAfter(n int) (entered <-chan struct{}, release func())

BlockLoginAfter lets n logins (LOGIN or XOAUTH2) through and holds the next one until release is called (release may be called more than once); the held login checks its password or token only then. entered fires once it is held.

func (*IMAP) BytesSent

func (s *IMAP) BytesSent() int64

BytesSent is the total written to all client connections so far.

func (*IMAP) DropAfterGmailLabelStore added in v1.30.0

func (s *IMAP) DropAfterGmailLabelStore(n int)

DropAfterGmailLabelStore drops the response after the nth next label STORE.

func (*IMAP) DropAfterNextAppend

func (s *IMAP) DropAfterNextAppend()

DropAfterNextAppend makes the next APPEND store the message and then close the client's connection before the tagged OK.

func (*IMAP) DropAfterNextCopy added in v1.35.0

func (s *IMAP) DropAfterNextCopy()

DropAfterNextCopy makes the next COPY store the copy and then close the client's connection before the tagged OK.

func (*IMAP) DropBeforeNextCopy added in v1.35.0

func (s *IMAP) DropBeforeNextCopy()

DropBeforeNextCopy makes the next COPY close the client's connection before copying anything.

func (*IMAP) DropFetchAfter

func (s *IMAP) DropFetchAfter(n int)

DropFetchAfter lets n FETCH commands complete and drops the connection during the one after, like DropNextFetch.

func (*IMAP) DropNextFetch

func (s *IMAP) DropNextFetch()

DropNextFetch makes the next FETCH write at most one write of response and then close the client's connection.

func (*IMAP) DropOnNextUIDExpunge

func (s *IMAP) DropOnNextUIDExpunge()

DropOnNextUIDExpunge makes the next UID EXPUNGE close the client's connection without expunging anything.

func (*IMAP) GmailLabelStores added in v1.30.0

func (s *IMAP) GmailLabelStores() int64

GmailLabelStores is the number of label STORE commands handled.

func (*IMAP) IDs

func (s *IMAP) IDs() []map[string]string

IDs returns the parameters of every ID command received, in order.

func (*IMAP) Logins

func (s *IMAP) Logins() int64

Logins is how many LOGIN and AUTHENTICATE commands the server has handled.

func (*IMAP) MovesAndCopies

func (s *IMAP) MovesAndCopies() int64

MovesAndCopies is how many MOVE and COPY commands the server has handled.

func (*IMAP) RejectNextGmailSearch added in v1.30.0

func (s *IMAP) RejectNextGmailSearch()

RejectNextGmailSearch makes one identity check return NO without a result.

func (*IMAP) RejectNextGmailSelect added in v1.30.0

func (s *IMAP) RejectNextGmailSelect()

RejectNextGmailSelect makes one membership check return NO for an existing folder.

func (*IMAP) ResetUIDValidity added in v1.33.0

func (s *IMAP) ResetUIDValidity(folder string)

ResetUIDValidity makes SELECT report a new UIDVALIDITY for folder from now on, as a server that recreated it would; the messages and UIDs stay.

func (*IMAP) Restart

func (s *IMAP) Restart()

Restart listens again on the same address with the same data.

func (*IMAP) SetPassword

func (s *IMAP) SetPassword(pw string)

SetPassword changes alice's password, as a user does on the provider's website.

func (*IMAP) Stop

func (s *IMAP) Stop()

Stop closes the listener and every live connection. Data is kept.

type Inbox

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

Inbox records what the test SMTP server received.

func StartSMTP

func StartSMTP(t testing.TB, opts ...SMTPOption) (addr string, in *Inbox)

StartSMTP starts a plaintext SMTP server accepting only alice/secret (PLAIN).

func (*Inbox) AuthAttempts

func (in *Inbox) AuthAttempts() int

AuthAttempts is how many AUTH exchanges the server has handled.

func (*Inbox) BlockData

func (in *Inbox) BlockData() (entered <-chan struct{}, release func())

BlockData makes the next sessions hold their reply after reading the full DATA until release is called (release may be called more than once). entered receives once per held session.

func (*Inbox) DisableAuth added in v1.32.0

func (in *Inbox) DisableAuth(off bool)

DisableAuth makes AUTH answer what Microsoft does for a mailbox whose SMTP AUTH is disabled (535 5.7.139), whatever the credentials.

func (*Inbox) FailAfterData

func (in *Inbox) FailAfterData(n int)

FailAfterData makes the next n sessions read the full DATA and then drop the connection without replying. The server has the message, so it is recorded.

func (*Inbox) Messages

func (in *Inbox) Messages() []Received

Messages returns a copy of the received messages.

func (*Inbox) RejectAuth

func (in *Inbox) RejectAuth(reject bool)

RejectAuth makes the server refuse (or, with false, accept again) alice/secret.

func (*Inbox) Reply added in v1.14.0

func (in *Inbox) Reply(to string, at SMTPStage, resp *smtp.SMTPError, once bool)

Reply makes the server answer resp for the recipient to at stage: at its RCPT TO, or once the full DATA of a message to it is read (the message is then not recorded). With once it answers only the next time, then accepts again; otherwise every time until Reply is called again. A nil resp clears it.

func (*Inbox) SetPassword

func (in *Inbox) SetPassword(pw string)

SetPassword changes alice's password.

type JMAP added in v1.33.0

type JMAP struct {
	*jmapmemserver.Server
	Inbox gojmap.ID
	// contains filtered or unexported fields
}

JMAP is a running in-memory JMAP server with one account, alice/secret, that starts with an inbox. Its hooks (ExpireState, DropEventSources, MergeEmails, RejectNextRequest, Redirect, SeparateDownloadHost) inject faults.

func StartJMAP added in v1.33.0

func StartJMAP(t testing.TB) *JMAP

StartJMAP starts a JMAP server, closed when t ends.

func (*JMAP) Deliver added in v1.33.0

func (s *JMAP) Deliver(folder string, raw []byte) gojmap.ID

Deliver puts raw into the mailbox named folder, as mail arriving.

func (*JMAP) Mailbox added in v1.33.0

func (s *JMAP) Mailbox(name string) gojmap.ID

Mailbox is the id of the mailbox named name, created if need be; "INBOX" is the inbox.

func (*JMAP) Password added in v1.33.0

func (s *JMAP) Password() string

Password is the password a client should use: "secret", or a wrong one after RejectAuth.

func (*JMAP) RejectAuth added in v1.33.0

func (s *JMAP) RejectAuth()

RejectAuth makes Password wrong from now on, so the server refuses it.

func (*JMAP) SessionURL added in v1.33.0

func (s *JMAP) SessionURL() string

SessionURL is where the session resource is.

type Mailbox added in v1.36.0

type Mailbox struct {
	Email    string
	IMAP     *IMAP
	SMTPAddr string
	SMTP     *Inbox
}

Mailbox is one seeded account's in-memory IMAP and SMTP server pair.

func StartMailboxes added in v1.36.0

func StartMailboxes(tb testing.TB, scale Scale, seed int64, opts ...Option) []Mailbox

StartMailboxes starts scale.Accounts in-memory IMAP and SMTP servers and populates each IMAP server deterministically from seed.

type Option

type Option func(*config)

Option customises StartIMAP and StartSMTP; each option says which servers it affects.

func Gmail added in v1.30.0

func Gmail() Option

Gmail makes the IMAP server behave as Gmail: it advertises X-GM-EXT-1, starts with INBOX and the Gmail folders (special-use in LIST), and keeps messages added with AddGmail as Gmail does. One such message is in several folders, each with its own UID; flags other than \Deleted are shared; FETCH answers X-GM-MSGID and X-GM-LABELS; COPY and MOVE add the destination to its folders (with the UID it already has there, if any), and MOVE and EXPUNGE take it out of the source; a MOVE to Trash or Spam takes it out of every other folder. Identity is never derived from content: two AddGmail calls make two messages, and an APPEND makes a new one.

func RequireID

func RequireID() Option

RequireID makes the IMAP server refuse SELECT with "NO Unsafe Login" until the client has sent ID, as NetEase does.

func WithXOAuth2

func WithXOAuth2(token string) Option

WithXOAuth2 makes the IMAP and SMTP servers offer XOAUTH2 and accept token for alice.

func WithXOAuth2Func

func WithXOAuth2Func(valid func(token string) bool) Option

WithXOAuth2Func is WithXOAuth2 with a validator, such as a testoauth server's ValidAccess. The XOAUTH2 user may be alice or an alice@ address.

func WithoutCOPYUID

func WithoutCOPYUID() Option

WithoutCOPYUID keeps UIDPLUS advertised but suppresses COPYUID response codes.

func WithoutIdle

func WithoutIdle() Option

WithoutIdle removes IDLE from the advertised capabilities (the server adds it on its own, so the connection strips it from CAPABILITY lines).

func WithoutMove

func WithoutMove() Option

WithoutMove removes MOVE from the advertised capabilities.

func WithoutUIDPlus

func WithoutUIDPlus() Option

WithoutUIDPlus removes UIDPLUS and suppresses COPYUID/APPENDUID response codes (the memory backend always returns them).

type POP3 added in v1.34.0

type POP3 struct {
	Addr  string
	Roots *x509.CertPool // trusts the certificate STLS presents
	// contains filtered or unexported fields
}

POP3 is a running in-memory POP3 server with one maildrop, alice/secret. It speaks USER/PASS, STLS, STAT, LIST, UIDL, RETR, TOP, DELE, RSET, NOOP and QUIT; deletions take effect at QUIT, as RFC 1939 says.

func StartPOP3 added in v1.34.0

func StartPOP3(t testing.TB) *POP3

StartPOP3 starts a server on 127.0.0.1:0, closed when t ends.

func (*POP3) Deletes added in v1.34.0

func (s *POP3) Deletes() int

Deletes is how many DELE commands took effect at a QUIT.

func (*POP3) Deliver added in v1.34.0

func (s *POP3) Deliver(raw []byte) string

Deliver appends raw to the maildrop and returns its UIDL.

func (*POP3) DisableTOP added in v1.34.0

func (s *POP3) DisableTOP()

DisableTOP makes the server refuse TOP, which RFC 1939 leaves optional.

func (*POP3) DisableUIDL added in v1.34.0

func (s *POP3) DisableUIDL()

DisableUIDL makes the server answer UIDL with -ERR, as one without it does.

func (*POP3) FailRETR added in v1.34.0

func (s *POP3) FailRETR(n int)

FailRETR makes every RETR after the next n fail; n < 0 lets them all succeed again.

func (*POP3) Port added in v1.34.0

func (s *POP3) Port() int

Port is the port the server listens on.

func (*POP3) RejectAuth added in v1.34.0

func (s *POP3) RejectAuth()

RejectAuth makes the server refuse alice's password from now on.

func (*POP3) RejectDele added in v1.34.0

func (s *POP3) RejectDele()

RejectDele makes the server refuse DELE from now on.

func (*POP3) Remove added in v1.34.0

func (s *POP3) Remove(uid string)

Remove deletes the message uid from the maildrop, as another client would.

func (*POP3) STLS added in v1.34.0

func (s *POP3) STLS() int

STLS is how many connections the server has upgraded with STLS.

func (*POP3) UIDs added in v1.34.0

func (s *POP3) UIDs() []string

UIDs is the maildrop's UIDLs, oldest first.

type Received

type Received struct {
	From string
	To   []string
	Data []byte
}

Received is one message accepted by the test SMTP server.

type SMTPOption

type SMTPOption = Option

SMTPOption customises StartSMTP; WithXOAuth2 applies to both servers.

func LoginOnly added in v1.24.1

func LoginOnly() SMTPOption

LoginOnly makes the SMTP server offer AUTH LOGIN and not PLAIN, as Exchange does.

func SaveToSent

func SaveToSent(im *IMAP) SMTPOption

SaveToSent makes the SMTP server file every accepted message into im's Sent folder, as providers that auto-save sent mail do.

type SMTPStage added in v1.14.0

type SMTPStage int

SMTPStage is when a Reply answers.

const (
	AtRcpt SMTPStage = iota // RCPT TO
	AtData                  // the end of DATA
)

type Scale added in v1.36.0

type Scale struct {
	Name     string
	Accounts int
	Folders  int
	Messages int
}

Scale sizes a seeded benchmark fixture: Accounts mailboxes, each with Folders total folders and Messages total messages across those folders.

func Scales added in v1.36.0

func Scales() []Scale

Scales returns the three benchmark tiers in ascending order.

Jump to

Keyboard shortcuts

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