summaryrefslogtreecommitdiffstats
path: root/ui/src/components/mail/view.rs
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-09-27 13:18:59 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-09-27 13:40:02 +0300
commit68c40a292091c9d0378ffcf31e53afd9535ac6a6 (patch)
tree855b8baa8292bae451f4a58691c02f49b9c7ac4a /ui/src/components/mail/view.rs
parentd44a68ec6950c533cf67ee2a34f9888a4ae569cc (diff)
melib: return Result with error when an IO operation fails
Don't unwrap anything because this might be temporary, for example a short IMAP disconnection.
Diffstat (limited to 'ui/src/components/mail/view.rs')
-rw-r--r--ui/src/components/mail/view.rs62
1 files changed, 59 insertions, 3 deletions
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()