summaryrefslogtreecommitdiffstats
path: root/ui/src/components/mail/view
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-05-07 01:57:44 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:47 +0300
commit35bac364b1f512757e29e5829ab2c79cb75e7448 (patch)
treec0df864f8f7c92948c291aa7741ebbeb9424a327 /ui/src/components/mail/view
parent59d912e2eebfde2a9e57af6a242ee7b8952fddd2 (diff)
ui: correctly display multipart html in Views
- Use Alt-r for entering raw mode - Use r to exit raw mode - added shortcuts - add attachment footer in HtmlView::new
Diffstat (limited to 'ui/src/components/mail/view')
-rw-r--r--ui/src/components/mail/view/envelope.rs8
-rw-r--r--ui/src/components/mail/view/html.rs41
2 files changed, 22 insertions, 27 deletions
diff --git a/ui/src/components/mail/view/envelope.rs b/ui/src/components/mail/view/envelope.rs
index 4e62f72b..f888b33e 100644
--- a/ui/src/components/mail/view/envelope.rs
+++ b/ui/src/components/mail/view/envelope.rs
@@ -315,17 +315,13 @@ impl Component for EnvelopeView {
ViewMode::Attachment(aidx) if body.attachments()[aidx].is_html() => {
let attachment = &body.attachments()[aidx];
self.subview = Some(Box::new(HtmlView::new(
- decode(&attachment, None),
+ &attachment,
context,
self.account_pos,
)));
}
ViewMode::Normal if body.is_html() => {
- self.subview = Some(Box::new(HtmlView::new(
- decode(&body, None),
- context,
- self.account_pos,
- )));
+ self.subview = Some(Box::new(HtmlView::new(&body, context, self.account_pos)));
self.mode = ViewMode::Subview;
}
_ => {
diff --git a/ui/src/components/mail/view/html.rs b/ui/src/components/mail/view/html.rs
index c6f29bf5..60e5b34c 100644
--- a/ui/src/components/mail/view/html.rs
+++ b/ui/src/components/mail/view/html.rs
@@ -31,10 +31,12 @@ pub struct HtmlView {
}
impl HtmlView {
- pub fn new(bytes: Vec<u8>, context: &mut Context, account_pos: usize) -> Self {
+ pub fn new(body: &Attachment, context: &mut Context, account_pos: usize) -> Self {
let id = ComponentId::new_v4();
+ let bytes: Vec<u8> = decode_rec(body, None);
+
let settings = context.accounts[account_pos].runtime_settings.conf();
- if let Some(filter_invocation) = settings.html_filter() {
+ let mut display_text = if let Some(filter_invocation) = settings.html_filter() {
let parts = split_command!(filter_invocation);
let (cmd, args) = (parts[0], &parts[1..]);
let command_obj = Command::new(cmd)
@@ -50,13 +52,7 @@ impl HtmlView {
)),
String::new(),
));
- let pager = Pager::from_string(
- String::from_utf8_lossy(&bytes).to_string(),
- None,
- None,
- None,
- );
- HtmlView { pager, bytes, id }
+ String::from_utf8_lossy(&bytes).to_string()
} else {
let mut html_filter = command_obj.unwrap();
html_filter
@@ -72,9 +68,7 @@ impl HtmlView {
display_text.push_str(&String::from_utf8_lossy(
&html_filter.wait_with_output().unwrap().stdout,
));
-
- let pager = Pager::from_string(display_text, None, None, None);
- HtmlView { pager, bytes, id }
+ display_text
}
} else {
if let Ok(mut html_filter) = Command::new("w3m")
@@ -96,8 +90,7 @@ impl HtmlView {
&html_filter.wait_with_output().unwrap().stdout,
));
- let pager = Pager::from_string(display_text, None, None, None);
- HtmlView { pager, bytes, id }
+ display_text
} else {
context.replies.push_back(UIEvent::Notification(
Some(format!(
@@ -105,15 +98,21 @@ impl HtmlView {
)),
String::new(),
));
- let pager = Pager::from_string(
- String::from_utf8_lossy(&bytes).to_string(),
- None,
- None,
- None,
- );
- HtmlView { pager, bytes, id }
+ String::from_utf8_lossy(&bytes).to_string()
}
+ };
+ if body.count_attachments() > 1 {
+ display_text =
+ body.attachments()
+ .iter()
+ .enumerate()
+ .fold(display_text, |mut s, (idx, a)| {
+ s.push_str(&format!("[{}] {}\n\n\n", idx, a));
+ s
+ });
}
+ let pager = Pager::from_string(display_text, None, None, None);
+ HtmlView { pager, bytes, id }
}
}