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
47
48
49
50
51
52
use std::str::FromStr;

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum FilterPhase {
    Connect,
    Helo,
    Ehlo,
    StartTls,
    Auth,
    MailFrom,
    RcptTo,
    Data,
    DataLine,
    Commit,
}

impl ToString for FilterPhase {
    fn to_string(&self) -> String {
        match self {
            FilterPhase::Connect => String::from("connect"),
            FilterPhase::Helo => String::from("helo"),
            FilterPhase::Ehlo => String::from("ehlo"),
            FilterPhase::StartTls => String::from("starttls"),
            FilterPhase::Auth => String::from("auth"),
            FilterPhase::MailFrom => String::from("mail-from"),
            FilterPhase::RcptTo => String::from("rcpt-to"),
            FilterPhase::Data => String::from("data"),
            FilterPhase::DataLine => String::from("data-line"),
            FilterPhase::Commit => String::from("commit"),
        }
    }
}

impl FromStr for FilterPhase {
    type Err = ();

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "connect" => Ok(FilterPhase::Connect),
            "helo" => Ok(FilterPhase::Helo),
            "ehlo" => Ok(FilterPhase::Ehlo),
            "starttls" => Ok(FilterPhase::StartTls),
            "auth" => Ok(FilterPhase::Auth),
            "mail-from" => Ok(FilterPhase::MailFrom),
            "rcpt-to" => Ok(FilterPhase::RcptTo),
            "data" => Ok(FilterPhase::Data),
            "data-line" => Ok(FilterPhase::DataLine),
            "commit" => Ok(FilterPhase::Commit),
            _ => Err(()),
        }
    }
}