From dc3d68214e2cd4b5f86279a7fa7b7d64c341b446 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Fri, 24 Jan 2025 20:34:35 +0100 Subject: First approach --- src/configuration.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/configuration.rs (limited to 'src/configuration.rs') diff --git a/src/configuration.rs b/src/configuration.rs new file mode 100644 index 0000000..1437594 --- /dev/null +++ b/src/configuration.rs @@ -0,0 +1,45 @@ +use std::env; +use std::sync::Arc; + +pub struct ProxyConfiguration { + pub local_port: u16, + pub remote_domain: String, + pub remote_port: u16, + pub protocol: &'static str, +} + +pub struct Configuration { + pub imap_configuration: Arc, + pub smtp_configuration: Arc, +} + +impl Configuration { + pub fn new() -> Self { + Configuration { + imap_configuration: Arc::new(ProxyConfiguration { + local_port: env::var("LOCAL_IMAP_PORT") + .expect("LOCAL_IMAP_PORT not set") + .parse() + .expect("Invalid LOCAL_IMAP_PORT"), + remote_domain: env::var("REMOTE_IMAP_DOMAIN").expect("REMOTE_IMAP_DOMAIN not set"), + remote_port: env::var("REMOTE_IMAP_PORT") + .expect("REMOTE_IMAP_PORT not set") + .parse() + .expect("Invalid REMOTE_IMAP_PORT"), + protocol: "IMAP", + }), + smtp_configuration: Arc::new(ProxyConfiguration { + local_port: env::var("LOCAL_SMTP_PORT") + .expect("LOCAL_SMTP_PORT not set") + .parse() + .expect("Invalid LOCAL_SMTP_PORT"), + remote_domain: env::var("REMOTE_SMTP_DOMAIN").expect("REMOTE_SMTP_DOMAIN not set"), + remote_port: env::var("REMOTE_SMTP_PORT") + .expect("REMOTE_SMTP_PORT not set") + .parse() + .expect("Invalid REMOTE_SMTP_PORT"), + protocol: "SMTP", + }), + } + } +} -- cgit