diff --git a/melib/src/backends/imap.rs b/melib/src/backends/imap.rs index aaad3d66..d9ff7df0 100644 --- a/melib/src/backends/imap.rs +++ b/melib/src/backends/imap.rs @@ -47,6 +47,8 @@ use std::str::FromStr; use std::sync::{Arc, Mutex}; pub type UID = usize; +pub static SUPPORTED_CAPABILITIES: &'static [&'static str] = &["IDLE"]; + #[derive(Debug, Default)] pub struct EnvelopeCache { bytes: Option, @@ -512,4 +514,14 @@ impl ImapType { } debug!(folders) } + + pub fn capabilities(&self) -> Vec { + self.connection + .lock() + .unwrap() + .capabilities + .iter() + .map(|c| String::from_utf8_lossy(c).into()) + .collect::>() + } } diff --git a/ui/src/components/mail/status.rs b/ui/src/components/mail/status.rs index 4a7a1e65..990d9b52 100644 --- a/ui/src/components/mail/status.rs +++ b/ui/src/components/mail/status.rs @@ -366,6 +366,73 @@ impl Component for AccountStatus { } self.dirty = false; let (width, height) = self.content.size(); + let a = &context.accounts[self.account_pos]; + if a.settings.account().format() == "imap" { + let backend_lck = a.backend.read().unwrap(); + + let b = (*backend_lck).as_any(); + if let Some(imap_backend) = b.downcast_ref::() { + write_string_to_grid( + "Server Capabilities:", + &mut self.content, + Color::Default, + Color::Default, + Attr::Default, + ((1, 1), (width - 1, height - 1)), + true, + ); + let mut capabilities = imap_backend.capabilities(); + let max_name_width = std::cmp::max( + "Server Capabilities:".len(), + capabilities.iter().map(String::len).max().unwrap_or(0), + ); + write_string_to_grid( + "meli support:", + &mut self.content, + Color::Default, + Color::Default, + Attr::Default, + ((max_name_width + 6, 1), (width - 1, height - 1)), + true, + ); + capabilities.sort(); + for (i, cap) in capabilities.into_iter().enumerate() { + let (width, height) = self.content.size(); + write_string_to_grid( + &cap, + &mut self.content, + Color::Default, + Color::Default, + Attr::Default, + ((1, 2 + i), (width - 1, height - 1)), + true, + ); + + let (width, height) = self.content.size(); + if melib::backends::imap::SUPPORTED_CAPABILITIES.contains(&cap.as_str()) { + write_string_to_grid( + "supported", + &mut self.content, + Color::Green, + Color::Default, + Attr::Default, + ((max_name_width + 6, 2 + i), (width - 1, height - 1)), + true, + ); + } else { + write_string_to_grid( + "not supported", + &mut self.content, + Color::Red, + Color::Default, + Attr::Default, + ((max_name_width + 6, 2 + i), (width - 1, height - 1)), + true, + ); + } + } + } + } /* self.content may have been resized with write_string_to_grid() calls above since it has * growable set */ @@ -393,7 +460,7 @@ impl Component for AccountStatus { ); context.dirty_areas.push_back(area); } - fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { + fn process_event(&mut self, event: &mut UIEvent, _context: &mut Context) -> bool { match *event { UIEvent::Resize => { self.dirty = true;