diff options
Diffstat (limited to 'src/bin/main.zig')
| -rw-r--r-- | src/bin/main.zig | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/bin/main.zig b/src/bin/main.zig index 1a9243b..db41f36 100644 --- a/src/bin/main.zig +++ b/src/bin/main.zig @@ -63,11 +63,21 @@ fn session(alloc: std.mem.Allocator, io: Io, stream: *Io.net.Stream) !void { var writer = stream.writer(io, &wbuf); const w = &writer.interface; + var tmp: [255]u8 = undefined; + var buf: [255]u8 = undefined; + var fbuf: [255]u8 = undefined; + const id = nv.Identity{ .addr = stream.socket.address }; + const who = try id.toString(&tmp); + const n = @min(who.len, buf.len); + for (who[0..n], buf[0..n]) |c, *o| o.* = if (c > 0x20 and c < 0x7f) c else '?'; + var fw: std.Io.Writer = .fixed(&fbuf); + try util.literal(&fw, who); + // Per-connection state var arena: std.heap.ArenaAllocator = .init(alloc); defer arena.deinit(); var store: Store = try .init(io, MAILDIR); - var app: App = .{ .gpa = alloc, .store = &store, .io = io }; + var app: App = .{ .gpa = alloc, .store = &store, .io = io, .peer = fw.buffered() }; // Greeting: the server speaks first try nv.Reply.single(.ready, "nvlope ready").send(w); @@ -90,7 +100,11 @@ fn session(alloc: std.mem.Allocator, io: Io, stream: *Io.net.Stream) !void { if (in_data) { if (std.mem.eql(u8, line, ".\r\n")) { in_data = false; - app.queue(); + app.queue() catch { + try nv.Reply.single(.storage_error, "Internal storage error").send(w); + try w.flush(); + continue; + }; try nv.Reply.single(.ok, "Queued").send(w); try w.flush(); std.debug.print("App {{\n\t body: {s}\n\tsender: {s}\n\trecipients: {any}\n}}\n", .{ app.body.items, app.sender.?, app.recipients.items }); |
