mirror of
https://github.com/soywod/himalaya.git
synced 2024-11-25 12:30:22 +00:00
add missing flags column for msgs table
This commit is contained in:
parent
1e5cce0205
commit
c9b26031e2
4 changed files with 51 additions and 9 deletions
10
CHANGELOG.md
10
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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
46
src/msg.rs
46
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<mailparse::ParsedMail<'a>> {
|
||||
Ok(mailparse::parse_mail(&self.raw)?)
|
||||
}
|
||||
|
@ -529,11 +553,18 @@ impl DisplayRow for Msg {
|
|||
fn to_row(&self) -> Vec<table::Cell> {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue