An SMTP client and server library for Zig implementing RFC 5321.
1// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>
2// SPDX-License-Identifier: MIT
3
4//! Demo CLI for the zig-smtp library.
5//!
6//! zig-smtp send [--tls|--starttls] [--insecure] [--allow-cleartext-auth]
7//! [--chunking] [--smtputf8] [--user <u> --password <p>]
8//! [--auth-method plain|login|cram-md5]
9//! [--ret full|hdrs] [--envid <id>]
10//! [--notify never|success,failure,delay] [--orcpt <address>]
11//! [--submitter <mailbox>|<>]
12//! [--lmtp] [--binarymime] <host> <port> <from> <to>...
13//! send a message read from stdin; --tls speaks TLS from the first
14//! byte (port 465 style), --starttls upgrades after EHLO (port 587
15//! style), --insecure skips certificate verification, --user/--password
16//! authenticate with the best advertised mechanism (or the one forced
17//! by --auth-method), and --allow-cleartext-auth permits a mechanism
18//! that sends the password over an unencrypted connection; the DSN
19//! options (RFC 3461) are --ret and --envid on the message and
20//! --notify and --orcpt on every recipient; --binarymime sends the
21//! input as BODY=BINARYMIME over BDAT, byte for byte
22//! zig-smtp serve [--tls-cert <pem> --tls-key <pem> [--implicit-tls]]
23//! [--auth <user>:<pass>] [--lmtp [--fail-delivery <address>]]
24//! <port>
25//! run a debug server on 127.0.0.1 that prints received messages;
26//! --auth requires authentication with the given credentials; with a
27//! certificate and key it advertises and accepts STARTTLS, or speaks
28//! TLS from the first byte with --implicit-tls; --lmtp speaks LMTP
29//! instead of SMTP, where --fail-delivery names one recipient to
30//! report as undeliverable at the end of the message
31
32const std = @import("std");
33const Io = std.Io;
34const smtp = @import("smtp");
35
36pub fn main(init: std.process.Init) !void {
37 const arena = init.arena.allocator();
38 const io = init.io;
39 const args = try init.minimal.args.toSlice(arena);
40
41 if (args.len >= 2 and std.mem.eql(u8, args[1], "send")) {
42 var config: SendConfig = .{};
43 var rest = args[2..];
44 while (rest.len > 0 and std.mem.startsWith(u8, rest[0], "--")) {
45 if (std.mem.eql(u8, rest[0], "--tls")) {
46 config.mode = .tls;
47 } else if (std.mem.eql(u8, rest[0], "--starttls")) {
48 config.mode = .starttls;
49 } else if (std.mem.eql(u8, rest[0], "--insecure")) {
50 config.insecure = true;
51 } else if (std.mem.eql(u8, rest[0], "--allow-cleartext-auth")) {
52 config.allow_cleartext_auth = true;
53 } else if (std.mem.eql(u8, rest[0], "--chunking")) {
54 config.chunking = true;
55 } else if (std.mem.eql(u8, rest[0], "--smtputf8")) {
56 config.smtputf8 = true;
57 } else if (std.mem.eql(u8, rest[0], "--lmtp")) {
58 config.protocol = .lmtp;
59 } else if (std.mem.eql(u8, rest[0], "--binarymime")) {
60 // Binary content can only be framed by BDAT, so this is
61 // chunking plus a declaration of what the chunks hold.
62 config.body = .binary_mime;
63 config.chunking = true;
64 } else if (rest.len >= 2 and std.mem.eql(u8, rest[0], "--submitter")) {
65 // RFC 4954 §5. "<>" is the two characters that say "I do not
66 // know", which is a different claim from not asking.
67 config.submitter = if (std.mem.eql(u8, rest[1], "<>"))
68 .unknown
69 else
70 .{ .mailbox = rest[1] };
71 rest = rest[1..];
72 } else if (rest.len >= 2 and std.mem.eql(u8, rest[0], "--ret")) {
73 config.ret = smtp.protocol.Ret.parse(rest[1]) catch return usage();
74 rest = rest[1..];
75 } else if (rest.len >= 2 and std.mem.eql(u8, rest[0], "--envid")) {
76 config.envid = rest[1];
77 rest = rest[1..];
78 } else if (rest.len >= 2 and std.mem.eql(u8, rest[0], "--notify")) {
79 config.notify = smtp.protocol.Notify.parse(rest[1]) catch return usage();
80 rest = rest[1..];
81 } else if (rest.len >= 2 and std.mem.eql(u8, rest[0], "--orcpt")) {
82 // Applied to every recipient, which is all a one-shot
83 // sender can sensibly do with it.
84 config.orcpt = rest[1];
85 rest = rest[1..];
86 } else if (rest.len >= 2 and std.mem.eql(u8, rest[0], "--user")) {
87 config.username = rest[1];
88 rest = rest[1..];
89 } else if (rest.len >= 2 and std.mem.eql(u8, rest[0], "--password")) {
90 config.password = rest[1];
91 rest = rest[1..];
92 } else if (rest.len >= 2 and std.mem.eql(u8, rest[0], "--auth-method")) {
93 config.auth_method = std.meta.stringToEnum(
94 @TypeOf(config.auth_method),
95 rest[1],
96 ) orelse if (std.mem.eql(u8, rest[1], "cram-md5")) .cram_md5 else return usage();
97 rest = rest[1..];
98 } else {
99 return usage();
100 }
101 rest = rest[1..];
102 }
103 if ((config.username == null) != (config.password == null)) return usage();
104 if (rest.len < 4) return usage();
105 return send(io, arena, config, rest[0], rest[1], rest[2], rest[3..]);
106 }
107 if (args.len >= 2 and std.mem.eql(u8, args[1], "serve")) {
108 var config: ServeConfig = .{};
109 var rest = args[2..];
110 while (rest.len > 0 and std.mem.startsWith(u8, rest[0], "--")) {
111 if (rest.len >= 2 and std.mem.eql(u8, rest[0], "--tls-cert")) {
112 config.cert_path = rest[1];
113 rest = rest[1..];
114 } else if (rest.len >= 2 and std.mem.eql(u8, rest[0], "--tls-key")) {
115 config.key_path = rest[1];
116 rest = rest[1..];
117 } else if (rest.len >= 2 and std.mem.eql(u8, rest[0], "--auth")) {
118 const sep = std.mem.indexOfScalar(u8, rest[1], ':') orelse return usage();
119 config.username = rest[1][0..sep];
120 config.password = rest[1][sep + 1 ..];
121 rest = rest[1..];
122 } else if (std.mem.eql(u8, rest[0], "--implicit-tls")) {
123 config.implicit_tls = true;
124 } else if (std.mem.eql(u8, rest[0], "--lmtp")) {
125 config.protocol = .lmtp;
126 } else if (rest.len >= 2 and std.mem.eql(u8, rest[0], "--fail-delivery")) {
127 config.fail_delivery = rest[1];
128 rest = rest[1..];
129 } else {
130 return usage();
131 }
132 rest = rest[1..];
133 }
134 if (rest.len != 1) return usage();
135 if ((config.cert_path == null) != (config.key_path == null)) return usage();
136 if (config.implicit_tls and config.cert_path == null) return usage();
137 if (config.fail_delivery != null and config.protocol != .lmtp) return usage();
138 return serve(io, arena, config, rest[0]);
139 }
140 return usage();
141}
142
143const ServeConfig = struct {
144 cert_path: ?[]const u8 = null,
145 key_path: ?[]const u8 = null,
146 implicit_tls: bool = false,
147 protocol: smtp.Server.Protocol = .smtp,
148 /// Accepted at RCPT time and then failed at the end of the message,
149 /// which only LMTP can say.
150 fail_delivery: ?[]const u8 = null,
151 username: ?[]const u8 = null,
152 password: ?[]const u8 = null,
153};
154
155const SendConfig = struct {
156 mode: enum { plain, tls, starttls } = .plain,
157 insecure: bool = false,
158 allow_cleartext_auth: bool = false,
159 chunking: bool = false,
160 smtputf8: bool = false,
161 protocol: smtp.Client.Protocol = .smtp,
162 body: ?smtp.protocol.Body = null,
163 submitter: ?smtp.protocol.Submitter = null,
164 ret: ?smtp.protocol.Ret = null,
165 envid: ?[]const u8 = null,
166 notify: ?smtp.protocol.Notify = null,
167 orcpt: ?[]const u8 = null,
168 username: ?[]const u8 = null,
169 password: ?[]const u8 = null,
170 auth_method: enum { auto, plain, login, cram_md5 } = .auto,
171};
172
173fn usage() noreturn {
174 std.log.err(
175 \\usage:
176 \\ zig-smtp send [--tls|--starttls] [--insecure] [--allow-cleartext-auth]
177 \\ [--user <u> --password <p>]
178 \\ [--auth-method plain|login|cram-md5]
179 \\ [--ret full|hdrs] [--envid <id>]
180 \\ [--notify never|success,failure,delay] [--orcpt <address>]
181 \\ [--submitter <mailbox>|<>]
182 \\ [--lmtp] [--binarymime] <host> <port> <from> <to>...
183 \\ (message is read from stdin)
184 \\ zig-smtp serve [--tls-cert <pem> --tls-key <pem> [--implicit-tls]]
185 \\ [--auth <user>:<pass>] [--lmtp [--fail-delivery <address>]]
186 \\ <port>
187 , .{});
188 std.process.exit(1);
189}
190
191fn send(
192 io: Io,
193 arena: std.mem.Allocator,
194 config: SendConfig,
195 host_arg: []const u8,
196 port_arg: []const u8,
197 from: []const u8,
198 recipients: []const []const u8,
199) !void {
200 const host = try Io.net.HostName.init(host_arg);
201 const port = try std.fmt.parseInt(u16, port_arg, 10);
202
203 var stdin_buf: [4096]u8 = undefined;
204 var stdin: Io.File.Reader = .init(.stdin(), io, &stdin_buf);
205
206 const stream = try host.connect(io, port, .{ .mode = .stream });
207 defer stream.close(io);
208 // The TLS layer requires stream buffers of at least min_buffer_len.
209 const read_buf = try arena.alloc(u8, smtp.Tls.min_buffer_len);
210 const write_buf = try arena.alloc(u8, smtp.Tls.min_buffer_len);
211 var stream_reader = stream.reader(io, read_buf);
212 var stream_writer = stream.writer(io, write_buf);
213
214 const tls_options: smtp.Tls.Options = .{
215 .host = host_arg,
216 .ca = if (config.insecure) .insecure else .system,
217 };
218 var tls: smtp.Tls = undefined;
219 var tls_active = false;
220 defer if (tls_active) {
221 tls.end() catch {};
222 tls.deinit(arena);
223 };
224
225 var reply_buf: [1024]u8 = undefined;
226 var client: smtp.Client = .init(&stream_reader.interface, &stream_writer.interface, &reply_buf);
227 client.allow_cleartext_auth = config.allow_cleartext_auth;
228 // The SASL scratch is the caller's; a mechanism never allocates one for
229 // itself and nothing puts one on the stack behind your back.
230 var sasl_scratch: [smtp.Client.sasl_buffer_suggested]u8 = undefined;
231 client.sasl_buffer = &sasl_scratch;
232 client.mode = config.protocol;
233
234 if (config.mode == .tls) {
235 try tls.init(io, arena, &stream_reader.interface, &stream_writer.interface, tls_options);
236 tls_active = true;
237 client.setTransport(tls.reader(), tls.writer(), .encrypted);
238 }
239
240 _ = try client.greet();
241 var extensions = try client.hello("localhost");
242
243 if (config.mode == .starttls) {
244 try client.starttls();
245 try tls.init(io, arena, &stream_reader.interface, &stream_writer.interface, tls_options);
246 tls_active = true;
247 client.setTransport(tls.reader(), tls.writer(), .encrypted);
248 extensions = try client.hello("localhost");
249 }
250
251 if (config.username) |username| {
252 const password = config.password.?;
253 // The mechanisms come from zig-sasl; what is chosen from them is the
254 // caller's business, and this one lets --auth-method force it.
255 var plain: smtp.sasl.Plain = .init(username, password);
256 var login: smtp.sasl.Login = .init(username, password);
257 var cram_md5: smtp.sasl.CramMd5 = .init(username, password);
258 const offered: []const smtp.sasl.Client = switch (config.auth_method) {
259 // In order of preference, which `selectFromList` reads as such:
260 // PLAIN because every server implements it correctly, CRAM-MD5
261 // last because it is the oldest. On a carrier with no encryption
262 // the first two are skipped and it is the only one left.
263 .auto => &.{ plain.client(), login.client(), cram_md5.client() },
264 .plain => &.{plain.client()},
265 .login => &.{login.client()},
266 .cram_md5 => &.{cram_md5.client()},
267 };
268 const mechanism = smtp.sasl.Client.selectFromList(
269 offered,
270 extensions.auth,
271 client.security == .encrypted or client.allow_cleartext_auth,
272 ) orelse {
273 std.log.err(
274 "no usable mechanism; the server offers: {s}{s}",
275 .{
276 if (extensions.auth.len == 0) "(none)" else extensions.auth,
277 // The common case by far: everything on offer sends the
278 // password, and this connection is not encrypted.
279 if (client.security == .plaintext and !client.allow_cleartext_auth)
280 ", and this connection is not encrypted " ++
281 "(use --starttls or --tls, or --allow-cleartext-auth)"
282 else
283 "",
284 },
285 );
286 return error.NoSupportedMechanism;
287 };
288 client.authenticate(mechanism) catch |err| {
289 switch (err) {
290 error.AuthenticationFailed => {
291 const reply = client.last_reply.?;
292 std.log.err("authentication failed: {d} {s}", .{ reply.code, reply.text });
293 },
294 error.ServerNotAuthenticated => std.log.err(
295 "the server accepted the login without proving itself; " ++
296 "this is not the server it claims to be",
297 .{},
298 ),
299 error.InsecureTransport => std.log.err(
300 "refusing to send credentials over an unencrypted connection; " ++
301 "use --starttls or --tls, or pass --allow-cleartext-auth",
302 .{},
303 ),
304 else => {},
305 }
306 return err;
307 };
308 }
309
310 if (config.chunking and !extensions.chunking) {
311 std.log.err("server does not advertise CHUNKING", .{});
312 return error.ChunkingNotAdvertised;
313 }
314 if (config.smtputf8 and !extensions.smtputf8) {
315 std.log.err("server does not advertise SMTPUTF8", .{});
316 return error.SmtpUtf8NotAdvertised;
317 }
318 if (config.body == .binary_mime and !extensions.binary_mime) {
319 // RFC 3030 is absolute about this one: without the advertisement,
320 // binary must not be sent under any circumstances.
321 std.log.err("server does not advertise BINARYMIME", .{});
322 return error.BinaryMimeNotAdvertised;
323 }
324 if (config.submitter != null and extensions.auth.len == 0) {
325 // RFC 4954 §5 obliges a server to take the parameter only if it
326 // advertised AUTH; one that did not will answer 555.
327 std.log.err("server does not advertise AUTH, so it will not take AUTH=", .{});
328 return error.AuthNotAdvertised;
329 }
330 const wants_dsn = config.ret != null or config.envid != null or
331 config.notify != null or config.orcpt != null;
332 if (wants_dsn and !extensions.dsn) {
333 // A conforming server answers an unrecognized parameter with 555,
334 // so this is only a clearer way to say the same thing.
335 std.log.err("server does not advertise DSN", .{});
336 return error.DsnNotAdvertised;
337 }
338 transact(&client, config, from, recipients, &stdin.interface) catch |err| {
339 if (err == error.UnexpectedReply) {
340 const reply = client.last_reply.?;
341 std.log.err("server rejected: {d} {s}", .{ reply.code, reply.text });
342 }
343 return err;
344 };
345 try client.quit();
346 std.log.info("message sent to {d} recipient(s)", .{recipients.len});
347}
348
349/// Runs the mail transaction, streaming the message from `message` so
350/// arbitrarily large input never has to fit in memory.
351fn transact(
352 client: *smtp.Client,
353 config: SendConfig,
354 from: []const u8,
355 recipients: []const []const u8,
356 message: *Io.Reader,
357) (smtp.Client.Error || smtp.Client.ArgumentError)!void {
358 try client.mail(from, .{
359 .smtputf8 = config.smtputf8,
360 .auth = config.submitter,
361 .body = config.body,
362 .ret = config.ret,
363 .envid = config.envid,
364 });
365 for (recipients) |recipient| try client.rcpt(recipient, .{
366 .notify = config.notify,
367 .orcpt = if (config.orcpt) |address|
368 .{ .addr_type = "rfc822", .address = address }
369 else
370 null,
371 });
372 if (config.chunking) {
373 // BDAT sends the input verbatim (no line-ending normalization).
374 while (true) {
375 const chunk = message.peekGreedy(1) catch |err| switch (err) {
376 error.EndOfStream => break,
377 error.ReadFailed => return error.ReadFailed,
378 };
379 try client.bdat(chunk, false);
380 message.toss(chunk.len);
381 }
382 try client.bdat("", true);
383 } else {
384 var data_writer = try client.data();
385 while (true) {
386 const chunk = message.peekGreedy(1) catch |err| switch (err) {
387 error.EndOfStream => break,
388 error.ReadFailed => return error.ReadFailed,
389 };
390 try data_writer.interface.writeAll(chunk);
391 message.toss(chunk.len);
392 }
393 // In LMTP there is one verdict per recipient rather than one for
394 // the message, and reporting them individually is the only reason
395 // to be speaking it.
396 var verdicts = try data_writer.endResults();
397 var failed = false;
398 while (try verdicts.next()) |reply| {
399 if (config.protocol == .lmtp) {
400 std.log.info("{s}: {d} {s}", .{
401 recipients[verdicts.index - 1],
402 reply.code,
403 reply.text,
404 });
405 }
406 if (!reply.isPositiveCompletion()) failed = true;
407 }
408 // Each verdict was reported above, so the error only has to say
409 // that one of them was a refusal.
410 if (failed) return if (config.protocol == .lmtp)
411 error.RecipientRejected
412 else
413 error.UnexpectedReply;
414 }
415}
416
417fn serve(io: Io, gpa: std.mem.Allocator, config: ServeConfig, port_arg: []const u8) !void {
418 const port = try std.fmt.parseInt(u16, port_arg, 10);
419 const address: Io.net.IpAddress = .{ .ip4 = .loopback(port) };
420 var listener = try address.listen(io, .{});
421 defer listener.deinit(io);
422
423 var auth: ?smtp.tls.config.CertKeyPair = if (config.cert_path) |cert_path|
424 try .fromFilePath(gpa, io, .cwd(), cert_path, config.key_path.?)
425 else
426 null;
427 const tls_options: ?smtp.Server.TlsOptions = if (auth) |*a| .{
428 .io = io,
429 .auth = a,
430 .mode = if (config.implicit_tls) .implicit else .starttls,
431 } else null;
432 std.log.info("listening on 127.0.0.1:{d}{s}", .{
433 port,
434 if (tls_options) |t| switch (t.mode) {
435 .starttls => " with STARTTLS",
436 .implicit => " with implicit TLS",
437 } else "",
438 });
439
440 var stdout_buf: [4096]u8 = undefined;
441 var stdout: Io.File.Writer = .init(.stdout(), io, &stdout_buf);
442
443 var printer: MessagePrinter = .{
444 .out = &stdout.interface,
445 .username = config.username,
446 .password = config.password,
447 .fail_delivery = config.fail_delivery,
448 };
449 // The credential check, which PLAIN and LOGIN share, and the password
450 // lookup CRAM-MD5 needs instead. Both close over the same one account.
451 const check: smtp.sasl.Server.PasswordCheck = .{
452 .context = &printer,
453 .verify = MessagePrinter.verify,
454 };
455 const passwords: smtp.sasl.Server.PasswordLookup = .{
456 .context = &printer,
457 .lookup = MessagePrinter.lookup,
458 };
459
460 var connections: usize = 0;
461 while (true) {
462 const stream = try listener.accept(io);
463 defer stream.close(io);
464 connections += 1;
465
466 // A fresh set per connection: the mechanisms hold per-exchange state,
467 // and CRAM-MD5's challenge must not repeat between them.
468 // RFC 2195 wants a challenge that never repeats. A counter and the
469 // clock is what a real server would use, plus its hostname.
470 var challenge_buf: [128]u8 = undefined;
471 const challenge = std.fmt.bufPrint(
472 &challenge_buf,
473 "<{d}.{d}@localhost>",
474 .{ connections, Io.Clock.real.now(io).nanoseconds },
475 ) catch unreachable;
476 var sasl_scratch: [smtp.Server.sasl_buffer_suggested]u8 = undefined;
477 var plain: smtp.sasl.PlainServer = .init(check);
478 var login: smtp.sasl.LoginServer = .init(check);
479 var cram_md5: smtp.sasl.CramMd5Server = .init(challenge, passwords);
480 const mechanisms: []const smtp.sasl.Server = if (config.username == null)
481 &.{}
482 else
483 &.{ plain.server(), login.server(), cram_md5.server() };
484
485 // Sized for the TLS handshake, which runs over the raw stream.
486 const read_buf = try gpa.alloc(u8, smtp.tls.input_buffer_len);
487 defer gpa.free(read_buf);
488 const write_buf = try gpa.alloc(u8, smtp.tls.output_buffer_len);
489 defer gpa.free(write_buf);
490 var stream_reader = stream.reader(io, read_buf);
491 var stream_writer = stream.writer(io, write_buf);
492 var session: smtp.Server = .init(
493 &stream_reader.interface,
494 &stream_writer.interface,
495 .{ .context = &printer, .vtable = &.{
496 .message = MessagePrinter.onMessage,
497 .recipientResult = MessagePrinter.onRecipientResult,
498 } },
499 .{
500 .protocol = config.protocol,
501 .hostname = "localhost",
502 .tls = tls_options,
503 .auth_mechanisms = mechanisms,
504 .sasl_buffer = &sasl_scratch,
505 .require_auth = config.username != null,
506 },
507 );
508 session.run(gpa) catch |err| {
509 std.log.warn("session ended with error: {t}", .{err});
510 };
511 }
512}
513
514const MessagePrinter = struct {
515 out: *Io.Writer,
516 username: ?[]const u8 = null,
517 password: ?[]const u8 = null,
518 fail_delivery: ?[]const u8 = null,
519
520 /// What PLAIN and LOGIN ask: is this password right? The answer is the
521 /// identity to report, which for this one-account server is the username.
522 fn verify(
523 context: ?*anyopaque,
524 authzid: []const u8,
525 authcid: []const u8,
526 password: []const u8,
527 ) ?[]const u8 {
528 const printer: *MessagePrinter = @ptrCast(@alignCast(context.?));
529 // Acting as somebody else is not a thing this server does.
530 if (authzid.len != 0) return null;
531 if (!std.mem.eql(u8, authcid, printer.username.?)) return null;
532 if (!std.mem.eql(u8, password, printer.password.?)) return null;
533 return printer.username.?;
534 }
535
536 /// What CRAM-MD5 asks instead: the password itself, because it has to
537 /// compute the same HMAC the client did.
538 fn lookup(context: ?*anyopaque, username: []const u8) ?[]const u8 {
539 const printer: *MessagePrinter = @ptrCast(@alignCast(context.?));
540 if (!std.mem.eql(u8, username, printer.username.?)) return null;
541 return printer.password.?;
542 }
543
544 fn onMessage(context: ?*anyopaque, envelope: smtp.Server.Envelope, data: []const u8) smtp.Server.Decision {
545 const printer: *MessagePrinter = @ptrCast(@alignCast(context.?));
546 printer.print(envelope, data) catch
547 return .{ .reject = .{ .code = 451, .text = "4.3.0 Local error" } };
548 return .accept;
549 }
550
551 /// LMTP's per-recipient verdict. Everything was already printed by
552 /// `onMessage`; this only reports the one address `--fail-delivery`
553 /// names as undeliverable, which is the outcome SMTP has no way to
554 /// express for one recipient out of several.
555 fn onRecipientResult(
556 context: ?*anyopaque,
557 envelope: smtp.Server.Envelope,
558 index: usize,
559 ) smtp.Server.Decision {
560 const printer: *MessagePrinter = @ptrCast(@alignCast(context.?));
561 const failing = printer.fail_delivery orelse return .accept;
562 if (std.mem.eql(u8, envelope.recipients[index].address, failing))
563 return .{ .reject = .{ .code = 550, .text = "5.2.1 Mailbox disabled" } };
564 return .accept;
565 }
566
567 fn print(printer: *MessagePrinter, envelope: smtp.Server.Envelope, data: []const u8) !void {
568 try printer.out.print("--- message from <{s}> to", .{envelope.from});
569 for (envelope.recipients) |recipient| {
570 try printer.out.print(" <{s}>", .{recipient.address});
571 // DSN parameters, printed so that a session can be checked from
572 // the outside (which is what the interop test does).
573 if (recipient.notify) |notify| try printer.out.print(" NOTIFY={f}", .{notify});
574 if (recipient.orcpt) |orcpt| try printer.out.print(" ORCPT={f}", .{orcpt});
575 }
576 if (envelope.ret) |ret| try printer.out.print(" RET={f}", .{ret});
577 if (envelope.envid) |envid| try printer.out.print(" ENVID={s}", .{envid});
578 // The decoded mailbox rather than `{f}`, which would print the xtext
579 // that went over the wire.
580 if (envelope.submitter) |who| switch (who) {
581 .unknown => try printer.out.writeAll(" AUTH=<>"),
582 .mailbox => |mailbox| try printer.out.print(" AUTH={s}", .{mailbox}),
583 };
584 if (envelope.authenticated_as) |who| try printer.out.print(" (authenticated as {s})", .{who});
585 try printer.out.print(" ({d} bytes)\n{s}---\n", .{ data.len, data });
586 try printer.out.flush();
587 }
588};