]> git.r.bdr.sh - rbdr/olden-mail/blobdiff - src/configuration.rs
Set cargo config only on CI
[rbdr/olden-mail] / src / configuration.rs
index 49cd991ab8b3a6cd05647c10cddb37eb8ab6d7e0..1c8741d71b96490feb0d286aa9621a4451a73b5b 100644 (file)
@@ -9,7 +9,7 @@ use std::sync::Arc;
 use thiserror::Error;
 
 #[derive(Error, Debug)]
 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}.")]
     #[error("Environment variable {0} not set.")]
     MissingEnvVar(String),
     #[error("Failed to parse {0}.")]
@@ -35,20 +35,20 @@ pub struct Configuration {
 impl Configuration {
     /// Creates a new configuration object by reading the environment
     /// variables. Exits if the right ones aren't found.
 impl Configuration {
     /// Creates a new configuration object by reading the environment
     /// variables. Exits if the right ones aren't found.
-    pub fn new() -> Result<Self, ConfigurationError> {
+    pub fn new() -> Result<Self, Error> {
         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()))?,
         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_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_port: get_env_number("REMOTE_SMTP_PORT", 993)?,
+                remote_host: get_env_var("REMOTE_SMTP_HOST", None)?,
+                remote_port: get_env_number("REMOTE_SMTP_PORT", 465)?,
                 protocol: "SMTP",
             }),
         })
                 protocol: "SMTP",
             }),
         })
@@ -56,23 +56,23 @@ impl Configuration {
 }
 
 /// Get an environment variable or return an error.
 }
 
 /// Get an environment variable or return an error.
-fn get_env_var(name: &str, default: Option<String>) -> Result<String, ConfigurationError> {
+fn get_env_var(name: &str, default: Option<String>) -> Result<String, Error> {
     match env::var(name) {
         Ok(value) => Ok(value),
         Err(_) => match default {
             Some(default_value) => Ok(default_value),
     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.
         },
     }
 }
 
 /// 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<u16, ConfigurationError> {
+fn get_env_number(name: &str, default: u16) -> Result<u16, Error> {
     match env::var(name) {
         Ok(value) => value
             .parse()
     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),
     }
 }
         Err(_) => Ok(default),
     }
 }