mirror of
https://github.com/chatmail/relay.git
synced 2026-08-10 10:30:51 +00:00
refactor: Implement Display for AddressDomain
Signed-off-by: Jagoda Ślązak <jslazak@jslazak.com>
This commit is contained in:
@@ -68,10 +68,7 @@ where
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
log::trace!(
|
||||
"Trying to acquire a permit for {} worker...",
|
||||
domain.as_ref()
|
||||
);
|
||||
log::trace!("Trying to acquire a permit for {domain} worker...",);
|
||||
if let Some(permit) = self.workers.get_permit(&domain) {
|
||||
transaction.state.permits.insert(domain, permit);
|
||||
}
|
||||
|
||||
@@ -100,10 +100,7 @@ where
|
||||
if let Some(w) = &worker
|
||||
&& w.handle.is_finished()
|
||||
{
|
||||
log::error!(
|
||||
"Worker for destination {} crashed! Restarting...",
|
||||
destination.as_ref()
|
||||
);
|
||||
log::error!("Worker for destination {destination} crashed! Restarting...",);
|
||||
worker = None;
|
||||
{
|
||||
let mut map = self.inner.write();
|
||||
@@ -180,10 +177,7 @@ impl Worker {
|
||||
.map(|id| id.to_string())
|
||||
.unwrap_or("?".to_string());
|
||||
|
||||
log::info!(
|
||||
"Starting worker {worker_id} for destination {}",
|
||||
destination.as_ref()
|
||||
);
|
||||
log::info!("Starting worker {worker_id} for destination {destination}");
|
||||
|
||||
let tls_resumption_store = Arc::new(rustls::client::ClientSessionMemoryCache::new(256));
|
||||
let https_client = HttpsClient::new(tls_resumption_store.clone())?;
|
||||
@@ -206,8 +200,7 @@ impl Worker {
|
||||
.await;
|
||||
if message.response_tx.send(result).is_err() {
|
||||
log::error!(
|
||||
"Worker {worker_id} ({}) failed to send response to transport handler.",
|
||||
destination.as_ref()
|
||||
"Worker {worker_id} ({destination}) failed to send response to transport handler."
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use hickory_resolver::{TokioResolver, proto::dnssec::TrustAnchors};
|
||||
use mailparse::MailAddr;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
@@ -88,6 +89,24 @@ impl AsRef<str> for AddressDomain {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for AddressDomain {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
AddressDomain::Literal(addr) => {
|
||||
// naive check, but should be enough as long as `AddressDomain`
|
||||
// is constructed using parse/from_str.
|
||||
write!(f, "[")?;
|
||||
if addr.contains(':') {
|
||||
write!(f, "IPv6:")?;
|
||||
}
|
||||
write!(f, "{addr}]")?;
|
||||
}
|
||||
AddressDomain::Name(domain) => write!(f, "{domain}")?,
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Logs email to `/tmp/filtermail-rejected/<reason>/<timestamp>.eml`
|
||||
/// and returns the file path.
|
||||
///
|
||||
@@ -160,4 +179,20 @@ mod tests {
|
||||
let result = AddressDomain::from_str(input).ok();
|
||||
assert_eq!(result, expected);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case::domain(AddressDomain::Name("example.org".to_string()), "example.org")]
|
||||
#[case::ipv4(AddressDomain::Literal("192.0.2.0".to_string()), "192.0.2.0")]
|
||||
#[case::ipv6(AddressDomain::Literal("2001:db8::1".to_string()), "2001:db8::1")]
|
||||
fn test_address_domain_as_ref(#[case] input: AddressDomain, #[case] expected: &str) {
|
||||
assert_eq!(input.as_ref(), expected);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case::domain(AddressDomain::Name("example.org".to_string()), "example.org")]
|
||||
#[case::ipv4(AddressDomain::Literal("192.0.2.0".to_string()), "[192.0.2.0]")]
|
||||
#[case::ipv6(AddressDomain::Literal("2001:db8::1".to_string()), "[IPv6:2001:db8::1]")]
|
||||
fn test_address_domain_display(#[case] input: AddressDomain, #[case] expected: &str) {
|
||||
assert_eq!(&format!("{input}"), expected);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user