melib/addressbook: log vcard parsing failures

master
Manos Pitsidianakis 2021-10-24 14:17:49 +03:00
parent 15ca25af73
commit 2580522931
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 29 additions and 13 deletions

View File

@ -105,9 +105,17 @@ impl AddressBook {
{
let mut ret = AddressBook::new(s.name.clone());
if let Some(vcard_path) = s.vcard_folder() {
if let Ok(cards) = vcard::load_cards(std::path::Path::new(vcard_path)) {
for c in cards {
ret.add_card(c);
match vcard::load_cards(std::path::Path::new(vcard_path)) {
Ok(cards) => {
for c in cards {
ret.add_card(c);
}
}
Err(err) => {
crate::log(
format!("Could not load vcards from {:?}: {}", vcard_path, err),
crate::WARN,
);
}
}
}

View File

@ -269,16 +269,24 @@ pub fn load_cards(p: &std::path::Path) -> Result<Vec<Card>> {
use std::io::Read;
contents.clear();
std::fs::File::open(&f)?.read_to_string(&mut contents)?;
if let Ok((_, c)) = parse_card().parse(contents.as_str()) {
for s in c {
ret.push(
CardDeserializer::from_str(s)
.and_then(TryInto::try_into)
.map(|mut card| {
Card::set_external_resource(&mut card, true);
is_any_valid = true;
card
}),
match parse_card().parse(contents.as_str()) {
Ok((_, c)) => {
for s in c {
ret.push(
CardDeserializer::from_str(s)
.and_then(TryInto::try_into)
.map(|mut card| {
Card::set_external_resource(&mut card, true);
is_any_valid = true;
card
}),
);
}
}
Err(err) => {
crate::log(
format!("Could not parse vcard from {}: {}", f.display(), err),
crate::WARN,
);
}
}