use std::mem;
use chrono::prelude::*;
use crate::account::model::*;
use crate::mime::grovel::Visitor;
#[derive(Clone, Copy, Debug, Default)]
pub struct UidFetcher;
impl Visitor for UidFetcher {
type Output = Uid;
fn uid(&mut self, uid: Uid) -> Result<(), Uid> {
Err(uid)
}
fn end(&mut self) -> Uid {
panic!("UidFetcher.end()")
}
}
#[derive(Clone, Copy, Debug, Default)]
pub struct ModseqFetcher;
impl Visitor for ModseqFetcher {
type Output = Modseq;
fn last_modified(&mut self, modseq: Modseq) -> Result<(), Modseq> {
Err(modseq)
}
fn end(&mut self) -> Modseq {
panic!("ModseqFetcher.end()")
}
}
#[derive(Clone, Debug, Default)]
pub struct FlagsInfo {
pub flags: Vec<Flag>,
pub recent: bool,
}
#[derive(Clone, Debug, Default)]
pub struct FlagsFetcher {
info: FlagsInfo,
}
impl FlagsFetcher {
pub fn new() -> Self {
Self::default()
}
}
impl Visitor for FlagsFetcher {
type Output = FlagsInfo;
fn want_flags(&self) -> bool {
true
}
fn flags(&mut self, flags: &[Flag]) -> Result<(), FlagsInfo> {
self.info.flags = flags.to_owned();
Ok(())
}
fn recent(&mut self) -> Result<(), FlagsInfo> {
self.info.recent = true;
Ok(())
}
fn end_flags(&mut self) -> Result<(), FlagsInfo> {
Err(self.end())
}
fn end(&mut self) -> FlagsInfo {
mem::take(&mut self.info)
}
}
#[derive(Clone, Copy, Debug, Default)]
pub struct Rfc822SizeFetcher;
impl Visitor for Rfc822SizeFetcher {
type Output = u32;
fn metadata(&mut self, md: &MessageMetadata) -> Result<(), u32> {
Err(md.size)
}
fn end(&mut self) -> u32 {
panic!("Rfc822SizeFetcher.end()")
}
}
#[derive(Clone, Copy, Debug, Default)]
pub struct InternalDateFetcher;
impl Visitor for InternalDateFetcher {
type Output = DateTime<FixedOffset>;
fn metadata(
&mut self,
md: &MessageMetadata,
) -> Result<(), DateTime<FixedOffset>> {
Err(md.internal_date)
}
fn end(&mut self) -> DateTime<FixedOffset> {
panic!("InternalDateFetcher.end()")
}
}
#[derive(Clone, Copy, Debug, Default)]
pub struct EmailIdFetcher;
impl Visitor for EmailIdFetcher {
type Output = String;
fn metadata(&mut self, md: &MessageMetadata) -> Result<(), String> {
Err(md.format_email_id())
}
fn end(&mut self) -> String {
panic!("EmailIdFetcher.end()")
}
}