imap_proto/parser/rfc5256.rs
1//!
2//! https://tools.ietf.org/html/rfc5256
3//!
4//! SORT extension
5//!
6
7use nom::{
8 bytes::streaming::{tag, tag_no_case},
9 combinator::{map, opt},
10 multi::many0,
11 sequence::{preceded, terminated},
12 IResult,
13};
14
15use crate::{parser::core::number, types::MailboxDatum};
16
17/// BASE.7.2.SORT. SORT Response
18///
19/// Data: zero or more numbers
20///
21/// The SORT response occurs as a result of a SORT or UID SORT
22/// command. The number(s) refer to those messages that match the
23/// search criteria. For SORT, these are message sequence numbers;
24/// for UID SORT, these are unique identifiers. Each number is
25/// delimited by a space.
26///
27/// Example:
28///
29/// ```ignore
30/// S: * SORT 2 3 6
31/// ```
32///
33/// [RFC5256 - 4 Additional Responses](https://tools.ietf.org/html/rfc5256#section-4)
34pub(crate) fn mailbox_data_sort(i: &[u8]) -> IResult<&[u8], MailboxDatum<'_>> {
35 map(
36 // Technically, trailing whitespace is not allowed for the SEARCH command,
37 // but multiple email servers in the wild seem to have it anyway (see #34, #108).
38 // Since the SORT command extends the SEARCH command, the trailing whitespace
39 // is exceptionnaly allowed here (as for the SEARCH command).
40 terminated(
41 preceded(tag_no_case(b"SORT"), many0(preceded(tag(" "), number))),
42 opt(tag(" ")),
43 ),
44 MailboxDatum::Sort,
45 )(i)
46}