Add some error checking in parsing

embed
Manos Pitsidianakis 2018-07-28 09:14:36 +03:00
parent 2f91d29326
commit 6ebab37a3d
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
4 changed files with 17 additions and 6 deletions

View File

@ -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

View File

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

View File

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

View File

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