Add some error checking in parsing
parent
2f91d29326
commit
6ebab37a3d
1
.gdbinit
1
.gdbinit
|
@ -2,3 +2,4 @@ break rust_panic
|
||||||
break core::option::expect_failed::h4927e1fef06c4878
|
break core::option::expect_failed::h4927e1fef06c4878
|
||||||
break core::panicking::panic
|
break core::panicking::panic
|
||||||
break libcore/panicking.rs:58
|
break libcore/panicking.rs:58
|
||||||
|
break libcore/result.rs:945
|
||||||
|
|
|
@ -216,7 +216,9 @@ impl MaildirType {
|
||||||
Envelope::from_token(Box::new(BackendOpGenerator::new(Box::new(
|
Envelope::from_token(Box::new(BackendOpGenerator::new(Box::new(
|
||||||
move || Box::new(MaildirOp::new(e_copy.clone())),
|
move || Box::new(MaildirOp::new(e_copy.clone())),
|
||||||
)))) {
|
)))) {
|
||||||
e.populate_headers();
|
if e.populate_headers().is_err() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
local_r.push(e);
|
local_r.push(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ pub mod attachments;
|
||||||
pub mod parser;
|
pub mod parser;
|
||||||
|
|
||||||
pub use self::attachments::*;
|
pub use self::attachments::*;
|
||||||
|
use error::{MeliError, Result};
|
||||||
use mailbox::backends::BackendOpGenerator;
|
use mailbox::backends::BackendOpGenerator;
|
||||||
|
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
@ -249,14 +250,14 @@ impl Envelope {
|
||||||
Some(e)
|
Some(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn populate_headers(&mut self) -> () {
|
pub fn populate_headers(&mut self) -> Result<()> {
|
||||||
let mut operation = self.operation_token.generate();
|
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,
|
Ok(v) => v,
|
||||||
_ => {
|
Err(e) => {
|
||||||
let operation = self.operation_token.generate();
|
let operation = self.operation_token.generate();
|
||||||
eprintln!("error in parsing mail\n{}", operation.description());
|
eprintln!("error in parsing mail\n{}", operation.description());
|
||||||
return;
|
return Err(MeliError::from(e));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -324,6 +325,7 @@ impl Envelope {
|
||||||
self.set_datetime(d);
|
self.set_datetime(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn date(&self) -> u64 {
|
pub fn date(&self) -> u64 {
|
||||||
self.timestamp
|
self.timestamp
|
||||||
|
@ -362,7 +364,9 @@ impl Envelope {
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let operation = self.operation_token.generate();
|
let operation = self.operation_token.generate();
|
||||||
eprintln!("error in parsing mail\n{}", operation.description());
|
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);
|
let mut builder = AttachmentBuilder::new(body);
|
||||||
|
|
|
@ -500,6 +500,9 @@ named!(pub address_list<String>, ws!(do_parse!(
|
||||||
named!(pub phrase<String>, ws!(do_parse!(
|
named!(pub phrase<String>, ws!(do_parse!(
|
||||||
list: many0!(alt_complete!( encoded_word_list | ascii_token)) >>
|
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 string_len = list.iter().fold(0, |mut acc, x| { acc+=x.len(); acc }) + list.len() - 1;
|
||||||
let list_len = list.len();
|
let list_len = list.len();
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
@ -512,6 +515,7 @@ named!(pub phrase<String>, ws!(do_parse!(
|
||||||
}
|
}
|
||||||
acc
|
acc
|
||||||
})
|
})
|
||||||
|
}
|
||||||
} )
|
} )
|
||||||
|
|
||||||
)));
|
)));
|
||||||
|
|
Loading…
Reference in New Issue