mirror of
https://github.com/soywod/himalaya.git
synced 2024-11-22 11:00:19 +00:00
add basic flags
This commit is contained in:
parent
10c523fd2c
commit
f8833ccd7c
2 changed files with 27 additions and 1 deletions
|
@ -116,7 +116,7 @@ impl<'a> ImapConnector<'a> {
|
|||
|
||||
let msgs = self
|
||||
.sess
|
||||
.fetch(range, "(UID ENVELOPE INTERNALDATE)")?
|
||||
.fetch(range, "(UID FLAGS ENVELOPE INTERNALDATE)")?
|
||||
.iter()
|
||||
.rev()
|
||||
.map(Msg::from)
|
||||
|
|
26
src/msg.rs
26
src/msg.rs
|
@ -196,9 +196,29 @@ impl<'a> ReadableMsg {
|
|||
|
||||
// Message
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Flag {
|
||||
Seen,
|
||||
Answered,
|
||||
Flagged,
|
||||
}
|
||||
|
||||
impl Flag {
|
||||
fn from_imap_flag(flag: &imap::types::Flag<'_>) -> Option<Self> {
|
||||
match flag {
|
||||
imap::types::Flag::Seen => Some(Self::Seen),
|
||||
imap::types::Flag::Answered => Some(Self::Answered),
|
||||
imap::types::Flag::Flagged => Some(Self::Flagged),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct Msg {
|
||||
pub uid: u32,
|
||||
pub flags: Vec<Flag>,
|
||||
pub subject: String,
|
||||
pub sender: String,
|
||||
pub date: String,
|
||||
|
@ -211,6 +231,7 @@ impl From<Vec<u8>> for Msg {
|
|||
fn from(raw: Vec<u8>) -> Self {
|
||||
Self {
|
||||
uid: 0,
|
||||
flags: vec![],
|
||||
subject: String::from(""),
|
||||
sender: String::from(""),
|
||||
date: String::from(""),
|
||||
|
@ -231,6 +252,11 @@ impl From<&imap::types::Fetch> for Msg {
|
|||
None => Self::from(fetch.body().unwrap_or_default().to_vec()),
|
||||
Some(envelope) => Self {
|
||||
uid: fetch.uid.unwrap_or_default(),
|
||||
flags: fetch
|
||||
.flags()
|
||||
.into_iter()
|
||||
.filter_map(Flag::from_imap_flag)
|
||||
.collect::<Vec<_>>(),
|
||||
subject: envelope
|
||||
.subject
|
||||
.and_then(|subj| rfc2047_decoder::decode(subj).ok())
|
||||
|
|
Loading…
Reference in a new issue