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
use crate::send_grid::{BccSettings, BypassListManagement, FooterSettings, SandboxMode, SpamCheck};
use serde_derive::{Deserialize, Serialize};

/// Represents a collection of different mail settings that specify how an email message is handled.
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct MailSettings {
    /// The BCC settings for the email message.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bcc: Option<BccSettings>,
    /// The bypass list management settings for the email message.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bypass_list_management: Option<BypassListManagement>,
    /// The footer settings for the email message.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub footer: Option<FooterSettings>,
    /// The sandbox mode settings for the email message.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sandbox_mode: Option<SandboxMode>,
    /// The spam check settings for the email message.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub spam_check: Option<SpamCheck>,
}

#[cfg(test)]
mod tests {
    use super::*;
    use serde_json::to_string;

    #[test]
    fn it_serializes_to_json() {
        let json = to_string(&MailSettings {
            bcc: Some(BccSettings {
                enable: true,
                email: "foo@example.com".to_owned(),
            }),
            bypass_list_management: Some(BypassListManagement { enable: true }),
            footer: Some(FooterSettings {
                enable: true,
                text: "hello".to_owned(),
                html: "world".to_owned(),
            }),
            sandbox_mode: Some(SandboxMode { enable: true }),
            spam_check: Some(SpamCheck {
                enable: true,
                threshold: 7,
                post_to_url: "https://example.com".to_owned(),
            }),
        })
        .unwrap();

        assert_eq!(json, r#"{"bcc":{"enable":true,"email":"foo@example.com"},"bypass_list_management":{"enable":true},"footer":{"enable":true,"text":"hello","html":"world"},"sandbox_mode":{"enable":true},"spam_check":{"enable":true,"threshold":7,"post_to_url":"https://example.com"}}"#);
    }
}