use std::time::Duration;
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum Mode {
#[default]
Local,
Domain,
Mailbox,
}
#[cfg(feature = "smtp")]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum CatchAll {
#[default]
Disabled,
OneProbe,
}
#[cfg(feature = "smtp")]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum TlsPolicy {
#[default]
Opportunistic,
Required,
}
#[cfg(feature = "smtp")]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct SmtpPolicy {
tls: TlsPolicy,
catch_all: CatchAll,
}
#[cfg(feature = "smtp")]
impl SmtpPolicy {
#[must_use]
pub const fn tls(self) -> TlsPolicy {
self.tls
}
#[must_use]
pub const fn catch_all(self) -> CatchAll {
self.catch_all
}
#[must_use]
pub const fn with_tls(mut self, tls: TlsPolicy) -> Self {
self.tls = tls;
self
}
#[must_use]
pub const fn with_catch_all(mut self, catch_all: CatchAll) -> Self {
self.catch_all = catch_all;
self
}
}
#[cfg(feature = "smtp")]
impl Default for SmtpPolicy {
fn default() -> Self {
Self {
tls: TlsPolicy::Opportunistic,
catch_all: CatchAll::Disabled,
}
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Limits {
input_bytes: usize,
concurrent_validations: usize,
}
impl Limits {
pub const MAX_CONCURRENT_VALIDATIONS: usize = 1_024;
#[must_use]
pub const fn with_input_bytes(mut self, input_bytes: usize) -> Self {
self.input_bytes = input_bytes;
self
}
#[must_use]
pub const fn with_concurrent_validations(mut self, concurrent_validations: usize) -> Self {
self.concurrent_validations = concurrent_validations;
self
}
#[must_use]
pub const fn input_bytes(self) -> usize {
self.input_bytes
}
#[must_use]
pub const fn concurrent_validations(self) -> usize {
self.concurrent_validations
}
}
impl Default for Limits {
fn default() -> Self {
Self {
input_bytes: crate::Address::MAX_INPUT_BYTES,
concurrent_validations: 16,
}
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Timeouts {
dns: Duration,
connect: Duration,
command: Duration,
total: Duration,
}
impl Timeouts {
#[must_use]
pub const fn with_dns(mut self, dns: Duration) -> Self {
self.dns = dns;
self
}
#[must_use]
pub const fn with_connect(mut self, connect: Duration) -> Self {
self.connect = connect;
self
}
#[must_use]
pub const fn with_command(mut self, command: Duration) -> Self {
self.command = command;
self
}
#[must_use]
pub const fn with_total(mut self, total: Duration) -> Self {
self.total = total;
self
}
#[must_use]
pub const fn dns(self) -> Duration {
self.dns
}
#[must_use]
pub const fn connect(self) -> Duration {
self.connect
}
#[must_use]
pub const fn command(self) -> Duration {
self.command
}
#[must_use]
pub const fn total(self) -> Duration {
self.total
}
}
impl Default for Timeouts {
fn default() -> Self {
Self {
dns: Duration::from_secs(3),
connect: Duration::from_secs(5),
command: Duration::from_secs(5),
total: Duration::from_secs(15),
}
}
}