Skip to content

Commit 4102cd6

Browse files
cry-incdjc
authored andcommitted
Added workaround for surgemail bug with unwanted spaces at the end of flag lists reported in #178
1 parent e5880b6 commit 4102cd6

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

imap-proto/src/parser/core.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use nom::{
22
branch::alt,
33
bytes::streaming::{escaped, tag, tag_no_case, take, take_while, take_while1},
44
character::streaming::{char, digit1, one_of},
5-
combinator::{map, map_res},
5+
combinator::{map, map_res, opt},
66
multi::{separated_list0, separated_list1},
7-
sequence::{delimited, tuple},
7+
sequence::{delimited, preceded, tuple},
88
IResult,
99
};
1010

@@ -212,7 +212,14 @@ where
212212
F: FnMut(&'a [u8]) -> IResult<&'a [u8], O, E>,
213213
E: nom::error::ParseError<&'a [u8]>,
214214
{
215-
delimited(char('('), separated_list0(char(' '), f), char(')'))
215+
delimited(
216+
char('('),
217+
separated_list0(char(' '), f),
218+
preceded(
219+
opt(char(' ')), // Surgemail sometimes sends a space before the closing bracket.
220+
char(')'),
221+
),
222+
)
216223
}
217224

218225
pub fn opt_opt<'a, F, O, E>(mut f: F) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], Option<O>, E>

imap-proto/src/parser/rfc3501/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ fn flag_list(i: &[u8]) -> IResult<&[u8], Vec<Cow<str>>> {
9393
// * FLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)
9494
//
9595
// As a workaround, "\*" is allowed here.
96+
//
97+
// Also, surgemail sends an additional space before the closing bracket:
98+
// * FLAGS (\Answered \Flagged \Deleted \Draft \Seen $Forwarded )
99+
//
100+
// As a workaround, optional spaces before the closing bracket are allowed.
96101
parenthesized_list(map(flag_perm, Cow::Borrowed))(i)
97102
}
98103

@@ -803,4 +808,22 @@ mod tests {
803808
Err(_)
804809
);
805810
}
811+
812+
#[test]
813+
fn test_surgemail_select_flags() {
814+
// Tests workaround for surgemail with space before closing bracket
815+
assert_matches!(
816+
super::flag_list(b"(\\Answered \\Flagged \\Deleted \\Draft \\Seen $Forwarded )"),
817+
Ok(([], flags)) => {
818+
assert_eq!(flags, vec![
819+
"\\Answered",
820+
"\\Flagged",
821+
"\\Deleted",
822+
"\\Draft",
823+
"\\Seen",
824+
"$Forwarded"
825+
])
826+
}
827+
);
828+
}
806829
}

0 commit comments

Comments
 (0)