ui: show supported IMAP CAPABILITIES list in Status
In status page for IMAP accounts, show a list of CAPABILITIES and whether meli supports themjmap
parent
d780d81891
commit
61fa6d3d4b
|
@ -47,6 +47,8 @@ use std::str::FromStr;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
pub type UID = usize;
|
pub type UID = usize;
|
||||||
|
|
||||||
|
pub static SUPPORTED_CAPABILITIES: &'static [&'static str] = &["IDLE"];
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct EnvelopeCache {
|
pub struct EnvelopeCache {
|
||||||
bytes: Option<String>,
|
bytes: Option<String>,
|
||||||
|
@ -512,4 +514,14 @@ impl ImapType {
|
||||||
}
|
}
|
||||||
debug!(folders)
|
debug!(folders)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn capabilities(&self) -> Vec<String> {
|
||||||
|
self.connection
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.capabilities
|
||||||
|
.iter()
|
||||||
|
.map(|c| String::from_utf8_lossy(c).into())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,6 +366,73 @@ impl Component for AccountStatus {
|
||||||
}
|
}
|
||||||
self.dirty = false;
|
self.dirty = false;
|
||||||
let (width, height) = self.content.size();
|
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::<melib::backends::ImapType>() {
|
||||||
|
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
|
/* self.content may have been resized with write_string_to_grid() calls above since it has
|
||||||
* growable set */
|
* growable set */
|
||||||
|
@ -393,7 +460,7 @@ impl Component for AccountStatus {
|
||||||
);
|
);
|
||||||
context.dirty_areas.push_back(area);
|
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 {
|
match *event {
|
||||||
UIEvent::Resize => {
|
UIEvent::Resize => {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
|
|
Loading…
Reference in New Issue