Module
Module documentation.
modulenet.smtp
Classes
Classes and inheritance.
classnet.smtp::Envelope
@brief`Envelope` type.
@details`Envelope` encapsulates state and operations exported by the system module. It commonly stores runtime handles, protocol state, buffers, configuration, or collection data. Its methods define the primary behavior for the type. If the type owns external resources, prefer `dispose` or `close` for deterministic release.
class Envelope {
/*
@brief `mail_from` field.classnet.smtp::FileMailbox
@brief`FileMailbox` type.
@details`FileMailbox` encapsulates state and operations exported by the system module. It commonly stores runtime handles, protocol state, buffers, configuration, or collection data. Its methods define the primary behavior for the type. If the type owns external resources, prefer `dispose` or `close` for deterministic release.
class FileMailbox {
/*
@brief `dir` field.classnet.smtp::SyncConn
@brief`SyncConn` type.
@details`SyncConn` encapsulates state and operations exported by the system module. It commonly stores runtime handles, protocol state, buffers, configuration, or collection data. Its methods define the primary behavior for the type. If the type owns external resources, prefer `dispose` or `close` for deterministic release.
class SyncConn {
/*
@brief `fd` field.Functions
Free functions and class methods.
functionnet.smtp::Envelope.init
Signature
func init(self: net.smtp.Envelope) -> Void func init(self: net.smtp.Envelope) -> Void {
self.mail_from = "";
self.recipients = new collections.Vector<String>();@briefInitializes a `Envelope` instance.
@detailsEstablishes the initial field state for `Envelope` so other methods can be called safely. Constructor logic should keep fields consistent and avoid leaking partially initialized resources.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionnet.smtp::Envelope.reset
Signature
func reset(self: net.smtp.Envelope) -> Void func reset(self: net.smtp.Envelope) -> Void {
self.mail_from = "";
_ = self.recipients.clear();@briefProvides the system library operation `Envelope.reset`.
@detailsExecutes the `reset` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionnet.smtp::Envelope.add_recipient
Signature
func add_recipient(self: net.smtp.Envelope, rcpt: String) -> Void func add_recipient(self: net.smtp.Envelope, rcpt: String) -> Void {
_ = self.recipients.push(rcpt);
}@briefProvides the system library operation `Envelope.add_recipient`.
@detailsExecutes the `add_recipient` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- rcptSMTP recipient address passed to the mail transaction.
@returnVoid
functionnet.smtp::Envelope.recipient_text
Signature
func recipient_text(self: net.smtp.Envelope) -> String func recipient_text(self: net.smtp.Envelope) -> String {
let out: String = "";
loop (let i: Int = 0; i < self.recipients.len(); i += 1) {@briefProvides the system library operation `Envelope.recipient_text`.
@detailsExecutes the `recipient_text` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnReturns the operation result as `String`.
functionnet.smtp::Envelope.deinit
Signature
func deinit(self: net.smtp.Envelope) -> Void func deinit(self: net.smtp.Envelope) -> Void {
}
}@briefReleases fallback resources at the end of the `Envelope` lifetime.
@detailsThis destructor hook is called by object lifetime management to clean up underlying resources that were not released explicitly. Normal application code should prefer `dispose`, `close`, or the module-specific close function to release resources at a deterministic time.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionnet.smtp::FileMailbox.init
Signature
func init(self: net.smtp.FileMailbox, dir: String, prefix: String = "mail") -> Void func init(self: net.smtp.FileMailbox, dir: String, prefix: String = "mail") -> Void {
self.dir = dir;
self.prefix = prefix;@briefInitializes a `FileMailbox` instance.
@detailsEstablishes the initial field state for `FileMailbox` so other methods can be called safely. Constructor logic should keep fields consistent and avoid leaking partially initialized resources.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- dirFilesystem path or file-related value used by the operation.
- prefixPrefix string matched, added, stripped, or used to build keys and paths.
@returnVoid
functionnet.smtp::FileMailbox.ensure_dir
Signature
func ensure_dir(self: net.smtp.FileMailbox) -> ErrCode func ensure_dir(self: net.smtp.FileMailbox) -> ErrCode {
let _, err = fs.mkdir_all(self.dir);
return err;@briefProvides the system library operation `FileMailbox.ensure_dir`.
@detailsExecutes the `ensure_dir` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnReturns `ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionnet.smtp::FileMailbox.next_path
Signature
func next_path(self: net.smtp.FileMailbox) -> String func next_path(self: net.smtp.FileMailbox) -> String {
self.next_id += 1;
let name: String = self.prefix + "-" + strconv.itoa(time.now_ms()) + "-" + strconv.itoa(self.next_id) + ".eml";@briefProvides the system library operation `FileMailbox.next_path`.
@detailsExecutes the `next_path` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnReturns the operation result as `String`.
functionnet.smtp::FileMailbox.store
Signature
func store(self: net.smtp.FileMailbox, env: net.smtp.Envelope) -> String, ErrCode func store(self: net.smtp.FileMailbox, env: net.smtp.Envelope) -> String, ErrCode {
let dir_err: ErrCode = self.ensure_dir();
if dir_err != std.OK {@briefProvides the system library operation `FileMailbox.store`.
@detailsExecutes the `store` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- envEnvironment variable map or process environment passed to the operation.
@returnReturns `String, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionnet.smtp::FileMailbox.deinit
Signature
func deinit(self: net.smtp.FileMailbox) -> Void func deinit(self: net.smtp.FileMailbox) -> Void {
}
}@briefReleases fallback resources at the end of the `FileMailbox` lifetime.
@detailsThis destructor hook is called by object lifetime management to clean up underlying resources that were not released explicitly. Normal application code should prefer `dispose`, `close`, or the module-specific close function to release resources at a deterministic time.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionnet.smtp::SyncConn.init
Signature
func init(self: net.smtp.SyncConn, fd: Int, timeout_ms: Int = 30000) -> Void func init(self: net.smtp.SyncConn, fd: Int, timeout_ms: Int = 30000) -> Void {
self.fd = fd;
self.timeout_ms = timeout_ms;@briefInitializes a `SyncConn` instance.
@detailsEstablishes the initial field state for `SyncConn` so other methods can be called safely. Constructor logic should keep fields consistent and avoid leaking partially initialized resources.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- fdOperating-system file descriptor or socket descriptor.
- timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnVoid
functionnet.smtp::SyncConn.send_raw
Signature
func send_raw(self: net.smtp.SyncConn, data: String) -> ErrCode func send_raw(self: net.smtp.SyncConn, data: String) -> ErrCode {
let _, err = net.tcp.send(self.fd, data, self.timeout_ms);
return err;@briefProvides the system library operation `SyncConn.send_raw`.
@detailsExecutes the `send_raw` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- dataInput or output data buffer.
@returnReturns `ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionnet.smtp::SyncConn.send_line
Signature
func send_line(self: net.smtp.SyncConn, line: String) -> ErrCode func send_line(self: net.smtp.SyncConn, line: String) -> ErrCode {
return self.send_raw(line + "\r\n");
}@briefProvides the system library operation `SyncConn.send_line`.
@detailsExecutes the `send_line` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- lineSingle input line or line-oriented buffer processed by the operation.
@returnReturns `ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionnet.smtp::SyncConn.recv_line
Signature
func recv_line(self: net.smtp.SyncConn, max_line: Int = 8192) -> String, ErrCode func recv_line(self: net.smtp.SyncConn, max_line: Int = 8192) -> String, ErrCode {
loop (; true; ) {
let nl: Int = strings.find_substr(self.buffer, "\n");@briefProvides the system library operation `SyncConn.recv_line`.
@detailsExecutes the `recv_line` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- max_lineMaximum allowed count or byte size.
@returnReturns `String, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionnet.smtp::SyncConn.close
Signature
func close(self: net.smtp.SyncConn) -> Void func close(self: net.smtp.SyncConn) -> Void {
_ = net.tcp.close(self.fd);
}@briefCloses resources and makes later operations unavailable with `SyncConn.close`.
@detailsExecutes the `close` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionnet.smtp::SyncConn.deinit
Signature
func deinit(self: net.smtp.SyncConn) -> Void func deinit(self: net.smtp.SyncConn) -> Void {
}
}@briefReleases fallback resources at the end of the `SyncConn` lifetime.
@detailsThis destructor hook is called by object lifetime management to clean up underlying resources that were not released explicitly. Normal application code should prefer `dispose`, `close`, or the module-specific close function to release resources at a deterministic time.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionnet.smtp::normalize_line
Signature
func normalize_line(line: String) -> Stringfunc normalize_line(line: String) -> String {
return strings.trim(line);
}@briefProvides the system library operation `normalize_line`.
@detailsExecutes the `normalize_line` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- lineSingle input line or line-oriented buffer processed by the operation.
@returnReturns the operation result as `String`.
functionnet.smtp::command_name
Signature
func command_name(line: String) -> Stringfunc command_name(line: String) -> String {
let t: String = normalize_line(line);
let sp: Int = strings.find_substr(t, " ");@briefProvides the system library operation `command_name`.
@detailsExecutes the `command_name` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- lineSingle input line or line-oriented buffer processed by the operation.
@returnReturns the operation result as `String`.
functionnet.smtp::command_arg
Signature
func command_arg(line: String) -> Stringfunc command_arg(line: String) -> String {
let t: String = normalize_line(line);
let sp: Int = strings.find_substr(t, " ");@briefProvides the system library operation `command_arg`.
@detailsExecutes the `command_arg` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- lineSingle input line or line-oriented buffer processed by the operation.
@returnReturns the operation result as `String`.
functionnet.smtp::strip_path_value
Signature
func strip_path_value(s: String) -> Stringfunc strip_path_value(s: String) -> String {
let out: String = strings.trim(s);
if strings.starts_with(out, "<") && strings.ends_with(out, ">") && std.len(out) >= 2 {@briefProvides the system library operation `strip_path_value`.
@detailsExecutes the `strip_path_value` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- sInput string.
@returnReturns the operation result as `String`.
functionnet.smtp::parse_mail_from
Signature
func parse_mail_from(line: String) -> Stringfunc parse_mail_from(line: String) -> String {
let arg: String = command_arg(line);
let lc: String = strings.to_lower_ascii(arg);@briefParses input data with `parse_mail_from`.
@detailsExecutes the `parse_mail_from` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- lineSingle input line or line-oriented buffer processed by the operation.
@returnReturns the operation result as `String`.
functionnet.smtp::parse_rcpt_to
Signature
func parse_rcpt_to(line: String) -> Stringfunc parse_rcpt_to(line: String) -> String {
let arg: String = command_arg(line);
let lc: String = strings.to_lower_ascii(arg);@briefParses input data with `parse_rcpt_to`.
@detailsExecutes the `parse_rcpt_to` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- lineSingle input line or line-oriented buffer processed by the operation.
@returnReturns the operation result as `String`.
functionnet.smtp::append_data_line
Signature
func append_data_line(data: String, line: String) -> Stringfunc append_data_line(data: String, line: String) -> String {
if strings.starts_with(line, "..") {
return data + std.substr(line, 1, std.len(line) - 1) + "\r\n";@briefProvides the system library operation `append_data_line`.
@detailsExecutes the `append_data_line` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- dataInput or output data buffer.
- lineSingle input line or line-oriented buffer processed by the operation.
@returnReturns the operation result as `String`.
functionnet.smtp::read_data
Signature
func read_data(conn: net.smtp.SyncConn, env: net.smtp.Envelope, max_bytes: Int) -> ErrCodefunc read_data(conn: net.smtp.SyncConn, env: net.smtp.Envelope, max_bytes: Int) -> ErrCode {
env.data = "";
let builder: std.StringBuilder = new std.StringBuilder(8192);@briefReads data with `read_data`.
@detailsExecutes the `read_data` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- connConnection object or native connection handle used for network I/O.
- envEnvironment variable map or process environment passed to the operation.
- max_bytesMaximum number of bytes to read or process in this operation.
@returnReturns `ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionnet.smtp::serve_session
Signature
func serve_session(fd: Int, mailbox: net.smtp.FileMailbox, hostname: String = "egret-smtp", timeout_ms: Int = 30000, max_message_bytes: Int = 16777216) -> Intfunc serve_session(fd: Int, mailbox: net.smtp.FileMailbox, hostname: String = "egret-smtp", timeout_ms: Int = 30000, max_message_bytes: Int = 16777216) -> Int {
let conn = new net.smtp.SyncConn(fd, timeout_ms);
let env = new net.smtp.Envelope();@briefProvides the system library operation `serve_session`.
@detailsExecutes the `serve_session` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- fdOperating-system file descriptor or socket descriptor.
- mailboxMailbox address or mailbox name used by the SMTP operation.
- hostnameHost name or address used for the network operation.
- timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
- max_message_bytesMaximum allowed count or byte size.
@returnReturns the operation result as `Int`.
Variables
Class fields (var).
varnet.smtp::Envelope.mail_from
Type
String@brief`mail_from` field.
@detailsHolds the `mail_from` value for each `Envelope` instance. The field type is `String`, and constructors and methods keep it synchronized with the object's runtime state.
var mail_from: String;
/*
@brief `recipients` field.varnet.smtp::Envelope.recipients
Type
collections.Vector<String>@brief`recipients` field.
@detailsHolds the `recipients` value for each `Envelope` instance. The field type is `collections.Vector<String>`, and constructors and methods keep it synchronized with the object's runtime state.
var recipients: collections.Vector<String>;
/*
@brief `data` field.varnet.smtp::Envelope.data
Type
String@brief`data` field.
@detailsStores the underlying data. The field type is `String`, and it is maintained by the constructors and methods of `Envelope`.
var data: String;
/*varnet.smtp::FileMailbox.dir
Type
String@brief`dir` field.
@detailsHolds the `dir` value for each `FileMailbox` instance. The field type is `String`, and constructors and methods keep it synchronized with the object's runtime state.
var dir: String;
/*
@brief `prefix` field.varnet.smtp::FileMailbox.prefix
Type
String@brief`prefix` field.
@detailsHolds the `prefix` value for each `FileMailbox` instance. The field type is `String`, and constructors and methods keep it synchronized with the object's runtime state.
var prefix: String;
/*
@brief `next_id` field.varnet.smtp::FileMailbox.next_id
Type
Int@brief`next_id` field.
@detailsHolds the `next_id` value for each `FileMailbox` instance. The field type is `Int`, and constructors and methods keep it synchronized with the object's runtime state.
var next_id: Int;
/*varnet.smtp::SyncConn.fd
Type
Int@brief`fd` field.
@detailsStores the underlying file descriptor or socket descriptor. The field type is `Int`, and it is maintained by the constructors and methods of `SyncConn`.
var fd: Int;
/*
@brief `timeout_ms` field.varnet.smtp::SyncConn.timeout_ms
Type
Int@brief`timeout_ms` field.
@detailsStores the default timeout in milliseconds. The field type is `Int`, and it is maintained by the constructors and methods of `SyncConn`.
var timeout_ms: Int;
/*
@brief `buffer` field.varnet.smtp::SyncConn.buffer
Type
String@brief`buffer` field.
@detailsHolds the `buffer` value for each `SyncConn` instance. The field type is `String`, and constructors and methods keep it synchronized with the object's runtime state.
var buffer: String;
/*