also looking at this
feat: mailbox recovery addresses and password reset by email
#13
21 files
+1503
-10
| @@ -66,6 +66,9 @@ pub const Message = struct { | ||
| 66 | 66 | attachments: []const Attachment = &.{}, |
| 67 | 67 | /// Only drafts and the sender's private Sent copy retain Bcc headers. |
| 68 | 68 | 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, | |
| 69 | 72 | }; |
| 70 | 73 | |
| 71 | 74 | pub const SendConfig = struct { |
| @@ -273,6 +276,7 @@ pub fn buildMime(allocator: std.mem.Allocator, msg: Message, ts: i64, msgid: []c | ||
| 273 | 276 | try w.print("Message-ID: {s}\r\n", .{msgid}); |
| 274 | 277 | if (msg.in_reply_to.len > 0) try w.print("In-Reply-To: {s}\r\n", .{msg.in_reply_to}); |
| 275 | 278 | 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"); | |
| 276 | 280 | try w.writeAll("MIME-Version: 1.0\r\n"); |
| 277 | 281 | |
| 278 | 282 | const has_attachments = msg.attachments.len > 0; |
| @@ -501,6 +505,18 @@ pub fn send(allocator: std.mem.Allocator, msg: Message, cfg: SendConfig) !SendRe | ||
| 501 | 505 | return .{ .message_id = msgid, .delivered = delivered, .failed = try failed.toOwnedSlice(allocator), .sent_saved = sent_saved }; |
| 502 | 506 | } |
| 503 | 507 | |
| 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. | |
| 511 | pub 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 | ||
| 504 | 520 | // ── Tests ──────────────────────────────────────────────────────────────────── |
| 505 | 521 | |
| 506 | 522 | test "isSafeAddress rejects injection, path traversal, and malformed" { |