Be better about handling header errors
This commit is contained in:
parent
e7d5cece4d
commit
ae72225a09
38
src/main.rs
38
src/main.rs
|
@ -204,30 +204,42 @@ fn main() {
|
||||||
|
|
||||||
let mut subjects = Vec::new();
|
let mut subjects = Vec::new();
|
||||||
if !uids.is_empty() {
|
if !uids.is_empty() {
|
||||||
let mut finish = |message: &[u8]| {
|
let mut finish = |message: &[u8]| -> bool {
|
||||||
if message.is_empty() {
|
match mailparse::parse_headers(message) {
|
||||||
return;
|
Ok((headers, _)) => {
|
||||||
}
|
use mailparse::MailHeaderMap;
|
||||||
|
match headers.get_first_value("Subject") {
|
||||||
if let Ok((headers, _)) = mailparse::parse_headers(message) {
|
Ok(Some(subject)) => {
|
||||||
use mailparse::MailHeaderMap;
|
subjects.push(subject);
|
||||||
if let Ok(Some(subject)) = headers.get_first_value("Subject") {
|
return true;
|
||||||
subjects.push(subject);
|
}
|
||||||
|
Ok(None) => {
|
||||||
|
subjects.push(String::from("<no subject>"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("failed to get message subject: {:?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Err(e) => println!("failed to parse headers of message: {:?}", e),
|
||||||
}
|
}
|
||||||
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
let lines = imap_socket
|
let lines = imap_socket
|
||||||
.fetch(&uids.join(","), "RFC822.HEADER")
|
.fetch(&uids.join(","), "RFC822.HEADER")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut message = Vec::new();
|
let mut message = Vec::new();
|
||||||
for line in lines {
|
for line in &lines {
|
||||||
if line.starts_with("* ") {
|
if line.starts_with("* ") {
|
||||||
finish(&message[..]);
|
if !message.is_empty() {
|
||||||
message.clear();
|
finish(&message[..]);
|
||||||
|
message.clear();
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
message.extend(line.into_bytes());
|
message.extend(line.as_bytes());
|
||||||
}
|
}
|
||||||
finish(&message[..]);
|
finish(&message[..]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user