Mock transport for testing. Each mock socket is a GenServer process that stores enqueued responses and records sent data.
Low-Level API
Use enqueue/2 to enqueue raw IMAP wire-format strings:
Mock.enqueue(socket, "* OK [CAPABILITY IMAP4rev2] Server ready\r\n")High-Level API
Use struct-based helpers that handle wire encoding and tag tracking automatically:
Mock.enqueue_greeting(socket, capabilities: ["IMAP4rev2"])
Mock.enqueue_response(socket, :ok, text: "LOGIN completed")
Mock.enqueue_response(socket, :ok,
untagged: [%Mailbox.Exists{count: 10}],
text: "SELECT completed"
)Tags are auto-generated (A0001, A0002, ...) matching the Connection's tag counter. See the Testing Guide for full examples.
Summary
Functions
Returns a specification to start this module under a supervisor.
Enqueue data that will be delivered to the controlling process when active mode is set.
Enqueue a continuation response (+). Does not increment the tag counter.
Enqueue a server greeting. Does not increment the tag counter.
Enqueue a tagged response with optional untagged responses preceding it. Auto-generates the next tag (A0001, A0002, ...) atomically.
Get all data that was sent through this mock socket.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Enqueue data that will be delivered to the controlling process when active mode is set.
Enqueue a continuation response (+). Does not increment the tag counter.
Options
:text- continuation text (default:"")
Examples
Mock.enqueue_continuation(socket, text: "Ready for literal data")
Mock.enqueue_continuation(socket)
Enqueue a server greeting. Does not increment the tag counter.
Options
:capabilities- list of capability strings (e.g.,["IMAP4rev2", "IDLE"]):text- greeting text (default:"Server ready")
Examples
Mock.enqueue_greeting(socket, capabilities: ["IMAP4rev2"])
Mock.enqueue_greeting(socket, capabilities: ["IMAP4rev2", "IDLE"], text: "Ready")
Mock.enqueue_greeting(socket, text: "Server ready")
Enqueue a tagged response with optional untagged responses preceding it. Auto-generates the next tag (A0001, A0002, ...) atomically.
Options
:untagged- list of response structs to encode before the tagged response:code- response code (e.g.,%Capability{capabilities: ["IMAP4rev2"]}):text- response text (default:"")
Examples
Mock.enqueue_response(socket, :ok, text: "LOGIN completed")
Mock.enqueue_response(socket, :ok,
untagged: [
%Mailbox.Exists{count: 172},
%Mailbox.Flags{flags: [:seen, :draft]}
],
code: {:read_write, nil},
text: "SELECT completed"
)
Mock.enqueue_response(socket, :no, text: "access denied")
Get all data that was sent through this mock socket.