Skip to content
This repository was archived by the owner on Jul 22, 2019. It is now read-only.

Commit 4ecd2f5

Browse files
mordakdjc
authored andcommitted
Add parsing for SEARCH response returning a Vector of IDs (#19)
* Rename and shuffle for RFC compliance. Add tests.
1 parent 96f2018 commit 4ecd2f5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/parser.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,15 @@ named!(capability_data<Response>, do_parse!(
305305
(Response::Capabilities(capabilities))
306306
));
307307

308+
named!(mailbox_data_search<Response>, do_parse!(
309+
tag_s!("SEARCH") >>
310+
ids: many0!(do_parse!(
311+
tag_s!(" ") >>
312+
id: number >>
313+
(id))) >>
314+
(Response::IDs(ids))
315+
));
316+
308317
named!(mailbox_data_flags<Response>, do_parse!(
309318
tag_s!("FLAGS ") >>
310319
flags: flag_list >>
@@ -405,7 +414,8 @@ named!(mailbox_data<Response>, alt!(
405414
mailbox_data_list |
406415
mailbox_data_lsub |
407416
mailbox_data_status |
408-
mailbox_data_recent
417+
mailbox_data_recent |
418+
mailbox_data_search
409419
));
410420

411421
named!(nstring<Option<&[u8]>>, map!(
@@ -699,4 +709,21 @@ mod tests {
699709
rsp @ _ => panic!("unexpected response {:?}", rsp),
700710
}
701711
}
712+
713+
#[test]
714+
fn test_search() {
715+
match parse_response(b"* SEARCH\r\n") {
716+
IResult::Done(_, Response::IDs(ids)) => {
717+
assert!(ids.is_empty());
718+
},
719+
rsp @ _ => panic!("unexpected response {:?}", rsp),
720+
}
721+
match parse_response(b"* SEARCH 12345 67890\r\n") {
722+
IResult::Done(_, Response::IDs(ids)) => {
723+
assert_eq!(ids[0], 12345);
724+
assert_eq!(ids[1], 67890);
725+
},
726+
rsp @ _ => panic!("unexpected response {:?}", rsp),
727+
}
728+
}
702729
}

src/types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub enum Response<'a> {
2727
Expunge(u32),
2828
Fetch(u32, Vec<AttributeValue<'a>>),
2929
MailboxData(MailboxDatum<'a>),
30+
IDs(Vec<u32>),
3031
}
3132

3233
#[derive(Debug, Eq, PartialEq)]

0 commit comments

Comments
 (0)