diff --git a/CHANGELOG.md b/CHANGELOG.md index dbea442..cdf4940 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - IDLE support [#29] +### Changed + +- Errors management with `error_chain` [#39] + +### Fixed + +- Missing `FLAGS` column in messages table [#40] + ## [0.2.0] - 2021-03-10 ### Added @@ -72,3 +80,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#25]: https://github.com/soywod/himalaya/issues/25 [#29]: https://github.com/soywod/himalaya/issues/29 [#32]: https://github.com/soywod/himalaya/issues/32 +[#39]: https://github.com/soywod/himalaya/issues/39 +[#40]: https://github.com/soywod/himalaya/issues/40 diff --git a/src/imap.rs b/src/imap.rs index 9745668..f6ae210 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -143,7 +143,7 @@ impl<'a> ImapConnector<'a> { let msgs = self .sess - .fetch(&range, "(UID ENVELOPE INTERNALDATE)") + .fetch(&range, "(UID FLAGS ENVELOPE INTERNALDATE)") .chain_err(|| format!("Cannot fetch range `{}`", &range))? .iter() .map(Msg::from) diff --git a/src/mbox.rs b/src/mbox.rs index 2cb894e..6ad92d5 100644 --- a/src/mbox.rs +++ b/src/mbox.rs @@ -58,6 +58,6 @@ impl<'a> DisplayTable<'a, Mbox> for Mboxes { impl fmt::Display for Mboxes { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.to_table()) + write!(f, "\n{}", self.to_table()) } } diff --git a/src/msg.rs b/src/msg.rs index 7104016..195575e 100644 --- a/src/msg.rs +++ b/src/msg.rs @@ -170,7 +170,7 @@ impl<'a> ReadableMsg { // Message -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, PartialEq)] #[serde(rename_all = "lowercase")] pub enum Flag { Seen, @@ -252,6 +252,30 @@ impl From<&imap::types::Fetch> for Msg { } impl<'a> Msg { + pub fn display_flags(&self) -> String { + let mut flags = String::new(); + + flags.push_str(if self.flags.contains(&Flag::Seen) { + " " + } else { + "✶" + }); + + flags.push_str(if self.flags.contains(&Flag::Answered) { + "↩" + } else { + " " + }); + + flags.push_str(if self.flags.contains(&Flag::Flagged) { + "!" + } else { + " " + }); + + flags + } + pub fn parse(&'a self) -> Result> { Ok(mailparse::parse_mail(&self.raw)?) } @@ -529,11 +553,18 @@ impl DisplayRow for Msg { fn to_row(&self) -> Vec { use crate::table::*; + let unseen = if self.flags.contains(&Flag::Seen) { + RESET + } else { + BOLD + }; + vec![ - Cell::new(&[RED], &self.uid.to_string()), - Cell::new(&[BLUE], &self.sender), - FlexCell::new(&[GREEN], &self.subject), - Cell::new(&[YELLOW], &self.date), + Cell::new(&[unseen.to_owned(), RED], &self.uid.to_string()), + Cell::new(&[unseen.to_owned(), WHITE], &self.display_flags()), + FlexCell::new(&[unseen.to_owned(), GREEN], &self.subject), + Cell::new(&[unseen.to_owned(), BLUE], &self.sender), + Cell::new(&[unseen.to_owned(), YELLOW], &self.date), ] } } @@ -549,8 +580,9 @@ impl<'a> DisplayTable<'a, Msg> for Msgs { vec![ Cell::new(&[BOLD, UNDERLINE, WHITE], "UID"), - Cell::new(&[BOLD, UNDERLINE, WHITE], "SENDER"), + Cell::new(&[BOLD, UNDERLINE, WHITE], "FLAGS"), FlexCell::new(&[BOLD, UNDERLINE, WHITE], "SUBJECT"), + Cell::new(&[BOLD, UNDERLINE, WHITE], "SENDER"), Cell::new(&[BOLD, UNDERLINE, WHITE], "DATE"), ] } @@ -562,6 +594,6 @@ impl<'a> DisplayTable<'a, Msg> for Msgs { impl fmt::Display for Msgs { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.to_table()) + write!(f, "\n{}", self.to_table()) } }