ReviewOS

also looking at this

mail-os/mail

feat: mailbox recovery addresses and password reset by email

#13
Merged chris wants to merge feat/mailbox-recovery into main
21 files +1503 -10
packages/zig/src/api/webmail_compose.zigmodified+16-0
Changes to packages/zig/src/api/webmail_compose.zig
@@ -66,6 +66,9 @@ pub const Message = struct {
6666 attachments: []const Attachment = &.{},
6767 /// Only drafts and the sender's private Sent copy retain Bcc headers.
6868 include_bcc: bool = false,
69 /// Mark a message the server wrote itself (RFC 3834), so vacation
70 /// responders and auto-forwarders do not answer it.
71 auto_submitted: bool = false,
6972};
7073
7174pub const SendConfig = struct {
@@ -273,6 +276,7 @@ pub fn buildMime(allocator: std.mem.Allocator, msg: Message, ts: i64, msgid: []c
273276 try w.print("Message-ID: {s}\r\n", .{msgid});
274277 if (msg.in_reply_to.len > 0) try w.print("In-Reply-To: {s}\r\n", .{msg.in_reply_to});
275278 if (msg.references.len > 0) try w.print("References: {s}\r\n", .{msg.references});
279 if (msg.auto_submitted) try w.writeAll("Auto-Submitted: auto-generated\r\n");
276280 try w.writeAll("MIME-Version: 1.0\r\n");
277281
278282 const has_attachments = msg.attachments.len > 0;
@@ -501,6 +505,18 @@ pub fn send(allocator: std.mem.Allocator, msg: Message, cfg: SendConfig) !SendRe
501505 return .{ .message_id = msgid, .delivered = delivered, .failed = try failed.toOwnedSlice(allocator), .sent_saved = sent_saved };
502506}
503507
508/// Deliver a message the server writes on its own behalf (password reset
509/// links and account notices): the same local-or-remote path and DKIM signing
510/// as a composed message, with no Sent copy, because no mailbox sent it.
511pub fn deliverSystem(allocator: std.mem.Allocator, msg: Message, cfg: SendConfig) !void {
512 if (msg.to.len == 0) return ComposeError.NoRecipients;
513 const ts = time_compat.timestamp();
514 const seq = nameSeq.fetchAdd(1, .monotonic);
515 const msgid = try std.fmt.allocPrint(allocator, "<{d}.{d}@{s}>", .{ ts, seq, cfg.hostname });
516 const raw = try buildMime(allocator, msg, ts, msgid);
517 for (msg.to) |recipient| try deliverOne(allocator, cfg, msg.from, recipient, raw);
518}
519
504520// ── Tests ────────────────────────────────────────────────────────────────────
505521
506522test "isSafeAddress rejects injection, path traversal, and malformed" {