From 77d9cef6fcb17940fb1ae355074e26c4792d180d Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 27 Jan 2020 15:55:01 +0200 Subject: [PATCH] melib/imap: small fixes - Ignore final line ("M__ OK ...") when parsing FETCH response. - Remove unnecessary import and reword some error messages --- melib/src/backends/imap.rs | 10 ++++++++-- melib/src/backends/imap/connection.rs | 1 - melib/src/backends/imap/protocol_parser.rs | 14 +++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/melib/src/backends/imap.rs b/melib/src/backends/imap.rs index 746cf10b..e20d9ad9 100644 --- a/melib/src/backends/imap.rs +++ b/melib/src/backends/imap.rs @@ -630,7 +630,10 @@ impl ImapType { conn.send_command(b"LIST \"\" \"*\"")?; conn.read_response(&mut res)?; debug!("out: {}", &res); - for l in res.lines().map(|l| l.trim()) { + let mut lines = res.lines(); + /* Remove "M__ OK .." line */ + lines.next_back(); + for l in lines.map(|l| l.trim()) { if let Ok(mut folder) = protocol_parser::list_folder_result(l.as_bytes()).to_full_result() { @@ -666,7 +669,10 @@ impl ImapType { conn.send_command(b"LSUB \"\" \"*\"")?; conn.read_response(&mut res)?; debug!("out: {}", &res); - for l in res.lines().map(|l| l.trim()) { + let mut lines = res.lines(); + /* Remove "M__ OK .." line */ + lines.next_back(); + for l in lines.map(|l| l.trim()) { if let Ok(subscription) = protocol_parser::list_folder_result(l.as_bytes()).to_full_result() { diff --git a/melib/src/backends/imap/connection.rs b/melib/src/backends/imap/connection.rs index c24b8295..f683ebd7 100644 --- a/melib/src/backends/imap/connection.rs +++ b/melib/src/backends/imap/connection.rs @@ -27,7 +27,6 @@ use std::io::Write; extern crate native_tls; use fnv::FnvHashSet; use native_tls::TlsConnector; -use std::borrow::Cow; use std::iter::FromIterator; use std::net::SocketAddr; use std::sync::{Arc, Mutex}; diff --git a/melib/src/backends/imap/protocol_parser.rs b/melib/src/backends/imap/protocol_parser.rs index 97f6f50e..62dc0b39 100644 --- a/melib/src/backends/imap/protocol_parser.rs +++ b/melib/src/backends/imap/protocol_parser.rs @@ -350,7 +350,7 @@ pub fn uid_fetch_response(input: &str) -> ImapParseResult> ret.uid = usize::from_str(unsafe { std::str::from_utf8_unchecked(uid) }).unwrap(); } else { return debug!(Err(MeliError::new(format!( - "217Unexpected input while parsing UID FETCH response. Got: `{:.40}`", + "Unexpected input while parsing UID FETCH response. Got: `{:.40}`", input )))); } @@ -361,7 +361,7 @@ pub fn uid_fetch_response(input: &str) -> ImapParseResult> i += (input.len() - i - rest.len()) + 1; } else { return debug!(Err(MeliError::new(format!( - "228Unexpected input while parsing UID FETCH response. Got: `{:.40}`", + "Unexpected input while parsing UID FETCH response. Got: `{:.40}`", input )))); } @@ -381,7 +381,7 @@ pub fn uid_fetch_response(input: &str) -> ImapParseResult> i += input.len() - i - rest.len(); } else { return debug!(Err(MeliError::new(format!( - "248Unexpected input while parsing UID FETCH response. Got: `{:.40}`", + "Unexpected input while parsing UID FETCH response. Got: `{:.40}`", input )))); } @@ -392,7 +392,7 @@ pub fn uid_fetch_response(input: &str) -> ImapParseResult> i += input.len() - i - rest.len(); } else { return debug!(Err(MeliError::new(format!( - "264Unexpected input while parsing UID FETCH response. Got: `{:.40}`", + "Unexpected input while parsing UID FETCH response. Got: `{:.40}`", &input[i..] )))); } @@ -408,9 +408,9 @@ pub fn uid_fetch_response(input: &str) -> ImapParseResult> } else if input.as_bytes()[struct_ptr] == b')' { if parenth_level == 0 { return debug!(Err(MeliError::new(format!( - "280Unexpected input while parsing UID FETCH response. Got: `{:.40}`", - &input[struct_ptr..] - )))); + "Unexpected input while parsing UID FETCH response. Got: `{:.40}`", + &input[struct_ptr..] + )))); } parenth_level -= 1; if parenth_level == 0 {