From b0e50a29bdd3d16238eea2f41504ec1046ae311b Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Fri, 25 Sep 2020 13:45:48 +0300 Subject: [PATCH] melib/list_management: don't ignore "NO" in List-Post --- melib/src/email/list_management.rs | 20 ++++++++++---------- melib/src/email/parser.rs | 2 +- src/components/mail/view.rs | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/melib/src/email/list_management.rs b/melib/src/email/list_management.rs index aad769fd8..3ecbb2022 100644 --- a/melib/src/email/list_management.rs +++ b/melib/src/email/list_management.rs @@ -25,10 +25,12 @@ use super::Envelope; use smallvec::SmallVec; use std::convert::From; -#[derive(Debug, Copy)] +#[derive(Debug, PartialEq, Clone, Copy)] pub enum ListAction<'a> { Url(&'a [u8]), Email(&'a [u8]), + ///`List-Post` field may contain the special value "NO". + No, } impl<'a> From<&'a [u8]> for ListAction<'a> { @@ -38,6 +40,8 @@ impl<'a> From<&'a [u8]> for ListAction<'a> { * parser::mailto() will handle this if user tries to unsubscribe. */ ListAction::Email(value) + } else if value.starts_with(b"NO") { + ListAction::No } else { /* Otherwise treat it as url. There's no foolproof way to check if this is valid, so * postpone it until we try an HTTP request. @@ -69,15 +73,6 @@ impl<'a> ListAction<'a> { } } -impl<'a> Clone for ListAction<'a> { - fn clone(&self) -> Self { - match self { - ListAction::Url(a) => ListAction::Url(<&[u8]>::clone(a)), - ListAction::Email(a) => ListAction::Email(<&[u8]>::clone(a)), - } - } -} - #[derive(Default, Debug)] pub struct ListActions<'a> { pub id: Option<&'a str>, @@ -129,6 +124,11 @@ impl<'a> ListActions<'a> { if let Some(post) = envelope.other_headers().get("List-Post") { ret.post = ListAction::parse_options_list(post.as_bytes()); + if let Some(ref l) = ret.post { + if l.starts_with(&[ListAction::No]) { + ret.post = None; + } + } } if let Some(unsubscribe) = envelope.other_headers().get("List-Unsubscribe") { diff --git a/melib/src/email/parser.rs b/melib/src/email/parser.rs index 2d5c26258..69381f5c7 100644 --- a/melib/src/email/parser.rs +++ b/melib/src/email/parser.rs @@ -1175,7 +1175,7 @@ pub mod mailing_lists { map(tag("NO"), |_| ()), map(opt(cfws), |_| ()), ), - |_| vec![], + |_| vec![&b"NO"[..]], ), ))(input)?; let (input, _) = opt(cfws)(input)?; diff --git a/src/components/mail/view.rs b/src/components/mail/view.rs index c7e697405..b7e04d060 100644 --- a/src/components/mail/view.rs +++ b/src/components/mail/view.rs @@ -223,6 +223,17 @@ impl MailView { if let Ok(Some(bytes_result)) = try_recv_timeout!(&mut chan) { match bytes_result { Ok(bytes) => { + if account + .collection + .get_env(self.coordinates.2) + .other_headers() + .is_empty() + { + let _ = account + .collection + .get_env_mut(self.coordinates.2) + .populate_headers(&bytes); + } let body = AttachmentBuilder::new(&bytes).build(); let body_text = self.attachment_to_text(&body, context); self.state = MailViewState::Loaded { @@ -1116,6 +1127,17 @@ impl Component for MailView { debug!("bytes_result"); match bytes_result { Ok(bytes) => { + if context.accounts[&self.coordinates.0] + .collection + .get_env(self.coordinates.2) + .other_headers() + .is_empty() + { + let _ = context.accounts[&self.coordinates.0] + .collection + .get_env_mut(self.coordinates.2) + .populate_headers(&bytes); + } let body = AttachmentBuilder::new(&bytes).build(); let body_text = self.attachment_to_text(&body, context); self.state = MailViewState::Loaded { @@ -1693,6 +1715,7 @@ impl Component for MailView { } return true; } + list_management::ListAction::No => {} } } }