mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-18 22:17:54 +08:00
158bc86cfa
* make use of mailparse::MailAddr * move addr logic to a dedicated file * update changelog * add suffix to downoalded attachments with same name (#204) * implement sort command (#34) * introduce backends structure (#296) * implement backend structure poc * improve config namings * improve account namings and structure * rename imap vars to backend * maildir backend (#299) * refactor config system, preparing maildir backend * rename deserializable by deserialized * wrap backend in a Box * reword backend trait methods * merge list envelopes functions * remove find_raw_msg from backend trait * remove expunge fn from backend trait * rename add_msg from backend trait * init maildir integration tests, start impl maildir backend fns * implement remaining methods maildir backend, refactor trait * improve backend trait, add copy and move fns * remove usage of Mbox in handlers * reorganize backends folder structure * move mbox out of domain folder * rename mbox entities * improve mbox structure * remove unused files, move smtp module * improve envelope, impl get_envelopes for maildir * link maildir mail entry id to envelope id * use erased-serde to make backend get_mboxes return a trait object * remove unused mbox files * rename Output trait * make get_envelopes return a trait object * remove unused impl for imap envelope * update backend return signature with Box * replace impl from imap::Fetch to mailparse::ParsedMail * split flags by backends * remove unused flags from msg * remove remaining flags from domain * impl maildir copy and move, improve maildir e2e tests * set up imap backend e2e tests * move domain/msg to msg * repair broken tests * fix maildir envelopes encoding issues * add date column to maildir envelopes * implement maildir list pagination * improve maildir subdir path management * add pgp and maildir features to readme * update changelog * bump version v0.5.6
54 lines
1.3 KiB
Rust
54 lines
1.3 KiB
Rust
use anyhow::{anyhow, Error, Result};
|
|
use std::{convert::TryFrom, fmt};
|
|
|
|
/// Represents the available output formats.
|
|
#[derive(Debug, PartialEq)]
|
|
pub enum OutputFmt {
|
|
Plain,
|
|
Json,
|
|
}
|
|
|
|
impl From<&str> for OutputFmt {
|
|
fn from(fmt: &str) -> Self {
|
|
match fmt {
|
|
slice if slice.eq_ignore_ascii_case("json") => Self::Json,
|
|
_ => Self::Plain,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl TryFrom<Option<&str>> for OutputFmt {
|
|
type Error = Error;
|
|
|
|
fn try_from(fmt: Option<&str>) -> Result<Self, Self::Error> {
|
|
match fmt {
|
|
Some(fmt) if fmt.eq_ignore_ascii_case("json") => Ok(Self::Json),
|
|
Some(fmt) if fmt.eq_ignore_ascii_case("plain") => Ok(Self::Plain),
|
|
None => Ok(Self::Plain),
|
|
Some(fmt) => Err(anyhow!(r#"cannot parse output format "{}""#, fmt)),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for OutputFmt {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
let fmt = match *self {
|
|
OutputFmt::Json => "JSON",
|
|
OutputFmt::Plain => "Plain",
|
|
};
|
|
write!(f, "{}", fmt)
|
|
}
|
|
}
|
|
|
|
/// Defines a struct-wrapper to provide a JSON output.
|
|
#[derive(Debug, Clone, serde::Serialize)]
|
|
pub struct OutputJson<T: serde::Serialize> {
|
|
response: T,
|
|
}
|
|
|
|
impl<T: serde::Serialize> OutputJson<T> {
|
|
pub fn new(response: T) -> Self {
|
|
Self { response }
|
|
}
|
|
}
|