diff --git a/melib/src/imap/connection.rs b/melib/src/imap/connection.rs index f63f618f..c698a29d 100644 --- a/melib/src/imap/connection.rs +++ b/melib/src/imap/connection.rs @@ -55,7 +55,7 @@ use crate::{ imap::{ protocol_parser::{ self, id_ext::id_ext_response, ImapLineSplit, ImapResponse, RequiredResponses, - SelectResponse, + ResponseCode, SelectResponse, }, Capabilities, ImapServerConf, UIDStore, }, @@ -926,6 +926,12 @@ impl ImapConnection { *self.uid_store.is_online.lock().unwrap() = (SystemTime::now(), Ok(())); match self.server_conf.protocol { + ImapProtocol::IMAP { .. } if response.trim().is_empty() => { + let r: ImapResponse = + ImapResponse::Bye(ResponseCode::Alert("Disconnected".into())); + self.stream = Err(Error::new("Offline")); + r.into() + } ImapProtocol::IMAP { .. } => { let r: ImapResponse = ImapResponse::try_from(response.as_slice())?; match r { diff --git a/melib/src/imap/protocol_parser.rs b/melib/src/imap/protocol_parser.rs index c83ef1bc..e52f50ae 100644 --- a/melib/src/imap/protocol_parser.rs +++ b/melib/src/imap/protocol_parser.rs @@ -302,12 +302,12 @@ pub enum ImapResponse { impl TryFrom<&'_ [u8]> for ImapResponse { type Error = Error; - fn try_from(val: &'_ [u8]) -> Result { - let val: &[u8] = val.split_rn().last().unwrap_or(val); + fn try_from(original_val: &'_ [u8]) -> Result { + let val: &[u8] = original_val.split_rn().last().unwrap_or(original_val); let mut val = val[val.find(b" ").ok_or_else(|| { Error::new(format!( "Expected tagged IMAP response (OK,NO,BAD, etc) but found {:?}", - val + String::from_utf8_lossy(original_val) )) })? + 1..] .trim(); @@ -317,7 +317,7 @@ impl TryFrom<&'_ [u8]> for ImapResponse { val = &val[..val.rfind(b"(").ok_or_else(|| { Error::new(format!( "Expected tagged IMAP response (OK,NO,BAD, etc) but found {:?}", - val + String::from_utf8_lossy(original_val) )) })?]; } @@ -335,7 +335,7 @@ impl TryFrom<&'_ [u8]> for ImapResponse { } else { return Err(Error::new(format!( "Expected tagged IMAP response (OK,NO,BAD, etc) but found {:?}", - val + String::from_utf8_lossy(original_val) ))); }) }