aboutsummaryrefslogtreecommitdiff
path: root/src/imap/mail_view.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-01-05 18:59:19 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-01-05 18:59:19 +0100
commit4806f7ff84c595ec6647744577388fe4fab33736 (patch)
treea4d3c0eebb9a40872449695e651b8f7df1d54d07 /src/imap/mail_view.rs
parentadf4d33f226a745330a3bb802fe9b96f263a0895 (diff)
downloadaerogramme-4806f7ff84c595ec6647744577388fe4fab33736.tar.gz
aerogramme-4806f7ff84c595ec6647744577388fe4fab33736.zip
WIP rewrite with a query managerfeat/more-imap-qol
Diffstat (limited to 'src/imap/mail_view.rs')
-rw-r--r--src/imap/mail_view.rs26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/imap/mail_view.rs b/src/imap/mail_view.rs
index c95c733..94215dc 100644
--- a/src/imap/mail_view.rs
+++ b/src/imap/mail_view.rs
@@ -1,6 +1,6 @@
use std::num::NonZeroU32;
-use anyhow::{anyhow, bail, Result};
+use anyhow::{anyhow, bail, Result, Context};
use chrono::{Offset, TimeZone, Utc};
use imap_codec::imap_types::core::{IString, NString};
@@ -22,16 +22,31 @@ use crate::imap::imf_view::message_envelope;
use crate::imap::mailbox_view::MailIdentifiers;
use crate::imap::mime_view;
use crate::imap::response::Body;
-use crate::mail::mailbox::MailMeta;
+use crate::mail::query::QueryResult;
pub struct MailView<'a> {
- pub ids: &'a MailIdentifiers,
- pub meta: &'a MailMeta,
- pub flags: &'a Vec<String>,
+ pub query_result: &'a QueryResult<'a>,
pub content: FetchedMail<'a>,
}
impl<'a> MailView<'a> {
+ pub fn new(query_result: &'a QueryResult<'a>) -> Result<Self> {
+ Ok(Self {
+ query_result,
+ content: match query_result {
+ QueryResult::FullResult { content, .. } => {
+ let (_, parsed) = eml_codec::parse_message(content).context("Invalid mail body")?;
+ FetchedMail::new_from_message(parsed)
+ },
+ QueryResult::PartialResult { metadata, .. } => {
+ let (_, parsed) = eml_codec::parse_imf(&metadata.headers).context("Invalid mail headers")?;
+ FetchedMail::Partial(parsed)
+ }
+ QueryResult::IndexResult { .. } => FetchedMail::None,
+ }
+ })
+ }
+
fn uid(&self) -> MessageDataItem<'static> {
MessageDataItem::Uid(self.ids.uid.clone())
}
@@ -193,6 +208,7 @@ pub enum SeenFlag {
// -------------------
pub enum FetchedMail<'a> {
+ None,
Partial(imf::Imf<'a>),
Full(AnyPart<'a>),
}