283 functions · four libraries · versioned with the binary

Mail Function Reference

Compiled in by build.bat xmail (or any protocol variant, which carries xmail automatically). Scripts include <xsmtp.h> (or xpop3/ximap) and the whole family's declarations resolve.

MIME layer (xmail, 89 functions)

The common foundation of sending and receiving mail: #include <xmail.h> pulls all declarations (module headers resolve through the VFS's xrt/ subtree).

xrtMailTreeParse / TreeLimitsInit parse

Raw mail → a limits-checked message tree (depth/count/size guards against malicious nesting).

bool xrtMailTreeParse(xstrview Message, const xrtMailTreeLimits* pLimits, xrtMailNode** ppTree);

xrtMailBuilderInit / Header / Body / Multipart / Finish build

Streaming construction: headers (encoded words and address normalization included), bodies (QP/Base64 auto-chosen), multipart boundaries, one-step finish. Zero intermediate copies.

void xrtMailBuilderInit(xrtMailBuilder* pBuilder, xbuffer* pBuffer); bool xrtMailBuilderBody(xrtMailBuilder* pBuilder, xbytesview Body, xrtMailCodec Codec);

xrtMailQp / Base64 families codecs

QP and Base64 encode/decode, each with a Write flavor (into your buffer) and a returning flavor (free with xrtFree).

xrtMailAddress / Word / Date / Param / MessageId fields

Address-list cursors, encoded-word (RFC 2047) decoding, dates (RFC 5322), Content-Type/Disposition parameters and Message-IDs — all borrowed views, cursor-iterated.

SMTP client (44 functions)

xrtSmtpClientOpen / Capabilities / Auth / Close session

Connect (plaintext/STARTTLS/SSL per config), capability negotiation, SASL auth, graceful close.

xsmtpclient* xrtSmtpClientOpen(const xsmtpclientconfig* pConfig, xnetengine* pEngine, xerror* pError);

xrtSmtpClientMail / Rcpt / Data / Bdat delivery

Two-phase delivery: envelope (MAIL FROM/RCPT TO) then content (DATA or BDAT chunks); SizeLimit pre-checks capacity.

xrtSmtpSubmit one-shot

Deliver a whole letter in one step (build → envelope → content → close), reusing the session API internally.

bool xrtSmtpSubmit(const xsmtpsubmitconfig* pConfig, xnetengine* pEngine, xerror* pError);

xrtSmtpReplyLineParse / CapabilityParse parsers

Reply-line and capability-line parsing, independent of the network — offline testable.

POP3 client (48 functions)

xrtPop3ClientOpen / Stat / List / Uidl inventory

Session setup and the three inventory calls (count/size, listing, unique IDs).

xrtPop3ClientRetr / Top / RetrTree fetch

Whole-message fetch, headers-plus-N-lines, and direct message-tree fetch (through the MIME layer).

bool xrtPop3ClientRetrTree(xpop3client* pClient, uint64 uMessage, const xrtMailTreeLimits* pLimits, xrtMailNode** ppTree);

xrtPop3ClientDelete / Reset / Noop / Quit manage

Delete marks (applied at QUIT), reset, keepalive and quit.

IMAP client (102 functions)

xrtImapClientOpen / Select / Examine session

Session and mailbox selection (read-write/read-only), returning mailbox metadata (exists/recent/UIDNEXT).

xrtImapClientBeginSearch / BeginFetch / BeginStore operations

Search (sequence sets/conditions), fetch (headers/body/flags on demand), flag edits — Begin* initiates, then Next/Refresh stream the results.

xrtImapClientAppend / BeginIdle / EndIdle advanced

Archive mail, IDLE push waiting (server-initiated new-mail notices), COMPRESS sessions.

xrtImapResponseParse / DataCursor families parsers

Response and data-item parsing (flag/status/search/fetch/body), independently testable.

Shared SASL & transport

The three protocols share one SASL machine (PLAIN / XOAUTH2 / OAUTHBEARER) and one transport (TCP + optional TLS + optional compression); credentials arrive via each AuthConfig. Secrets go through env or Custom (see the config reference); TLS verification is on by default.

Construction & conventions

Ownership: client handles are library-allocated (Close disconnects / Destroy frees); parse results and replies are borrowed views — copy with the Write/Bytes families before leaving the function. Variant composition: xsmtp/xpop3/ximap carry xmail via requires; runtime probing with xsExtensionEnabled("xsmtp"). Tutorial in chapter 36.

Complete per-function signatures live in the repository's lib/{xmail,xsmtp,xpop3,ximap}/include (mirrored on Gitee); this page covers the main paths and common combinations by family.