summaryrefslogtreecommitdiff
path: root/src/bin/app.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/app.zig')
-rw-r--r--src/bin/app.zig19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/bin/app.zig b/src/bin/app.zig
index 512c2f7..46ba178 100644
--- a/src/bin/app.zig
+++ b/src/bin/app.zig
@@ -1,10 +1,12 @@
const std = @import("std");
const nv = @import("nvlope");
const Allocator = std.mem.Allocator;
+const normalizeUser = @import("util.zig").normalizeUser;
+const Store = @import("store.zig");
pub const App = @This();
-mailbox: []const u8 = "./Mail",
+comptime maildir: []const u8 = "./Mail",
gpa: Allocator,
domain: []const u8 = "localhost",
sender: ?[]const u8 = null,
@@ -17,6 +19,7 @@ state: enum(u8) {
mail, // MAIL
rcpt, // RCPT
} = .init,
+store: *Store,
const max_rcpt = 100;
const max_size = 512;
@@ -84,9 +87,21 @@ pub fn rcpt(self: *App, arena: Allocator, r: nv.RcptTo) !nv.Reply {
return nv.Reply.single(.too_many, "Too many recipients");
var it = r.paramIterator();
- if (it.next() != null) // NOTIFY/ORCPT not supported
+ if (it.next() != null)
return nv.Reply.single(.param_unrecognized, "Unrecognized parameter");
+ const at = std.mem.lastIndexOfScalar(u8, r.path, '@') orelse
+ return self.acceptLocal(std.mem.trim(u8, r.path, " "));
+ const local = r.path[0..at];
+ const domain = r.path[at + 1 ..];
+ 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 owned = try self.gpa.dupe(u8, r.path);
errdefer self.gpa.free(owned);
try self.recipients.append(self.gpa, owned);