Documentation
¶
Overview ¶
Package testmail provides in-memory IMAP and SMTP servers for tests.
Index ¶
- type IMAP
- 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) DropAfterNextAppend()
- func (s *IMAP) DropFetchAfter(n int)
- func (s *IMAP) DropNextFetch()
- func (s *IMAP) DropOnNextUIDExpunge()
- func (s *IMAP) IDs() []map[string]string
- func (s *IMAP) Logins() int64
- func (s *IMAP) MovesAndCopies() int64
- func (s *IMAP) Restart()
- func (s *IMAP) SetPassword(pw string)
- func (s *IMAP) Stop()
- type Inbox
- type Option
- type Received
- type SMTPOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 (*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) 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) 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) MovesAndCopies ¶
MovesAndCopies is how many MOVE and COPY commands the server has handled.
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) 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) SetPassword ¶
SetPassword changes alice's password.
type Option ¶
type Option func(*config)
Option customises StartIMAP and StartSMTP; each option says which servers it affects.
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 SMTPOption ¶
type SMTPOption = Option
SMTPOption customises StartSMTP; WithXOAuth2 applies to both servers.
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.