diff --git a/.gdbinit b/.gdbinit index acbd163b..35641e96 100644 --- a/.gdbinit +++ b/.gdbinit @@ -2,3 +2,4 @@ break rust_panic break core::option::expect_failed::h4927e1fef06c4878 break core::panicking::panic break libcore/panicking.rs:58 +break libcore/result.rs:945 diff --git a/melib/src/mailbox/backends/maildir.rs b/melib/src/mailbox/backends/maildir.rs index afef36c9..46bd1ce1 100644 --- a/melib/src/mailbox/backends/maildir.rs +++ b/melib/src/mailbox/backends/maildir.rs @@ -216,7 +216,9 @@ impl MaildirType { Envelope::from_token(Box::new(BackendOpGenerator::new(Box::new( move || Box::new(MaildirOp::new(e_copy.clone())), )))) { - e.populate_headers(); + if e.populate_headers().is_err() { + continue; + } local_r.push(e); } } diff --git a/melib/src/mailbox/email/mod.rs b/melib/src/mailbox/email/mod.rs index 81979a87..0a21ddfa 100644 --- a/melib/src/mailbox/email/mod.rs +++ b/melib/src/mailbox/email/mod.rs @@ -23,6 +23,7 @@ pub mod attachments; pub mod parser; pub use self::attachments::*; +use error::{MeliError, Result}; use mailbox::backends::BackendOpGenerator; use std::cmp::Ordering; @@ -249,14 +250,14 @@ impl Envelope { Some(e) } - pub fn populate_headers(&mut self) -> () { + pub fn populate_headers(&mut self) -> Result<()> { let mut operation = self.operation_token.generate(); - let headers = match parser::headers(operation.fetch_headers().unwrap()).to_full_result() { + let headers = match parser::headers(operation.fetch_headers()?).to_full_result() { Ok(v) => v, - _ => { + Err(e) => { let operation = self.operation_token.generate(); eprintln!("error in parsing mail\n{}", operation.description()); - return; + return Err(MeliError::from(e)); } }; @@ -324,6 +325,7 @@ impl Envelope { self.set_datetime(d); } } + Ok(()) } pub fn date(&self) -> u64 { self.timestamp @@ -362,7 +364,9 @@ impl Envelope { Err(_) => { let operation = self.operation_token.generate(); eprintln!("error in parsing mail\n{}", operation.description()); - panic!() + let error_msg = b"Mail cannot be shown because of errors."; + let mut builder = AttachmentBuilder::new(error_msg); + return builder.build() } }; let mut builder = AttachmentBuilder::new(body); diff --git a/melib/src/mailbox/email/parser.rs b/melib/src/mailbox/email/parser.rs index b05e7b32..80f7ff30 100644 --- a/melib/src/mailbox/email/parser.rs +++ b/melib/src/mailbox/email/parser.rs @@ -500,6 +500,9 @@ named!(pub address_list, ws!(do_parse!( named!(pub phrase, ws!(do_parse!( list: many0!(alt_complete!( encoded_word_list | ascii_token)) >> ( { + if list.len() == 0 { + String::new() + } else { let string_len = list.iter().fold(0, |mut acc, x| { acc+=x.len(); acc }) + list.len() - 1; let list_len = list.len(); let mut i = 0; @@ -512,6 +515,7 @@ named!(pub phrase, ws!(do_parse!( } acc }) + } } ) )));