imap: interpret empty server response as BYE

This should trigger a reconnect to the IMAP server.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/473/head
Manos Pitsidianakis 2 months ago
parent 1e11c29c88
commit 1779ad5d3a
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -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 {

@ -302,12 +302,12 @@ pub enum ImapResponse {
impl TryFrom<&'_ [u8]> for ImapResponse {
type Error = Error;
fn try_from(val: &'_ [u8]) -> Result<Self> {
let val: &[u8] = val.split_rn().last().unwrap_or(val);
fn try_from(original_val: &'_ [u8]) -> Result<Self> {
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)
)));
})
}

Loading…
Cancel
Save