summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--ui/src/components/mail/view.rs57
-rw-r--r--ui/src/components/mail/view/envelope.rs8
-rw-r--r--ui/src/components/mail/view/html.rs41
3 files changed, 61 insertions, 45 deletions
diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs
index 8da8e054..1c569775 100644
--- a/ui/src/components/mail/view.rs
+++ b/ui/src/components/mail/view.rs
@@ -396,18 +396,15 @@ impl Component for MailView {
self.pager = None;
let attachment = &body.attachments()[aidx];
self.subview = Some(Box::new(HtmlView::new(
- decode(&attachment, None),
+ &attachment,
context,
self.coordinates.0,
)));
self.mode = ViewMode::Subview;
}
ViewMode::Normal if body.is_html() => {
- self.subview = Some(Box::new(HtmlView::new(
- decode(&body, None),
- context,
- self.coordinates.0,
- )));
+ self.subview =
+ Some(Box::new(HtmlView::new(&body, context, self.coordinates.0)));
self.pager = None;
self.mode = ViewMode::Subview;
}
@@ -547,25 +544,24 @@ impl Component for MailView {
self.cmd_buf.clone(),
)));
}
- UIEvent::Input(Key::Char('r'))
- if self.mode == ViewMode::Normal || self.mode == ViewMode::Raw =>
+ UIEvent::Input(Key::Alt('r'))
+ if self.mode == ViewMode::Normal || self.mode == ViewMode::Subview =>
{
- self.mode = if self.mode == ViewMode::Raw {
- ViewMode::Normal
- } else {
- ViewMode::Raw
- };
- self.dirty = true;
+ self.mode = ViewMode::Raw;
+ self.set_dirty();
}
UIEvent::Input(Key::Char('r'))
- if self.mode.is_attachment() || self.mode == ViewMode::Subview =>
+ if self.mode.is_attachment()
+ || self.mode == ViewMode::Subview
+ || self.mode == ViewMode::Url
+ || self.mode == ViewMode::Raw =>
{
self.mode = ViewMode::Normal;
- self.subview.take();
- self.dirty = true;
+ self.set_dirty();
}
UIEvent::Input(Key::Char('a'))
- if !self.cmd_buf.is_empty() && self.mode == ViewMode::Normal =>
+ if !self.cmd_buf.is_empty()
+ && (self.mode == ViewMode::Normal || self.mode == ViewMode::Subview) =>
{
let lidx = self.cmd_buf.parse::<usize>().unwrap();
self.cmd_buf.clear();
@@ -734,6 +730,31 @@ impl Component for MailView {
_ => {}
}
}
+ fn get_shortcuts(&self, context: &Context) -> ShortcutMap {
+ let mut map = if let Some(ref sbv) = self.subview {
+ sbv.get_shortcuts(context)
+ } else if let Some(ref pgr) = self.pager {
+ pgr.get_shortcuts(context)
+ } else {
+ FnvHashMap::with_capacity_and_hasher(4, Default::default())
+ };
+
+ map.insert("add_addresses_to_contacts", Key::Char('c'));
+ map.insert("view_raw_source", Key::Alt('r'));
+ if self.mode.is_attachment() || self.mode == ViewMode::Subview || self.mode == ViewMode::Raw
+ {
+ map.insert("return_to_normal_view", Key::Char('r'));
+ }
+ map.insert("open_attachment", Key::Char('a'));
+ if self.mode == ViewMode::Url {
+ map.insert("go_to_url", Key::Char('g'));
+ }
+ if self.mode == ViewMode::Normal || self.mode == ViewMode::Url {
+ map.insert("toggle_url_mode", Key::Char('u'));
+ }
+
+ map
+ }
fn id(&self) -> ComponentId {
self.id
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 }
}
}