//!
//! https://tools.ietf.org/html/rfc5161
//!
//! The IMAP ENABLE Extension
//!

// rustfmt doesn't do a very good job on nom parser invocations.
#![cfg_attr(rustfmt, rustfmt_skip)]

use crate::types::*;
use crate::parser::core::atom;

// The ENABLED response lists capabilities that were enabled in response
// to a ENABLE command.
// [RFC5161 - 3.2 The ENABLED Response](https://tools.ietf.org/html/rfc5161#section-3.2)
named!(pub (crate) resp_enabled<Response>, map!(
    enabled_data,
    Response::Capabilities
));

named!(enabled_data<Vec<Capability>>, do_parse!(
        tag_no_case!("ENABLED") >>
        capabilities: many0!(preceded!(char!(' '), capability)) >>
        (capabilities)
));

named!(capability<Capability>,
       map!(atom, Capability::Atom)
);

//!
//! https://tools.ietf.org/html/rfc5161
//!
//! The IMAP ENABLE Extension
//!

use nom::{
    bytes::streaming::tag_no_case,
    character::streaming::char,
    combinator::map,
    multi::many0,
    sequence::{preceded, tuple},
    IResult,
};

use crate::parser::core::atom;
use crate::types::*;

// The ENABLED response lists capabilities that were enabled in response
// to a ENABLE command.
// [RFC5161 - 3.2 The ENABLED Response](https://tools.ietf.org/html/rfc5161#section-3.2)
pub(crate) fn resp_enabled(i: &[u8]) -> IResult<&[u8], Response> {
    map(enabled_data, Response::Capabilities)(i)
}

fn enabled_data(i: &[u8]) -> IResult<&[u8], Vec<Capability>> {
    let (i, (_, capabilities)) = tuple((
        tag_no_case("ENABLED"),
        many0(preceded(char(' '), capability)),
    ))(i)?;
    Ok((i, capabilities))
}

fn capability(i: &[u8]) -> IResult<&[u8], Capability> {
    map(atom, Capability::Atom)(i)
}

Rewrite RFC 5161 parser with function parsers
Rewrite RFC 5161 parser with function parsers
