Skip to content

Commit 9a508cc

Browse files
committed
Do not ignore SELECT command errors
If NO or BAD response is returned, return an error instead of Ok(Malibox::default()).
1 parent efc6ffc commit 9a508cc

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

src/parse.rs

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,44 @@ pub(crate) async fn parse_mailbox<T: Stream<Item = io::Result<ResponseData>> + U
165165
) -> Result<Mailbox> {
166166
let mut mailbox = Mailbox::default();
167167

168-
while let Some(resp) = stream
169-
.take_while(|res| filter_sync(res, &command_tag))
170-
.next()
171-
.await
172-
{
168+
while let Some(resp) = stream.next().await {
173169
let resp = resp?;
174170
match resp.parsed() {
171+
Response::Done {
172+
tag,
173+
status,
174+
code,
175+
information,
176+
..
177+
} if tag == &command_tag => {
178+
use imap_proto::Status;
179+
match status {
180+
Status::Ok => {
181+
break;
182+
}
183+
Status::Bad => {
184+
return Err(Error::Bad(format!(
185+
"code: {:?}, info: {:?}",
186+
code, information
187+
)))
188+
}
189+
Status::No => {
190+
return Err(Error::No(format!(
191+
"code: {:?}, info: {:?}",
192+
code, information
193+
)))
194+
}
195+
_ => {
196+
return Err(Error::Io(io::Error::new(
197+
io::ErrorKind::Other,
198+
format!(
199+
"status: {:?}, code: {:?}, information: {:?}",
200+
status, code, information
201+
),
202+
)));
203+
}
204+
}
205+
}
175206
Response::Data {
176207
status,
177208
code,
@@ -618,4 +649,19 @@ mod tests {
618649
let ids: HashSet<u32> = ids.iter().cloned().collect();
619650
assert_eq!(ids, HashSet::<u32>::new());
620651
}
652+
653+
#[async_std::test]
654+
async fn parse_mailbox_does_not_exist_error() {
655+
let (send, recv) = channel::bounded(10);
656+
let responses = input_stream(&[
657+
"A0003 NO Mailbox doesn't exist: DeltaChat (0.001 + 0.140 + 0.139 secs).\r\n",
658+
]);
659+
let mut stream = async_std::stream::from_iter(responses);
660+
661+
let id = RequestId("A0003".into());
662+
let mailbox = parse_mailbox(&mut stream, send, id).await;
663+
assert!(recv.is_empty());
664+
665+
assert!(matches!(mailbox, Err(Error::No(_))));
666+
}
621667
}

0 commit comments

Comments
 (0)