diff options
Diffstat (limited to 'src/bin/app.zig')
| -rw-r--r-- | src/bin/app.zig | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/bin/app.zig b/src/bin/app.zig index 46ba178..e3b76fd 100644 --- a/src/bin/app.zig +++ b/src/bin/app.zig @@ -6,8 +6,8 @@ const Store = @import("store.zig"); pub const App = @This(); -comptime maildir: []const u8 = "./Mail", gpa: Allocator, +io: std.Io, domain: []const u8 = "localhost", sender: ?[]const u8 = null, recipients: std.ArrayList([]const u8) = .empty, @@ -25,6 +25,26 @@ const max_rcpt = 100; const max_size = 512; const max_body = 10 * 1024 * 1024; +fn acceptLocal(self: *App, raw: []const u8) !nv.Reply { + _ = self; + _ = raw; + return error.NotImplemented; +} + +pub fn queue(self: *App) void { + for (self.recipients.items) |rc| { + const at = std.mem.lastIndexOfScalar(u8, rc, '@') orelse rc.len; + const local = rc.path[0..at]; + const domain = rc.path[at + 1 ..]; + if (std.ascii.eqlIgnoreCase(domain, self.domain) and self.store.exists(self.io, local)) { + var mailbox = try self.store.maildir.openDir(self.io, local, .{}); + defer mailbox.close(self.io); + var tmp = try mailbox.openDir(self.io, "tmp"); + tmp.createFile(self.io, "MAAAIL", .{.lock}); + } + } +} + pub fn appendBodyLine(self: *App, line: []const u8) !enum { ok, too_large } { const l = if (std.mem.startsWith(u8, line, "..")) line[1..] else line; if (self.body.items.len + l.len > max_body) return .too_large; @@ -33,7 +53,7 @@ pub fn appendBodyLine(self: *App, line: []const u8) !enum { ok, too_large } { } pub fn resetTransaction(self: *App) void { - if (@intFromEnum(self.state) <= 2) self.state = .ready else self.state = .start; + if (@backingInt(self.state) <= 2) self.state = .ready else self.state = .start; if (self.sender) |s| self.gpa.free(s); self.sender = null; for (self.recipients.items) |r| self.gpa.free(r); @@ -63,7 +83,7 @@ pub fn helo(self: *App, arena: Allocator, id: nv.Identity) !nv.Reply { pub fn mail(self: *App, arena: Allocator, m: nv.MailFrom) !nv.Reply { _ = arena; - if (@intFromEnum(self.state) < 2) return nv.Reply.single(.bad_sequence, "Need EHLO before MAIL"); + if (@backingInt(self.state) < 2) return nv.Reply.single(.bad_sequence, "Need EHLO before MAIL"); var it = m.paramIterator(); while (it.next()) |p| { if (std.ascii.eqlIgnoreCase(p.key, "SIZE")) { @@ -97,10 +117,10 @@ pub fn rcpt(self: *App, arena: Allocator, r: nv.RcptTo) !nv.Reply { if (!std.ascii.eqlIgnoreCase(domain, self.domain)) return nv.Reply.single(.relay_denied, "Relay access denied"); // 554 var buf: [64]u8 = undefined; - const user = normalizeUser(&buf, local) catch - return nv.Reply.single(.mailbox_unavailable, "No such user"); // 550 - if (!self.store.exists(user)) - return nv.Reply.single(.mailbox_unavailable, "No such user"); // 550 + const user = normalizeUser(local, &buf) catch + return nv.Reply.single(.rejected, "No such user"); // 550 + if (!try self.store.exists(self.io, user)) + return nv.Reply.single(.rejected, "No such user"); // 550 const owned = try self.gpa.dupe(u8, r.path); errdefer self.gpa.free(owned); |
