Documentation
¶
Overview ¶
Package testmail provides in-memory IMAP and SMTP servers for tests.
Index ¶
- Constants
- func AutodiscoverRoots() *x509.CertPool
- type Autodiscover
- func (a *Autodiscover) AnswerEWSURL(u string)
- func (a *Autodiscover) Credentialed(host string) bool
- func (a *Autodiscover) Dial(ctx context.Context, network, addr string) (net.Conn, error)
- func (a *Autodiscover) LookupSRV(_ context.Context, service, proto, name string) (string, []*net.SRV, error)
- func (a *Autodiscover) Moved(host, to string)
- func (a *Autodiscover) Net() ews.Net
- func (a *Autodiscover) RedirectAddr(host, email string)
- func (a *Autodiscover) RedirectGET(host, to string)
- func (a *Autodiscover) RedirectURL(host, to string)
- func (a *Autodiscover) SRV(domain, target string)
- func (a *Autodiscover) Serve(host string)
- func (a *Autodiscover) ServePOX(host string)
- func (a *Autodiscover) ServeSOAP(host string)
- type DKIMFixture
- type EWS
- func (s *EWS) Advance(d time.Duration)
- func (s *EWS) Affinity() []EWSAffinity
- func (s *EWS) Busy(n int, backOff time.Duration, fault bool)
- func (s *EWS) Count(name string) int
- func (s *EWS) Deliver(path string, raw []byte) string
- func (s *EWS) DeliverAt(path string, raw []byte, received time.Time) string
- func (s *EWS) DropNextChallenge()
- func (s *EWS) DropStreams()
- func (s *EWS) FailItem(id, code string)
- func (s *EWS) FailSend(code string)
- func (s *EWS) GarbleVerdict(body string)
- func (s *EWS) GatewayVerdict(status int, body string)
- func (s *EWS) Items(path string) []string
- func (s *EWS) LimitFindItem(n int)
- func (s *EWS) LoseSubscriptions()
- func (s *EWS) LoseVerdict()
- func (s *EWS) MarkAnswered(id string)
- func (s *EWS) MarkFlagged(id string, flagged bool)
- func (s *EWS) MarkRead(id string, read bool)
- func (s *EWS) MaxConcurrent() int
- func (s *EWS) OmitNewItemIds()
- func (s *EWS) Password() string
- func (s *EWS) Read(id string) bool
- func (s *EWS) Refuse(rcpt string)
- func (s *EWS) RefuseSubscribe(code string)
- func (s *EWS) RejectAuth()
- func (s *EWS) RejectNextSendAuth()
- func (s *EWS) Remove(id string)
- func (s *EWS) RemoveFolder(path string)
- func (s *EWS) RenameFolder(path, name string)
- func (s *EWS) Requests() int
- func (s *EWS) RequireExtendedProtection()
- func (s *EWS) Reset(path string)
- func (s *EWS) Sent() []EWSSent
- func (s *EWS) SetLatency(d time.Duration)
- func (s *EWS) SetVersion(major, minor int)
- func (s *EWS) StartAutodiscover() *Autodiscover
- func (s *EWS) Streams() int
- func (s *EWS) Subscriptions() int
- func (s *EWS) URL() string
- func (s *EWS) Unsent(id string) bool
- func (s *EWS) UseNTLM()
- func (s *EWS) WaitStreams(t testing.TB, n int)
- type EWSAffinity
- type EWSSent
- type GmailMessage
- type Graph
- func (s *Graph) AllowToken(tok string)
- func (s *Graph) Deliver(folder string, raw []byte) string
- func (s *Graph) DeliverAt(folder string, raw []byte, received time.Time) string
- func (s *Graph) Folder(name string) string
- func (s *Graph) HostURL() string
- func (s *Graph) MarkFlagged(immutableID string, flagged bool)
- func (s *Graph) MarkRead(immutableID string, read bool)
- func (s *Graph) MaxInFlight() int
- func (s *Graph) MessageState(immutableID string) (folderID string, read, flagged bool, categories []string, ok bool)
- func (s *Graph) MoveMessage(immutableID, dstFolder string)
- func (s *Graph) NonImmutableRequests() int
- func (s *Graph) RejectAuth()
- func (s *Graph) Remove(immutableID string)
- func (s *Graph) RenameFolder(folderID, newName string)
- func (s *Graph) Reset(folder string)
- func (s *Graph) ResetWith(folder string, status int, inner bool)
- func (s *Graph) SendURL() string
- func (s *Graph) Sent() []GraphSent
- func (s *Graph) SetAfterFolderDelta(fn func(folderName string))
- func (s *Graph) SetAfterFolderList(fn func())
- func (s *Graph) SetCategories(immutableID string, cats []string)
- func (s *Graph) SetDeltaPageSize(n int)
- func (s *Graph) SetLatency(d time.Duration)
- func (s *Graph) SetListPageSize(n int)
- func (s *Graph) SetOmitWellKnownNames(on bool)
- func (s *Graph) SetPartialFlagDeltas(on bool)
- func (s *Graph) SetTokenValidator(fn func(string) bool)
- func (s *Graph) Throttle(n, status int, retryAfter string)
- func (s *Graph) Token() string
- func (s *Graph) URL() string
- type GraphSent
- type IMAP
- func (s *IMAP) AddGmail(raw string, flags []imap.Flag, folders ...string) *GmailMessage
- func (s *IMAP) BlockLogin() (entered <-chan struct{}, release func())
- func (s *IMAP) BlockLoginAfter(n int) (entered <-chan struct{}, release func())
- func (s *IMAP) BytesSent() int64
- func (s *IMAP) DropAfterGmailLabelStore(n int)
- func (s *IMAP) DropAfterNextAppend()
- func (s *IMAP) DropAfterNextCopy()
- func (s *IMAP) DropBeforeNextCopy()
- func (s *IMAP) DropFetchAfter(n int)
- func (s *IMAP) DropNextFetch()
- func (s *IMAP) DropOnNextUIDExpunge()
- func (s *IMAP) GmailLabelStores() int64
- func (s *IMAP) IDs() []map[string]string
- func (s *IMAP) Logins() int64
- func (s *IMAP) MovesAndCopies() int64
- func (s *IMAP) RejectNextGmailSearch()
- func (s *IMAP) RejectNextGmailSelect()
- func (s *IMAP) ResetUIDValidity(folder string)
- func (s *IMAP) Restart()
- func (s *IMAP) SetPassword(pw string)
- func (s *IMAP) Stop()
- type Inbox
- func (in *Inbox) AuthAttempts() int
- func (in *Inbox) BlockData() (entered <-chan struct{}, release func())
- func (in *Inbox) DisableAuth(off bool)
- func (in *Inbox) FailAfterData(n int)
- func (in *Inbox) Messages() []Received
- func (in *Inbox) RejectAuth(reject bool)
- func (in *Inbox) Reply(to string, at SMTPStage, resp *smtp.SMTPError, once bool)
- func (in *Inbox) SetPassword(pw string)
- type JMAP
- type Option
- type POP3
- func (s *POP3) Deletes() int
- func (s *POP3) Deliver(raw []byte) string
- func (s *POP3) DisableTOP()
- func (s *POP3) DisableUIDL()
- func (s *POP3) FailRETR(n int)
- func (s *POP3) Port() int
- func (s *POP3) RejectAuth()
- func (s *POP3) RejectDele()
- func (s *POP3) Remove(uid string)
- func (s *POP3) STLS() int
- func (s *POP3) UIDs() []string
- type Received
- type SMTPOption
- type SMTPStage
Constants ¶
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.
Variables ¶
This section is empty.
Functions ¶
func AutodiscoverRoots ¶ added in v1.35.0
AutodiscoverRoots trusts the certificate every Autodiscover presents.
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
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 DKIMFixture ¶ added in v1.21.0
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) 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, 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
StartEWS starts an EWS server answering as Exchange 2019, closed when t ends.
func (*EWS) Advance ¶ added in v1.35.0
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
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) Deliver ¶ added in v1.35.0
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
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
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
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
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
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
Items is the ItemIds of the mail in the folder at path, in order.
func (*EWS) LimitFindItem ¶ added in v1.35.0
LimitFindItem makes a FindItem page hold at most n items, whatever the client asks for, as a server's throttling policy does.
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
MarkAnswered records a reply to the item id (PidTagLastVerbExecuted 102).
func (*EWS) MarkFlagged ¶ added in v1.35.0
MarkFlagged flags or unflags the item id.
func (*EWS) MaxConcurrent ¶ added in v1.35.0
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
Password is the password a client should use: "secret", or a wrong one after RejectAuth.
func (*EWS) RefuseSubscribe ¶ added in v1.35.0
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) RemoveFolder ¶ added in v1.35.0
RemoveFolder deletes the folder at path with its mail.
func (*EWS) RenameFolder ¶ added in v1.35.0
RenameFolder renames the folder at path to name; its FolderId stays.
func (*EWS) Requests ¶ added in v1.35.0
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
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) SetLatency ¶ added in v1.35.0
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
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
Streams is how many GetStreamingEvents connections have been opened.
func (*EWS) Subscriptions ¶ added in v1.35.0
Subscriptions is how many subscriptions the server holds.
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
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
StartGraph starts an in-process fake Microsoft Graph server, closed when t ends.
func (*Graph) AllowToken ¶ added in v1.35.0
AllowToken sets the accepted Bearer token and clears RejectAuth.
func (*Graph) Deliver ¶ added in v1.35.0
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
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
Folder returns the id of folder name (creating nested segments on "/" if missing). "INBOX" resolves to the Inbox folder.
func (*Graph) MarkFlagged ¶ added in v1.35.0
MarkFlagged updates a message's flag state as another client would.
func (*Graph) MarkRead ¶ added in v1.35.0
MarkRead updates a message's isRead state as another client would.
func (*Graph) MaxInFlight ¶ added in v1.35.0
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
MoveMessage moves immutableID into dstFolder on the server as another client would.
func (*Graph) NonImmutableRequests ¶ added in v1.35.0
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
Remove deletes a message on the server as another client would.
func (*Graph) RenameFolder ¶ added in v1.35.0
RenameFolder renames a folder on the server as another client would.
func (*Graph) ResetWith ¶ added in v1.35.0
ResetWith invalidates deltaLinks for folder using status (e.g. 410 or 400) and optionally nesting syncStateNotFound inside error.innerError.code.
func (*Graph) Sent ¶ added in v1.35.0
Sent returns copies of all messages submitted via /me/sendMail.
func (*Graph) SetAfterFolderDelta ¶ added in v1.35.0
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
SetCategories sets a message's categories as another client would.
func (*Graph) SetDeltaPageSize ¶ added in v1.35.0
SetDeltaPageSize limits how many entries each delta response page carries.
func (*Graph) SetLatency ¶ added in v1.35.0
SetLatency delays each request so concurrency tests can observe overlap.
func (*Graph) SetListPageSize ¶ added in v1.35.0
SetListPageSize limits how many folders/messages a non-delta page carries.
func (*Graph) SetOmitWellKnownNames ¶ added in v1.35.0
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
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
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
Throttle makes the next n requests answer with status (429 or 503) and Retry-After header retryAfter.
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 ¶
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
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 ¶
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) DropAfterGmailLabelStore ¶ added in v1.30.0
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 ¶
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
GmailLabelStores is the number of label STORE commands handled.
func (*IMAP) MovesAndCopies ¶
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
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 ¶
SetPassword changes alice's password, as a user does on the provider's website.
type Inbox ¶
type Inbox struct {
// contains filtered or unexported fields
}
Inbox records what the test SMTP server received.
func StartSMTP ¶
func StartSMTP(t *testing.T, opts ...SMTPOption) (addr string, in *Inbox)
StartSMTP starts a plaintext SMTP server accepting only alice/secret (PLAIN).
func (*Inbox) AuthAttempts ¶
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
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 ¶
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) RejectAuth ¶
RejectAuth makes the server refuse (or, with false, accept again) alice/secret.
func (*Inbox) Reply ¶ added in v1.14.0
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 ¶
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 (*JMAP) Deliver ¶ added in v1.33.0
Deliver puts raw into the mailbox named folder, as mail arriving.
func (*JMAP) Mailbox ¶ added in v1.33.0
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
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
SessionURL is where the session resource is.
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 ¶
WithXOAuth2 makes the IMAP and SMTP servers offer XOAUTH2 and accept token for alice.
func WithXOAuth2Func ¶
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 (*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
FailRETR makes every RETR after the next n fail; n < 0 lets them all succeed again.
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
Remove deletes the message uid from the maildrop, as another client would.
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.