mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
move envelopes and flags to lib
refactor maildir envelopes/flags refactor notmuch envelopes
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ edition = "2021"
|
||||
imap-backend = ["imap", "imap-proto"]
|
||||
maildir-backend = ["maildir", "md5"]
|
||||
notmuch-backend = ["notmuch", "maildir-backend"]
|
||||
default = ["imap-backend", "maildir-backend", "notmuch-backend"]
|
||||
default = ["imap-backend", "maildir-backend"]
|
||||
|
||||
[dependencies]
|
||||
lettre = { version = "0.10.0-rc.6", features = ["serde"] }
|
||||
|
||||
@@ -2,3 +2,4 @@ mod process;
|
||||
|
||||
pub mod account;
|
||||
pub mod mbox;
|
||||
pub mod msg;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
use serde::Serialize;
|
||||
|
||||
use super::Flags;
|
||||
|
||||
/// Represents the message envelope. The envelope is just a message
|
||||
/// subset, and is mostly used for listings.
|
||||
#[derive(Debug, Default, Clone, Serialize)]
|
||||
pub struct Envelope {
|
||||
/// Represents the message identifier.
|
||||
pub id: String,
|
||||
/// Represents the internal message identifier.
|
||||
pub internal_id: String,
|
||||
/// Represents the message flags.
|
||||
pub flags: Flags,
|
||||
/// Represents the subject of the message.
|
||||
pub subject: String,
|
||||
/// Represents the first sender of the message.
|
||||
pub sender: String,
|
||||
/// Represents the internal date of the message.
|
||||
pub date: Option<String>,
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
use serde::Serialize;
|
||||
use std::ops;
|
||||
|
||||
use super::Envelope;
|
||||
|
||||
/// Represents the list of envelopes.
|
||||
#[derive(Debug, Default, Serialize)]
|
||||
pub struct Envelopes {
|
||||
#[serde(rename = "response")]
|
||||
pub envelopes: Vec<Envelope>,
|
||||
}
|
||||
|
||||
impl ops::Deref for Envelopes {
|
||||
type Target = Vec<Envelope>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.envelopes
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::DerefMut for Envelopes {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.envelopes
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
use serde::Serialize;
|
||||
|
||||
/// Represents the flag variants.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
||||
pub enum Flag {
|
||||
Seen,
|
||||
Answered,
|
||||
Flagged,
|
||||
Deleted,
|
||||
Draft,
|
||||
Recent,
|
||||
Custom(String),
|
||||
}
|
||||
|
||||
impl From<&str> for Flag {
|
||||
fn from(flag_str: &str) -> Self {
|
||||
match flag_str {
|
||||
"seen" => Flag::Seen,
|
||||
"answered" | "replied" => Flag::Answered,
|
||||
"flagged" => Flag::Flagged,
|
||||
"deleted" | "trashed" => Flag::Deleted,
|
||||
"draft" => Flag::Draft,
|
||||
"recent" => Flag::Recent,
|
||||
flag => Flag::Custom(flag.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
use std::{fmt, ops};
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use super::Flag;
|
||||
|
||||
/// Represents the list of flags.
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize)]
|
||||
pub struct Flags(pub Vec<Flag>);
|
||||
|
||||
impl Flags {
|
||||
/// Builds a symbols string.
|
||||
pub fn to_symbols_string(&self) -> String {
|
||||
let mut flags = String::new();
|
||||
flags.push_str(if self.contains(&Flag::Seen) {
|
||||
" "
|
||||
} else {
|
||||
"✷"
|
||||
});
|
||||
flags.push_str(if self.contains(&Flag::Answered) {
|
||||
"↵"
|
||||
} else {
|
||||
" "
|
||||
});
|
||||
flags.push_str(if self.contains(&Flag::Flagged) {
|
||||
"⚑"
|
||||
} else {
|
||||
" "
|
||||
});
|
||||
flags
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::Deref for Flags {
|
||||
type Target = Vec<Flag>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::DerefMut for Flags {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Flags {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut glue = "";
|
||||
|
||||
for flag in &self.0 {
|
||||
write!(f, "{}", glue)?;
|
||||
match flag {
|
||||
Flag::Seen => write!(f, "\\Seen")?,
|
||||
Flag::Answered => write!(f, "\\Answered")?,
|
||||
Flag::Flagged => write!(f, "\\Flagged")?,
|
||||
Flag::Deleted => write!(f, "\\Deleted")?,
|
||||
Flag::Draft => write!(f, "\\Draft")?,
|
||||
Flag::Recent => write!(f, "\\Recent")?,
|
||||
Flag::Custom(flag) => write!(f, "{}", flag)?,
|
||||
}
|
||||
glue = " ";
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for Flags {
|
||||
fn from(flags: &str) -> Self {
|
||||
Flags(
|
||||
flags
|
||||
.split_whitespace()
|
||||
.map(|flag| flag.trim().into())
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromIterator<Flag> for Flags {
|
||||
fn from_iter<T: IntoIterator<Item = Flag>>(iter: T) -> Self {
|
||||
let mut flags = Flags::default();
|
||||
for flag in iter {
|
||||
flags.push(flag);
|
||||
}
|
||||
flags
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
mod flag;
|
||||
pub use flag::*;
|
||||
|
||||
mod flags;
|
||||
pub use flags::*;
|
||||
|
||||
mod envelope;
|
||||
pub use envelope::*;
|
||||
|
||||
mod envelopes;
|
||||
pub use envelopes::*;
|
||||
Reference in New Issue
Block a user