X-Git-Url: https://git.r.bdr.sh/rbdr/olden-mail/blobdiff_plain/2fdda21d13ed742bdb52ec3ba74538af83de2bf4..6dca7b58231c8ad3d5808c442ae93f2ba5b44908:/src/configuration.rs diff --git a/src/configuration.rs b/src/configuration.rs index 49cd991..15216a8 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -9,7 +9,7 @@ use std::sync::Arc; use thiserror::Error; #[derive(Error, Debug)] -pub enum ConfigurationError { +pub enum Error { #[error("Environment variable {0} not set.")] MissingEnvVar(String), #[error("Failed to parse {0}.")] @@ -35,19 +35,19 @@ pub struct Configuration { impl Configuration { /// Creates a new configuration object by reading the environment /// variables. Exits if the right ones aren't found. - pub fn new() -> Result { + pub fn new() -> Result { Ok(Configuration { imap_configuration: Arc::new(Proxy { local_port: get_env_number("LOCAL_IMAP_PORT", 143)?, bind_address: get_env_var("LOCAL_IMAP_BIND_ADDRESS", Some("0.0.0.0".to_string()))?, - remote_host: get_env_var("REMOTE_IMAP_DOMAIN", None)?, + remote_host: get_env_var("REMOTE_IMAP_HOST", None)?, remote_port: get_env_number("REMOTE_IMAP_PORT", 993)?, protocol: "IMAP", }), smtp_configuration: Arc::new(Proxy { local_port: get_env_number("LOCAL_SMTP_PORT", 25)?, bind_address: get_env_var("LOCAL_SMTP_BIND_ADDRESS", Some("0.0.0.0".to_string()))?, - remote_host: get_env_var("REMOTE_SMTP_DOMAIN", None)?, + remote_host: get_env_var("REMOTE_SMTP_HOST", None)?, remote_port: get_env_number("REMOTE_SMTP_PORT", 993)?, protocol: "SMTP", }), @@ -56,23 +56,23 @@ impl Configuration { } /// Get an environment variable or return an error. -fn get_env_var(name: &str, default: Option) -> Result { +fn get_env_var(name: &str, default: Option) -> Result { match env::var(name) { Ok(value) => Ok(value), Err(_) => match default { Some(default_value) => Ok(default_value), - None => Err(ConfigurationError::MissingEnvVar(name.to_string())), + None => Err(Error::MissingEnvVar(name.to_string())), }, } } /// Get an environment variable and parse it as a number. Return a default /// if not set. -fn get_env_number(name: &str, default: u16) -> Result { +fn get_env_number(name: &str, default: u16) -> Result { match env::var(name) { Ok(value) => value .parse() - .map_err(|_| ConfigurationError::ParseError(name.to_string())), + .map_err(|_| Error::ParseError(name.to_string())), Err(_) => Ok(default), } }