melib/addressbook: log vcard parsing failures
parent
15ca25af73
commit
2580522931
|
@ -105,9 +105,17 @@ impl AddressBook {
|
||||||
{
|
{
|
||||||
let mut ret = AddressBook::new(s.name.clone());
|
let mut ret = AddressBook::new(s.name.clone());
|
||||||
if let Some(vcard_path) = s.vcard_folder() {
|
if let Some(vcard_path) = s.vcard_folder() {
|
||||||
if let Ok(cards) = vcard::load_cards(std::path::Path::new(vcard_path)) {
|
match vcard::load_cards(std::path::Path::new(vcard_path)) {
|
||||||
for c in cards {
|
Ok(cards) => {
|
||||||
ret.add_card(c);
|
for c in cards {
|
||||||
|
ret.add_card(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
crate::log(
|
||||||
|
format!("Could not load vcards from {:?}: {}", vcard_path, err),
|
||||||
|
crate::WARN,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,16 +269,24 @@ pub fn load_cards(p: &std::path::Path) -> Result<Vec<Card>> {
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
contents.clear();
|
contents.clear();
|
||||||
std::fs::File::open(&f)?.read_to_string(&mut contents)?;
|
std::fs::File::open(&f)?.read_to_string(&mut contents)?;
|
||||||
if let Ok((_, c)) = parse_card().parse(contents.as_str()) {
|
match parse_card().parse(contents.as_str()) {
|
||||||
for s in c {
|
Ok((_, c)) => {
|
||||||
ret.push(
|
for s in c {
|
||||||
CardDeserializer::from_str(s)
|
ret.push(
|
||||||
.and_then(TryInto::try_into)
|
CardDeserializer::from_str(s)
|
||||||
.map(|mut card| {
|
.and_then(TryInto::try_into)
|
||||||
Card::set_external_resource(&mut card, true);
|
.map(|mut card| {
|
||||||
is_any_valid = true;
|
Card::set_external_resource(&mut card, true);
|
||||||
card
|
is_any_valid = true;
|
||||||
}),
|
card
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
crate::log(
|
||||||
|
format!("Could not parse vcard from {}: {}", f.display(), err),
|
||||||
|
crate::WARN,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue