mirror of
https://github.com/soywod/himalaya.git
synced 2024-09-21 01:11:18 +00:00
add basic flags
This commit is contained in:
parent
10c523fd2c
commit
f8833ccd7c
|
@ -116,7 +116,7 @@ impl<'a> ImapConnector<'a> {
|
||||||
|
|
||||||
let msgs = self
|
let msgs = self
|
||||||
.sess
|
.sess
|
||||||
.fetch(range, "(UID ENVELOPE INTERNALDATE)")?
|
.fetch(range, "(UID FLAGS ENVELOPE INTERNALDATE)")?
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.map(Msg::from)
|
.map(Msg::from)
|
||||||
|
|
26
src/msg.rs
26
src/msg.rs
|
@ -196,9 +196,29 @@ impl<'a> ReadableMsg {
|
||||||
|
|
||||||
// Message
|
// 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)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct Msg {
|
pub struct Msg {
|
||||||
pub uid: u32,
|
pub uid: u32,
|
||||||
|
pub flags: Vec<Flag>,
|
||||||
pub subject: String,
|
pub subject: String,
|
||||||
pub sender: String,
|
pub sender: String,
|
||||||
pub date: String,
|
pub date: String,
|
||||||
|
@ -211,6 +231,7 @@ impl From<Vec<u8>> for Msg {
|
||||||
fn from(raw: Vec<u8>) -> Self {
|
fn from(raw: Vec<u8>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
uid: 0,
|
uid: 0,
|
||||||
|
flags: vec![],
|
||||||
subject: String::from(""),
|
subject: String::from(""),
|
||||||
sender: String::from(""),
|
sender: String::from(""),
|
||||||
date: 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()),
|
None => Self::from(fetch.body().unwrap_or_default().to_vec()),
|
||||||
Some(envelope) => Self {
|
Some(envelope) => Self {
|
||||||
uid: fetch.uid.unwrap_or_default(),
|
uid: fetch.uid.unwrap_or_default(),
|
||||||
|
flags: fetch
|
||||||
|
.flags()
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(Flag::from_imap_flag)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
subject: envelope
|
subject: envelope
|
||||||
.subject
|
.subject
|
||||||
.and_then(|subj| rfc2047_decoder::decode(subj).ok())
|
.and_then(|subj| rfc2047_decoder::decode(subj).ok())
|
||||||
|
|
Loading…
Reference in a new issue