melib: multipart/mixed with html messages not displayed as html

embed
Manos Pitsidianakis 2019-05-03 23:51:21 +03:00
parent 8ef470fb15
commit 1f2c0b4fa7
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 161 additions and 123 deletions

View File

@ -299,12 +299,12 @@ impl Attachment {
text.extend(decode(self, None));
}
ContentType::Multipart {
kind: ref multipart_type,
subattachments: ref sub_att_vec,
ref kind,
ref subattachments,
..
} => match *multipart_type {
} => match kind {
MultipartType::Alternative => {
for a in sub_att_vec {
for a in subattachments {
if let ContentType::Text {
kind: Text::Plain, ..
} = a.content_type
@ -314,9 +314,9 @@ impl Attachment {
}
}
}
MultipartType::Mixed | MultipartType::Digest => {
for a in sub_att_vec {
a.get_text_recursive(text);
_ => {
for a in subattachments {
a.get_text_recursive(text)
}
}
},
@ -369,6 +369,19 @@ impl Attachment {
ContentType::Text {
kind: Text::Html, ..
} => true,
ContentType::Multipart {
ref subattachments, ..
} => subattachments
.iter()
.fold(true, |acc, a| match &a.content_type {
ContentType::Text {
kind: Text::Plain, ..
} => false,
ContentType::Text {
kind: Text::Html, ..
} => acc,
_ => acc,
}),
_ => false,
}
}
@ -401,17 +414,17 @@ fn decode_rfc822(_raw: &[u8]) -> Attachment {
type Filter<'a> = Box<FnMut(&'a Attachment, &mut Vec<u8>) -> () + 'a>;
fn decode_rec_helper<'a>(a: &'a Attachment, filter: &mut Option<Filter<'a>>) -> Vec<u8> {
let mut ret = match a.content_type {
let ret = match a.content_type {
ContentType::Unsupported { .. } => Vec::new(),
ContentType::Text { .. } => decode_helper(a, filter),
ContentType::MessageRfc822 => decode_rec(&decode_rfc822(&a.raw), None),
ContentType::Multipart {
kind: ref multipart_type,
subattachments: ref sub_att_vec,
ref kind,
ref subattachments,
..
} => {
if *multipart_type == MultipartType::Alternative {
for a in sub_att_vec {
} => match kind {
MultipartType::Alternative => {
for a in subattachments {
if let ContentType::Text {
kind: Text::Plain, ..
} = a.content_type
@ -420,18 +433,16 @@ fn decode_rec_helper<'a>(a: &'a Attachment, filter: &mut Option<Filter<'a>>) ->
}
}
decode_helper(a, filter)
} else {
}
_ => {
let mut vec = Vec::new();
for a in sub_att_vec {
for a in subattachments {
vec.extend(decode_rec_helper(a, filter));
}
vec
}
}
},
};
if let Some(filter) = filter {
filter(a, &mut ret);
}
ret
}

View File

@ -131,6 +131,7 @@ impl MailView {
use std::io::Write;
use std::process::{Command, Stdio};
let settings = context.accounts[self.coordinates.0].runtime_settings.conf();
/* FIXME: duplication with view/html.rs */
if let Some(filter_invocation) = settings.html_filter() {
let parts = split_command!(filter_invocation);
let (cmd, args) = (parts[0], &parts[1..]);
@ -163,6 +164,33 @@ impl MailView {
)
.into_bytes();
v.extend(html_filter.wait_with_output().unwrap().stdout);
} else {
if let Ok(mut html_filter) = Command::new("w3m")
.args(&["-I", "utf-8", "-T", "text/html"])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
{
html_filter
.stdin
.as_mut()
.unwrap()
.write_all(&v)
.expect("Failed to write to html filter stdin");
*v = String::from(
"Text piped through `w3m`. Press `v` to open in web browser. \n\n",
)
.into_bytes();
v.extend(html_filter.wait_with_output().unwrap().stdout);
} else {
context.replies.push_back(UIEvent::Notification(
Some(format!(
"Failed to find any application to use as html filter"
)),
String::new(),
));
return;
}
}
}
})),
@ -194,7 +222,7 @@ impl MailView {
} else if lidx < 1000 {
385 + (lidx - 99) * 5
} else {
panic!("BUG: Message body with more than 100 urls, fix this");
panic!("FIXME: Message body with more than 100 urls, fix this");
};
t.insert_str(l.start() + offset, &format!("[{}]", lidx));
}
@ -261,7 +289,6 @@ impl Component for MailView {
let upper_left = upper_left!(area);
let bottom_right = bottom_right!(area);
if self.dirty {
let y: usize = {
let accounts = &mut context.accounts;
let mailbox = &mut accounts[self.coordinates.0][self.coordinates.1]
@ -352,6 +379,7 @@ impl Component for MailView {
}
};
if self.dirty {
let body = {
let mailbox_idx = self.coordinates; // coordinates are mailbox idxs
let mailbox = &context.accounts[mailbox_idx.0][mailbox_idx.1]
@ -407,9 +435,9 @@ impl Component for MailView {
}
};
self.dirty = false;
}
match self.mode {
ViewMode::Subview => {
ViewMode::Subview if self.subview.is_some() => {
if let Some(s) = self.subview.as_mut() {
s.draw(grid, (set_y(upper_left, y + 1), bottom_right), context);
}
@ -425,7 +453,6 @@ impl Component for MailView {
}
}
}
}
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
match self.mode {