conf: Make conf validation recognize AccountSettings extra keys
AccountSettings extra keys like `vcard_folder` were not taken into account when validating a config. This commit introduces an AccountSettings::validate_config() method that checks for the presence and validity of this key value. Fixes #349 #349 Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>pull/351/head
parent
0b468d88ad
commit
1fe3619208
|
@ -555,6 +555,7 @@ This is required so that you don't accidentally start meli and find out later th
|
||||||
.collect(),
|
.collect(),
|
||||||
extra: extra.into_iter().collect(),
|
extra: extra.into_iter().collect(),
|
||||||
};
|
};
|
||||||
|
s.validate_config()?;
|
||||||
backends.validate_config(&lowercase_format, &mut s)?;
|
backends.validate_config(&lowercase_format, &mut s)?;
|
||||||
if !s.extra.is_empty() {
|
if !s.extra.is_empty() {
|
||||||
return Err(Error::new(format!(
|
return Err(Error::new(format!(
|
||||||
|
|
|
@ -21,14 +21,14 @@
|
||||||
|
|
||||||
//! Basic mail account configuration to use with
|
//! Basic mail account configuration to use with
|
||||||
//! [`backends`](./backends/index.html)
|
//! [`backends`](./backends/index.html)
|
||||||
use std::collections::HashMap;
|
use std::{collections::HashMap, path::Path};
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backends::SpecialUsageMailbox,
|
backends::SpecialUsageMailbox,
|
||||||
email::Address,
|
email::Address,
|
||||||
error::{Error, Result},
|
error::{Error, ErrorKind, Result},
|
||||||
};
|
};
|
||||||
pub use crate::{SortField, SortOrder};
|
pub use crate::{SortField, SortOrder};
|
||||||
|
|
||||||
|
@ -100,6 +100,34 @@ impl AccountSettings {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn validate_config(&mut self) -> Result<()> {
|
||||||
|
#[cfg(feature = "vcard")]
|
||||||
|
{
|
||||||
|
if let Some(folder) = self.extra.remove("vcard_folder") {
|
||||||
|
let path = Path::new(&folder);
|
||||||
|
|
||||||
|
if !matches!(path.try_exists(), Ok(true)) {
|
||||||
|
return Err(Error::new(format!(
|
||||||
|
"`vcard_folder` path {} does not exist",
|
||||||
|
path.display()
|
||||||
|
))
|
||||||
|
.set_details("`vcard_folder` must be a path of a folder containing .vcf files")
|
||||||
|
.set_kind(ErrorKind::Configuration));
|
||||||
|
}
|
||||||
|
if !path.is_dir() {
|
||||||
|
return Err(Error::new(format!(
|
||||||
|
"`vcard_folder` path {} is not a directory",
|
||||||
|
path.display()
|
||||||
|
))
|
||||||
|
.set_details("`vcard_folder` must be a path of a folder containing .vcf files")
|
||||||
|
.set_kind(ErrorKind::Configuration));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
|
Loading…
Reference in New Issue