Skip to main content

rspamd_client/protocol/
commands.rs

1//! Commands that can be sent to the server
2
3/// Commands that can be sent to the server
4pub enum RspamdCommand {
5    Scan,
6    Learnspam,
7    Learnham,
8    FuzzyAdd,
9    FuzzyDel,
10}
11
12/// Ephemeral endpoint representation
13pub struct RspamdEndpoint<'a> {
14    pub url: &'a str,
15    pub command: RspamdCommand,
16    pub need_body: bool,
17}
18
19/// Represents a request to the Rspamd server
20impl<'a> RspamdEndpoint<'a> {
21    /// Create a new endpoint from a command
22    pub fn from_command(command: RspamdCommand) -> RspamdEndpoint<'a> {
23        match command {
24            RspamdCommand::Scan => Self {
25                url: "/checkv2",
26                command,
27                need_body: true,
28            },
29            RspamdCommand::Learnspam => Self {
30                url: "/learnspam",
31                command,
32                need_body: true,
33            },
34            RspamdCommand::Learnham => Self {
35                url: "/learnham",
36                command,
37                need_body: true,
38            },
39            RspamdCommand::FuzzyAdd => Self {
40                url: "/fuzzyadd",
41                command,
42                need_body: true,
43            },
44            RspamdCommand::FuzzyDel => Self {
45                url: "/fuzzydel",
46                command,
47                need_body: true,
48            },
49        }
50    }
51}