diff options
Diffstat (limited to 'src/configuration.rs')
| -rw-r--r-- | src/configuration.rs | 45 |
1 files changed, 45 insertions, 0 deletions
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<ProxyConfiguration>, + pub smtp_configuration: Arc<ProxyConfiguration>, +} + +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", + }), + } + } +} |