diff options
| author | Nic Gaffney <gaffney_nic@protonmail.com> | 2026-10-20 18:57:33 -0500 |
|---|---|---|
| committer | Nic Gaffney <gaffney_nic@protonmail.com> | 2026-10-20 18:57:33 -0500 |
| commit | ad821a3e2cfb535c62ac2041c951433b6e99db58 (patch) | |
| tree | c48f939a28be8ffe4f1ab3f291c7510dfe606ab4 /src/bin/store.zig | |
| parent | 735cb3fedd5f8adf89cfc869103e4e7992a61139 (diff) | |
| download | nvlope-ad821a3e2cfb535c62ac2041c951433b6e99db58.tar.gz | |
Spool in progress
Diffstat (limited to 'src/bin/store.zig')
| -rw-r--r-- | src/bin/store.zig | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/bin/store.zig b/src/bin/store.zig new file mode 100644 index 0000000..ad720ae --- /dev/null +++ b/src/bin/store.zig @@ -0,0 +1,57 @@ +const std = @import("std"); +const App = @import("app.zig"); +const normalizeUser = @import("util.zig").normalizeUser; + +const Self = @This(); + +maildir: std.fs.Dir, + +pub fn init(app: App) !Self { + const maildir = std.fs.openDirAbsolute(app.maildir, .{}) catch |e| switch (e) { + error.FileNotFound => blk: { // First time startup, create the maildir + try std.fs.makeDirAbsolute(app.maildir); + break :blk try std.fs.openDirAbsolute(app.maildir, .{}); + }, + else => return e, + }; + maildir.makePath("spool/queue") catch |e| switch (e) { + error.PathAlreadyExists => void, + else => return e, + }; + maildir.makePath("spool/active") catch |e| switch (e) { + error.PathAlreadyExists => void, + else => return e, + }; + maildir.makePath("spool/tmp") catch |e| switch (e) { + error.PathAlreadyExists => void, + else => return e, + }; + maildir.makePath("mailboxes") catch |e| switch (e) { + error.PathAlreadyExists => void, + else => return e, + }; + return .{ .maildir = maildir }; +} + +pub fn register(self: *Self, raw: []const u8) !void { + var buf: [64]u8 = undefined; + const user = try normalizeUser(&buf, raw); + var mailbox = try self.maildir.openDir("mailboxes", .{}); + defer mailbox.close(); + try mailbox.makeDir(user); + var userbox = try mailbox.openDir(user, .{}); + defer userbox.close(); + try userbox.makeDir("tmp"); + try userbox.makeDir("new"); + try userbox.makeDir("cur"); +} + +pub fn exists(self: Self, raw: []const u8) !bool { + const mailbox = try self.maildir.openDir("mailboxes", .{}); + defer mailbox.close(); + _ = mailbox.statFile(raw) catch |e| switch (e) { + error.FileNotFound => return false, + else => return e, + }; + return true; +} |
