conf: Make conf validation recognize AccountSettings extra keys
Run cargo lints / Lint on ${{ matrix.build }} (linux-amd64, ubuntu-latest, stable, x86_64-unknown-linux-gnu) (pull_request) Successful in 9m19s Details
Run Tests / Test on ${{ matrix.build }} (linux-amd64, ubuntu-latest, stable, x86_64-unknown-linux-gnu) (pull_request) Successful in 14m39s Details

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
Manos Pitsidianakis 2024-02-04 14:47:22 +02:00
parent 0b468d88ad
commit 1fe3619208
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
2 changed files with 31 additions and 2 deletions

View File

@ -555,6 +555,7 @@ This is required so that you don't accidentally start meli and find out later th
.collect(),
extra: extra.into_iter().collect(),
};
s.validate_config()?;
backends.validate_config(&lowercase_format, &mut s)?;
if !s.extra.is_empty() {
return Err(Error::new(format!(

View File

@ -21,14 +21,14 @@
//! Basic mail account configuration to use with
//! [`backends`](./backends/index.html)
use std::collections::HashMap;
use std::{collections::HashMap, path::Path};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use crate::{
backends::SpecialUsageMailbox,
email::Address,
error::{Error, Result},
error::{Error, ErrorKind, Result},
};
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)]