melib/list_management: don't ignore "NO" in List-Post

jmap-eventsource
Manos Pitsidianakis 2020-09-25 13:45:48 +03:00
parent 1ddde400ee
commit b0e50a29bd
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 34 additions and 11 deletions

View File

@ -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") {

View File

@ -1175,7 +1175,7 @@ pub mod mailing_lists {
map(tag("NO"), |_| ()),
map(opt(cfws), |_| ()),
),
|_| vec![],
|_| vec![&b"NO"[..]],
),
))(input)?;
let (input, _) = opt(cfws)(input)?;

View File

@ -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 => {}
}
}
}