split idle cmd into notify+watch, remove err when empty result

This commit is contained in:
Clément DOUIN
2021-05-07 16:41:51 +02:00
parent 9d40a7d30f
commit ef1a22d986
6 changed files with 143 additions and 67 deletions
+16 -3
View File
@@ -187,7 +187,12 @@ pub fn msg_matches(app: &App) -> Result<bool> {
let mut imap_conn = ImapConnector::new(&app.account)?;
let msgs = imap_conn.list_msgs(&app.mbox, &page_size, &page)?;
let msgs = Msgs::from(&msgs);
let msgs = if let Some(ref fetches) = msgs {
Msgs::from(fetches)
} else {
Msgs::new()
};
trace!("messages: {:?}", msgs);
app.output.print(msgs);
@@ -238,7 +243,11 @@ pub fn msg_matches(app: &App) -> Result<bool> {
let mut imap_conn = ImapConnector::new(&app.account)?;
let msgs = imap_conn.search_msgs(&app.mbox, &query, &page_size, &page)?;
let msgs = Msgs::from(&msgs);
let msgs = if let Some(ref fetches) = msgs {
Msgs::from(fetches)
} else {
Msgs::new()
};
trace!("messages: {:?}", msgs);
app.output.print(msgs);
@@ -637,7 +646,11 @@ pub fn msg_matches(app: &App) -> Result<bool> {
let mut imap_conn = ImapConnector::new(&app.account)?;
let msgs =
imap_conn.list_msgs(&app.mbox, &app.config.default_page_size(&app.account), &0)?;
let msgs = Msgs::from(&msgs);
let msgs = if let Some(ref fetches) = msgs {
Msgs::from(fetches)
} else {
Msgs::new()
};
app.output.print(msgs);
imap_conn.logout();
+10 -5
View File
@@ -80,7 +80,6 @@ impl<'a> Attachments {
.get_headers()
.get_first_value("content-type")
.unwrap_or_default();
if !ctype.starts_with("text") {
self.0.push(Attachment::from_part(part));
}
@@ -646,15 +645,21 @@ impl<'m> Table for Msg<'m> {
// Msgs
#[derive(Debug, Serialize)]
pub struct Msgs<'m>(pub Vec<Msg<'m>>);
pub struct Msgs<'a>(pub Vec<Msg<'a>>);
impl<'m> From<&'m imap::types::ZeroCopy<Vec<imap::types::Fetch>>> for Msgs<'m> {
fn from(fetches: &'m imap::types::ZeroCopy<Vec<imap::types::Fetch>>) -> Self {
impl<'a> From<&'a imap::types::ZeroCopy<Vec<imap::types::Fetch>>> for Msgs<'a> {
fn from(fetches: &'a imap::types::ZeroCopy<Vec<imap::types::Fetch>>) -> Self {
Self(fetches.iter().rev().map(Msg::from).collect::<Vec<_>>())
}
}
impl<'m> fmt::Display for Msgs<'m> {
impl Msgs<'_> {
pub fn new() -> Self {
Self(vec![])
}
}
impl fmt::Display for Msgs<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "\n{}", Table::render(&self.0))
}