use crate::common::*;
use crate::types::response::*;
use nom::IResult;
pub fn greeting(s: &[u8]) -> Option<Greeting> {
match greeting_parser(s) {
Ok((_, x)) => Some(x),
Err(_) => None,
}
}
pub(crate) fn greeting_parser(s: &[u8]) -> IResult<&[u8], Greeting> {
one_line_response_two_parts_parser::<Greeting>(s)
}
pub fn quit(s: &[u8]) -> Option<Quit> {
match quit_parser(s) {
Ok((_, x)) => Some(x),
Err(_) => None,
}
}
pub(crate) fn quit_parser(s: &[u8]) -> IResult<&[u8], Quit> {
one_line_response_two_parts_parser::<Quit>(s)
}
pub fn user(s: &[u8]) -> Option<User> {
match user_parser(s) {
Ok((_, x)) => Some(x),
Err(_) => None,
}
}
pub(crate) fn user_parser(s: &[u8]) -> IResult<&[u8], User> {
one_line_response_two_parts_parser::<User>(s)
}
pub fn pass(s: &[u8]) -> Option<Pass> {
match pass_parser(s) {
Ok((_, x)) => Some(x),
Err(_) => None,
}
}
pub(crate) fn pass_parser(s: &[u8]) -> IResult<&[u8], Pass> {
one_line_response_two_parts_parser::<Pass>(s)
}
pub fn apop(s: &[u8]) -> Option<Apop> {
match apop_parser(s) {
Ok((_, x)) => Some(x),
Err(_) => None,
}
}
pub(crate) fn apop_parser(s: &[u8]) -> IResult<&[u8], Apop> {
one_line_response_two_parts_parser::<Apop>(s)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_greeting_parser() {
assert_eq!(
greeting_parser(b"+OK POP3 server ready\r\n").unwrap().1,
Greeting {
status_indicator: StatusIndicator::OK,
information: b"POP3 server ready"
}
)
}
#[test]
fn test_greeting() {
assert_eq!(
greeting(b"+OK POP3 server ready\r\n").unwrap(),
Greeting {
status_indicator: StatusIndicator::OK,
information: b"POP3 server ready"
}
)
}
#[test]
fn test_quit() {
assert_eq!(
quit(b"+OK dewey POP3 server signing off\r\n").unwrap(),
Quit {
status_indicator: StatusIndicator::OK,
information: b"dewey POP3 server signing off"
}
)
}
#[test]
fn test_user() {
assert_eq!(
user(b"+OK successfully\r\n").unwrap(),
User {
status_indicator: StatusIndicator::OK,
information: b"successfully"
}
)
}
#[test]
fn test_pass() {
assert_eq!(
pass(b"+OK successfully\r\n").unwrap(),
Pass {
status_indicator: StatusIndicator::OK,
information: b"successfully"
}
)
}
#[test]
fn test_apop() {
assert_eq!(
apop(b"+OK maildrop has 1 message (369 octets)\r\n").unwrap(),
Apop {
status_indicator: StatusIndicator::OK,
information: b"maildrop has 1 message (369 octets)"
}
)
}
}