1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::repository::email::EmailClientType;
use lightspeed_core::model::boolean::Boolean;
use structopt::StructOpt;

#[derive(Debug, Clone, StructOpt)]
#[structopt(rename_all = "kebab-case")]
pub struct EmailClientConfig {
    #[structopt(long, env = "LS_EMAIL_CLIENT_TYPE", default_value = "full")]
    pub client_type: EmailClientType,

    #[structopt(long, env = "LS_EMAIL_SERVER_PORT", default_value = "1025")]
    pub server_port: u16,

    #[structopt(long, env = "LS_EMAIL_SERVER_ADDRESS", default_value = "127.0.0.1")]
    pub server_address: String,

    #[structopt(long, env = "LS_EMAIL_SERVER_USERNAME", default_value = "")]
    pub server_username: String,

    #[structopt(long, env = "LS_EMAIL_SERVER_PASSWORD", default_value = "")]
    pub server_password: String,

    #[structopt(long, env = "LS_EMAIL_SERVER_USE_TLS", default_value = "false")]
    pub server_use_tls: Boolean,

    #[structopt(long, env = "LS_EMAIL_FORWARD_ALL_EMAILS_TO_FIXED_RECIPIENTS", value_delimiter = ";")]
    pub forward_all_emails_to_fixed_recipients: Option<Vec<String>>,
}

impl EmailClientConfig {
    pub fn build() -> Self {
        let app = Self::clap().setting(structopt::clap::AppSettings::AllowExternalSubcommands);
        Self::from_clap(&app.get_matches())
    }
}

#[cfg(test)]
mod test {

    use super::*;

    #[test]
    fn should_build_config() {
        let config = EmailClientConfig::build();
        assert!(config.forward_all_emails_to_fixed_recipients.is_none());
    }

    /*
    #[test]
    fn should_build_optional_fixed_recipients() {

        std::env::set_var("LS_EMAIL_FORWARD_ALL_EMAILS_TO_FIXED_RECIPIENTS", "to@me.com;to@they.com");

        let config = EmailClientConfig::build();
        assert_eq!(Some(vec!["to@me.com".to_owned(), "to@they.com".to_owned()]), config.forward_all_emails_to_fixed_recipients);

    }
    */
}