imap_proto/parser/
rfc5161.rs

1//!
2//! https://tools.ietf.org/html/rfc5161
3//!
4//! The IMAP ENABLE Extension
5//!
6
7use nom::{
8    bytes::streaming::tag_no_case,
9    character::streaming::char,
10    combinator::map,
11    multi::many0,
12    sequence::{preceded, tuple},
13    IResult,
14};
15use std::borrow::Cow;
16
17use crate::parser::core::atom;
18use crate::types::*;
19
20// The ENABLED response lists capabilities that were enabled in response
21// to a ENABLE command.
22// [RFC5161 - 3.2 The ENABLED Response](https://tools.ietf.org/html/rfc5161#section-3.2)
23pub(crate) fn resp_enabled(i: &[u8]) -> IResult<&[u8], Response<'_>> {
24    map(enabled_data, Response::Capabilities)(i)
25}
26
27fn enabled_data(i: &[u8]) -> IResult<&[u8], Vec<Capability<'_>>> {
28    let (i, (_, capabilities)) = tuple((
29        tag_no_case("ENABLED"),
30        many0(preceded(char(' '), capability)),
31    ))(i)?;
32    Ok((i, capabilities))
33}
34
35fn capability(i: &[u8]) -> IResult<&[u8], Capability<'_>> {
36    map(map(atom, Cow::Borrowed), Capability::Atom)(i)
37}