Browse Source

Add some error checking in parsing

tags/pre-alpha-0.0
Manos Pitsidianakis 3 years ago
parent
commit
6ebab37a3d
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 1
      .gdbinit
  2. 4
      melib/src/mailbox/backends/maildir.rs
  3. 14
      melib/src/mailbox/email/mod.rs
  4. 4
      melib/src/mailbox/email/parser.rs

1
.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

4
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);
}
}

14
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);

4
melib/src/mailbox/email/parser.rs

@ -500,6 +500,9 @@ named!(pub address_list<String>, ws!(do_parse!(
named!(pub phrase<String>, 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<String>, ws!(do_parse!(
}
acc
})
}
} )
)));

Loading…
Cancel
Save