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
53
54
55
56
57
58
59
60
61
62
use imap_types::AuthMechanism;
use nom::IResult;
use crate::rfc3501::core::atom;
pub mod address;
pub mod body;
pub mod command;
pub mod core;
pub mod datetime;
pub mod envelope;
pub mod fetch_attributes;
pub mod flag;
pub mod mailbox;
pub mod response;
pub mod section;
pub mod sequence;
pub mod status_attributes;
pub fn auth_type(input: &[u8]) -> IResult<&[u8], AuthMechanism> {
let (rem, atom) = atom(input)?;
Ok((rem, AuthMechanism::from(atom)))
}
#[cfg(test)]
mod test {
use std::convert::TryFrom;
use imap_types::AuthMechanism;
use super::auth_type;
#[test]
fn test_auth_type() {
let tests = [
(b"plain ".as_ref(), AuthMechanism::Plain),
(b"pLaiN ".as_ref(), AuthMechanism::Plain),
(b"lOgiN ".as_ref(), AuthMechanism::Login),
(b"login ".as_ref(), AuthMechanism::Login),
(
b"loginX ".as_ref(),
AuthMechanism::try_from("loginX").unwrap(),
),
(
b"Xplain ".as_ref(),
AuthMechanism::try_from("Xplain").unwrap(),
),
];
for (test, expected) in tests.iter() {
let (rem, got) = auth_type(test).unwrap();
assert_eq!(*expected, got);
assert_eq!(rem, b" ");
}
}
}