rspamd_client/
config.rs

1//!
2//! ## Configuration for rspamd-client
3//!
4//! The `Config` struct allows you to customize various aspects of the client, including the base URL, proxy settings, and TLS settings.
5//!
6
7use std::collections::HashMap;
8use std::iter::IntoIterator;
9use typed_builder::TypedBuilder;
10
11/// Custom TLS settings for the Rspamd client
12#[derive(Debug, Clone, PartialEq)]
13pub struct TlsSettings {
14    /// Path to the TLS certificate file
15    pub cert_path: String,
16
17    /// Path to the TLS key file
18    pub key_path: String,
19
20    /// Optional path to the TLS CA file
21    pub ca_path: Option<String>,
22}
23
24/// Proxy configuration for the Rspamd client
25#[derive(Debug, Clone, PartialEq)]
26pub struct ProxyConfig {
27    /// Proxy server URL
28    pub proxy_url: String,
29
30    /// Optional username for proxy authentication
31    pub username: Option<String>,
32
33    /// Optional password for proxy authentication
34    pub password: Option<String>,
35}
36
37#[derive(TypedBuilder, Debug, PartialEq, Default)]
38pub struct EnvelopeData {
39    /// Sender email address
40    #[builder(default, setter(strip_option))]
41    pub from: Option<String>,
42
43    /// Recipients email addresses
44    #[builder(default)]
45    pub rcpt: Vec<String>,
46
47    /// Optional IP address of the sender
48    #[builder(default, setter(strip_option))]
49    pub ip: Option<String>,
50
51    /// Optional IP of the sender
52    #[builder(default, setter(strip_option))]
53    pub user: Option<String>,
54
55    /// Optional HELO string
56    #[builder(default, setter(strip_option))]
57    pub helo: Option<String>,
58
59    /// Optional hostname
60    #[builder(default, setter(strip_option))]
61    pub hostname: Option<String>,
62
63    /// Optional additional headers
64    #[builder(default)]
65    pub additional_headers: HashMap<String, String>,
66}
67
68impl IntoIterator for EnvelopeData {
69    type Item = (String, String);
70    type IntoIter = std::collections::hash_map::IntoIter<String, String>;
71
72    /// Convert the EnvelopeData struct into an iterator
73    fn into_iter(mut self) -> Self::IntoIter {
74        // We add all options to the additional headers
75        if let Some(from) = self.from {
76            self.additional_headers.insert("From".to_string(), from);
77        }
78        if let Some(ip) = self.ip {
79            self.additional_headers.insert("IP".to_string(), ip);
80        }
81        if let Some(user) = self.user {
82            self.additional_headers.insert("User".to_string(), user);
83        }
84        if let Some(helo) = self.helo {
85            self.additional_headers.insert("Helo".to_string(), helo);
86        }
87        if let Some(hostname) = self.hostname {
88            self.additional_headers.insert("Hostname".to_string(), hostname);
89        }
90        for rcpt in self.rcpt {
91            self.additional_headers.insert("Rcpt".to_string(), rcpt);
92        }
93        self.additional_headers.into_iter()
94    }
95}
96
97/// Configuration for Rspamd client
98#[derive(TypedBuilder,Debug, PartialEq)]
99pub struct Config {
100    /// Base URL of Rspamd server
101    pub base_url: String,
102
103    /// Optional API key for authentication
104    #[builder(default, setter(strip_option))]
105    pub password: Option<String>,
106
107    /// Timeout duration for requests
108    #[builder(default=30.0)]
109    pub timeout: f64,
110
111    /// Number of retries for requests
112    #[builder(default=1)]
113    pub retries: u32,
114
115    /// Custom TLS settings for the asynchronous client
116    #[builder(default, setter(strip_option))]
117    pub tls_settings: Option<TlsSettings>,
118
119    /// Proxy configuration for the asynchronous client
120    #[builder(default, setter(strip_option))]
121    pub proxy_config: Option<ProxyConfig>,
122
123    /// Use zstd compression
124    #[builder(default=true)]
125    pub zstd: bool,
126
127    /// Encryption key if using native HTTPCrypt encryption (must be in Rspamd base32 format)
128    #[builder(default, setter(strip_option))]
129    pub encryption_key: Option<String>,
130}