summaryrefslogtreecommitdiff
path: root/src/lib/response.zig
blob: 56c327a1c1266e9548a2670b31eed8ca3e9d90e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const std = @import("std");

pub const Identity = union(enum) {
    domain: []const u8,
    addr: std.Io.net.IpAddress,
};

pub const Message = struct {
    str: []const u8,
    cmd: Command,
    client: Identity,
};

pub const Command = enum {
    EHLO,
    HELO,
    MAIL,
    RCPT,
    DATA,
    RSET,
    NOOP,
    QUIT,
    VRFY,

    pub fn fromStr(msg: []const u8) ?Command {
        var MSG: [4]u8 = undefined;
        if (msg.len != 4) return null;
        _ = std.ascii.upperString(&MSG, msg);
        if (std.mem.eql(u8, &MSG, "EHLO")) return .EHLO;
        if (std.mem.eql(u8, &MSG, "HELO")) return .HELO;
        if (std.mem.eql(u8, &MSG, "MAIL")) return .MAIL;
        if (std.mem.eql(u8, &MSG, "RCPT")) return .RCPT;
        if (std.mem.eql(u8, &MSG, "DATA")) return .DATA;
        if (std.mem.eql(u8, &MSG, "RSET")) return .RSET;
        if (std.mem.eql(u8, &MSG, "NOOP")) return .NOOP;
        if (std.mem.eql(u8, &MSG, "QUIT")) return .QUIT;
        if (std.mem.eql(u8, &MSG, "VRFY")) return .VRFY;
        return null;
    }
};

const Response = enum(u32) {
    OK = 250,
};

pub fn ehlo_rsp() Response {}