From be57b65dae81d74e5e0844ad367be41099c8806c Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Wed, 9 Sep 2020 22:51:55 +0300 Subject: [PATCH] melib/email: add flags arg to Mail::new --- melib/src/email.rs | 4 ++-- melib/src/email/attachments.rs | 2 +- src/bin.rs | 2 +- src/components/mail/view.rs | 31 ++++++++++++++++++------------- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/melib/src/email.rs b/melib/src/email.rs index fa03ee541..9f02f999d 100644 --- a/melib/src/email.rs +++ b/melib/src/email.rs @@ -94,9 +94,9 @@ impl Deref for Mail { } impl Mail { - pub fn new(bytes: Vec) -> Result { + pub fn new(bytes: Vec, flags: Option) -> Result { Ok(Mail { - envelope: Envelope::from_bytes(&bytes, None)?, + envelope: Envelope::from_bytes(&bytes, flags)?, bytes, }) } diff --git a/melib/src/email/attachments.rs b/melib/src/email/attachments.rs index bb5466a9f..e7d95906d 100644 --- a/melib/src/email/attachments.rs +++ b/melib/src/email/attachments.rs @@ -362,7 +362,7 @@ impl fmt::Display for Attachment { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.content_type { ContentType::MessageRfc822 => { - match Mail::new(self.body.display_bytes(&self.raw).to_vec()) { + match Mail::new(self.body.display_bytes(&self.raw).to_vec(), None) { Ok(wrapper) => write!( f, "message/rfc822: {} - {} - {}", diff --git a/src/bin.rs b/src/bin.rs index e26ef9edb..faa37dde1 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -309,7 +309,7 @@ fn run_app(opt: Opt) -> Result<()> { if let Some(SubCommand::View { path }) = opt.subcommand { let bytes = std::fs::read(&path) .chain_err_summary(|| format!("Could not read from `{}`", path.display()))?; - let wrapper = Mail::new(bytes) + let wrapper = Mail::new(bytes, Some(Flag::SEEN)) .chain_err_summary(|| format!("Could not parse `{}`", path.display()))?; state = State::new( Some(Settings::without_accounts().unwrap_or_default()), diff --git a/src/components/mail/view.rs b/src/components/mail/view.rs index d325aa3f4..f008b28b7 100644 --- a/src/components/mail/view.rs +++ b/src/components/mail/view.rs @@ -481,20 +481,25 @@ impl MailView { } } else { match u.content_type() { - ContentType::MessageRfc822 => match Mail::new(u.body().to_vec()) { - Ok(wrapper) => { - context - .replies - .push_back(UIEvent::Action(Tab(New(Some(Box::new( - EnvelopeView::new(wrapper, None, None, self.coordinates.0), - )))))); + ContentType::MessageRfc822 => { + match Mail::new(u.body().to_vec(), Some(Flag::SEEN)) { + Ok(wrapper) => { + context.replies.push_back(UIEvent::Action(Tab(New(Some( + Box::new(EnvelopeView::new( + wrapper, + None, + None, + self.coordinates.0, + )), + ))))); + } + Err(e) => { + context.replies.push_back(UIEvent::StatusEvent( + StatusEvent::DisplayMessage(format!("{}", e)), + )); + } } - Err(e) => { - context.replies.push_back(UIEvent::StatusEvent( - StatusEvent::DisplayMessage(format!("{}", e)), - )); - } - }, + } ContentType::Text { .. } | ContentType::PGPSignature => { self.mode = ViewMode::Attachment(lidx);