summaryrefslogtreecommitdiff
path: root/src/lib/commands.zig
diff options
context:
space:
mode:
authorNic Gaffney <gaffney_nic@protonmail.com>2026-10-20 03:35:56 -0500
committerNic Gaffney <gaffney_nic@protonmail.com>2026-10-20 03:35:56 -0500
commitafac4c8c7780cc40bb41d8bae97a4ae83a79db9f (patch)
tree63b7efe0b995630002a662738013d3fcb885df29 /src/lib/commands.zig
parent73e4e4490696a7f680cc0ef5e3b6d2d8ebc9c690 (diff)
downloadnvlope-afac4c8c7780cc40bb41d8bae97a4ae83a79db9f.tar.gz
Finished minimal message impl
Diffstat (limited to 'src/lib/commands.zig')
-rw-r--r--src/lib/commands.zig64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/lib/commands.zig b/src/lib/commands.zig
new file mode 100644
index 0000000..719e93f
--- /dev/null
+++ b/src/lib/commands.zig
@@ -0,0 +1,64 @@
+const IpAddress = @import("std").Io.net.IpAddress;
+const std = @import("std");
+
+pub const Identity = union(enum) {
+ domain: []const u8,
+ addr: IpAddress,
+
+ pub fn toString(self: Identity, buf: []u8) ![]const u8 {
+ return switch (self) {
+ .domain => self.domain,
+ .addr => blk: {
+ var fw: std.Io.Writer = .fixed(buf);
+ try self.addr.format(&fw);
+ const full = fw.buffered();
+ const host: []const u8 = if (std.mem.lastIndexOfScalar(u8, full, ':')) |i| full[0..i] else full;
+ break :blk host;
+ },
+ };
+ }
+};
+
+pub const Path = struct {
+ path: []const u8,
+ params: []const u8,
+
+ pub const Param = struct { key: []const u8, value: ?[]const u8 };
+
+ pub const ParamIterator = struct {
+ it: std.mem.TokenIterator(u8, .scalar),
+
+ pub fn next(self: *ParamIterator) ?Param {
+ const tok = self.it.next() orelse return null;
+ if (std.mem.indexOfScalar(u8, tok, '=')) |i|
+ return .{ .key = tok[0..i], .value = tok[i + 1 ..] };
+ return .{ .key = tok, .value = null };
+ }
+ };
+
+ pub fn paramIterator(self: Path) ParamIterator {
+ return .{ .it = std.mem.tokenizeScalar(u8, self.params, ' ') };
+ }
+};
+
+pub const MailFrom = Path;
+pub const RcptTo = Path;
+
+pub const User = struct {
+ name: []const u8, // local part; a quoted string keeps its quotes
+ host: ?Identity, // null only for <postmaster>
+};
+
+pub const Verb = enum { ehlo, helo, mail, rcpt, data, rset, noop, quit, vrfy };
+
+pub const Command = union(Verb) {
+ ehlo: Identity,
+ helo: Identity,
+ mail: MailFrom,
+ rcpt: RcptTo,
+ data: void,
+ rset: void,
+ noop: void,
+ quit: void,
+ vrfy: []const u8,
+};