From 3703ae762ef272c051dce7a001175930a6da27d4 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 22 Jun 2020 17:25:49 +0300 Subject: [PATCH] imap: show reason for error on invalid uid fetch response --- melib/src/backends/imap/protocol_parser.rs | 29 ++++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/melib/src/backends/imap/protocol_parser.rs b/melib/src/backends/imap/protocol_parser.rs index 4e64e9abd..0edc9f0b2 100644 --- a/melib/src/backends/imap/protocol_parser.rs +++ b/melib/src/backends/imap/protocol_parser.rs @@ -661,17 +661,30 @@ pub fn uid_fetch_responses(mut input: &str) -> ImapParseResult = None; - while let Ok((rest, el, el_alert)) = uid_fetch_response(input) { - if let Some(el_alert) = el_alert { - match &mut alert { - Some(Alert(ref mut alert)) => { - alert.extend(el_alert.0.chars()); + while let next_response = uid_fetch_response(input) { + match next_response { + Ok((rest, el, el_alert)) => { + if let Some(el_alert) = el_alert { + match &mut alert { + Some(Alert(ref mut alert)) => { + alert.extend(el_alert.0.chars()); + } + a @ None => *a = Some(el_alert), + } } - a @ None => *a = Some(el_alert), + input = rest; + ret.push(el); + if !input.starts_with("* ") { + break; + } + } + Err(err) => { + return Err(MeliError::new(format!( + "Unexpected input while parsing UID FETCH responses: `{:.40}`, {}", + input, err + ))); } } - input = rest; - ret.push(el); } if !input.is_empty() && ret.is_empty() {