diff options
Diffstat (limited to 'ui/src/components/mail')
-rw-r--r-- | ui/src/components/mail/compose.rs | 6 | ||||
-rw-r--r-- | ui/src/components/mail/listing/compact.rs | 42 | ||||
-rw-r--r-- | ui/src/components/mail/listing/conversations.rs | 8 | ||||
-rw-r--r-- | ui/src/components/mail/view.rs | 62 |
4 files changed, 105 insertions, 13 deletions
diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index 3f6da8eb..6c268772 100644 --- a/ui/src/components/mail/compose.rs +++ b/ui/src/components/mail/compose.rs @@ -128,15 +128,15 @@ impl Composer { * msg: index of message we reply to in thread_nodes * context: current context */ - pub fn edit(account_pos: usize, h: EnvelopeHash, context: &Context) -> Self { + pub fn edit(account_pos: usize, h: EnvelopeHash, context: &Context) -> Result<Self> { let mut ret = Composer::default(); let op = context.accounts[account_pos].operation(h); let envelope: &Envelope = context.accounts[account_pos].get_env(&h); - ret.draft = Draft::edit(envelope, op); + ret.draft = Draft::edit(envelope, op)?; ret.account_cursor = account_pos; - ret + Ok(ret) } pub fn with_context( coordinates: (usize, usize, usize), diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index ecbec4ad..3aef9145 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -352,6 +352,7 @@ impl ListingTrait for CompactListing { } self.filter_term.clear(); + let mut error: Option<(EnvelopeHash, MeliError)> = None; for (i, h) in self.order.keys().enumerate() { let account = &context.accounts[self.cursor_pos.0]; let envelope = &account.collection[h]; @@ -367,8 +368,14 @@ impl ListingTrait for CompactListing { self.selection.insert(*h, false); continue; } - let op = account.operation(*h); - let body = envelope.body(op); + let op = account.operation(env_hash); + let body = match envelope.body(op) { + Ok(b) => b, + Err(e) => { + error = Some((env_hash, e)); + break; + } + }; let decoded = decode_rec(&body, None); let body_text = String::from_utf8_lossy(&decoded); if body_text.contains(&filter_term) { @@ -377,22 +384,45 @@ impl ListingTrait for CompactListing { self.selection.insert(*h, false); } } - if !self.filtered_selection.is_empty() { + + if let Some((env_hash, error)) = error { + self.length = 0; + let message = format!("Error: {}", error.to_string()); + log( + format!( + "Failed to open envelope {}: {}", + context.accounts[self.new_cursor_pos.0] + .get_env(&env_hash) + .message_id_display(), + error.to_string() + ), + ERROR, + ); + self.data_columns.columns[0] = CellBuffer::new(message.len(), 1, Cell::with_char(' ')); + write_string_to_grid( + &message, + &mut self.data_columns.columns[0], + Color::Default, + Color::Default, + Attr::Default, + ((0, 0), (message.len() - 1, 0)), + false, + ); + } else if !self.filtered_selection.is_empty() { self.filter_term = filter_term.to_string(); self.cursor_pos.2 = std::cmp::min(self.filtered_selection.len() - 1, self.cursor_pos.2); self.length = self.filtered_selection.len(); } else { self.length = 0; let message = format!("No results for `{}`.", filter_term); - self.data_columns.columns[0] = - CellBuffer::new(message.len(), self.length + 1, Cell::with_char(' ')); + self.data_columns.columns[0] = CellBuffer::new(message.len(), 1, Cell::with_char(' ')); write_string_to_grid( &message, &mut self.data_columns.columns[0], Color::Default, Color::Default, Attr::Default, - ((0, 0), (MAX_COLS - 1, 0)), + ((0, 0), (message.len() - 1, 0)), false, ); } diff --git a/ui/src/components/mail/listing/conversations.rs b/ui/src/components/mail/listing/conversations.rs index 716f0882..f40c3583 100644 --- a/ui/src/components/mail/listing/conversations.rs +++ b/ui/src/components/mail/listing/conversations.rs @@ -417,7 +417,13 @@ impl ListingTrait for ConversationsListing { continue; } let op = account.operation(env_hash); - let body = envelope.body(op); + let body = match envelope.body(op) { + Ok(b) => b, + Err(e) => { + error = Some(e); + break; + } + }; let decoded = decode_rec(&body, None); let body_text = String::from_utf8_lossy(&decoded); if body_text.contains(&filter_term) { diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index cd256f6c..529d8799 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -597,7 +597,25 @@ impl Component for MailView { let account = &mut context.accounts[self.coordinates.0]; let envelope: &Envelope = &account.get_env(&self.coordinates.2); let op = account.operation(envelope.hash()); - envelope.body(op) + match envelope.body(op) { + Ok(body) => body, + Err(e) => { + context.replies.push_back(UIEvent::Notification( + Some("Failed to open e-mail".to_string()), + e.to_string(), + Some(NotificationType::ERROR), + )); + log( + format!( + "Failed to open envelope {}: {}", + envelope.message_id_display(), + e.to_string() + ), + ERROR, + ); + return; + } + } }; match self.mode { ViewMode::Attachment(aidx) if body.attachments()[aidx].is_html() => { @@ -799,7 +817,27 @@ impl Component for MailView { let account = &mut context.accounts[self.coordinates.0]; let envelope: &Envelope = &account.get_env(&self.coordinates.2); let op = account.operation(envelope.hash()); - if let Some(u) = envelope.body(op).attachments().get(lidx) { + + let attachments = match envelope.body(op) { + Ok(body) => body.attachments(), + Err(e) => { + context.replies.push_back(UIEvent::Notification( + Some("Failed to open e-mail".to_string()), + e.to_string(), + Some(NotificationType::ERROR), + )); + log( + format!( + "Failed to open envelope {}: {}", + envelope.message_id_display(), + e.to_string() + ), + ERROR, + ); + return true; + } + }; + if let Some(u) = attachments.get(lidx) { match u.content_type() { ContentType::MessageRfc822 => { match EnvelopeWrapper::new(u.body().to_vec()) { @@ -910,7 +948,25 @@ impl Component for MailView { let envelope: &Envelope = &account.get_env(&self.coordinates.2); let finder = LinkFinder::new(); let op = account.operation(envelope.hash()); - let t = envelope.body(op).text().to_string(); + let t = match envelope.body(op) { + Ok(body) => body.text().to_string(), + Err(e) => { + context.replies.push_back(UIEvent::Notification( + Some("Failed to open e-mail".to_string()), + e.to_string(), + Some(NotificationType::ERROR), + )); + log( + format!( + "Failed to open envelope {}: {}", + envelope.message_id_display(), + e.to_string() + ), + ERROR, + ); + return true; + } + }; let links: Vec<Link> = finder.links(&t).collect(); if let Some(u) = links.get(lidx) { u.as_str().to_string() |