diff --git a/filtermail/src/inbound.rs b/filtermail/src/inbound.rs index 4eabbf8f..2fc47b59 100644 --- a/filtermail/src/inbound.rs +++ b/filtermail/src/inbound.rs @@ -32,7 +32,7 @@ impl SmtpHandler for IncomingBeforeQueueHandler { } fn check_data(&self, envelope: &Envelope) -> Result<(), String> { - log::info!("Processing DATA message from {}", envelope.mail_from); + log::debug!("Processing DATA message from {}", envelope.mail_from); let message = match parse_mail(&envelope.data) { Ok(m) => m, @@ -40,16 +40,16 @@ impl SmtpHandler for IncomingBeforeQueueHandler { }; let mail_encrypted = check_encrypted(&message, false); - log::debug!("mail_encrypted: {}", mail_encrypted); + log::debug!("mail_encrypted: {mail_encrypted}"); log::debug!("is_securejoin: {}", is_securejoin(&message)); // Allow encrypted or securejoin messages if mail_encrypted || is_securejoin(&message) { - log::info!("Incoming: Filtering encrypted mail."); + log::debug!("Incoming: Filtering encrypted mail."); return Ok(()); } - log::info!("Incoming: Filtering unencrypted mail."); + log::debug!("Incoming: Filtering unencrypted mail."); // Allow cleartext mailer-daemon messages if let Some(auto_submitted) = message.headers.get_first_value("Auto-Submitted") @@ -72,7 +72,7 @@ impl SmtpHandler for IncomingBeforeQueueHandler { for recipient in &envelope.rcpt_to { if !self.config.is_cleartext_ok(recipient) { - log::info!("Rejected unencrypted mail."); + log::warn!("Rejected unencrypted email from: {}", envelope.mail_from); return Err(ENCRYPTION_NEEDED_523.to_string()); } } @@ -81,7 +81,7 @@ impl SmtpHandler for IncomingBeforeQueueHandler { } async fn reinject_mail(&self, envelope: &Envelope) -> Result<(), String> { - log::info!("Re-injecting the mail that passed checks"); + log::debug!("Re-injecting the mail that passed checks"); let mailer = AsyncSmtpTransport::::builder_dangerous("localhost") .port(self.config.postfix_reinject_port_incoming) diff --git a/filtermail/src/main.rs b/filtermail/src/main.rs index 129af418..74b356ac 100644 --- a/filtermail/src/main.rs +++ b/filtermail/src/main.rs @@ -55,7 +55,7 @@ async fn main() { let handler = Arc::new(OutgoingBeforeQueueHandler::new(config.clone())); let addr = format!("127.0.0.1:{}", config.filtermail_smtp_port); let max_size = config.max_message_size; - log::debug!("Outgoing SMTP server listening on {}", addr); + log::debug!("Outgoing SMTP server listening on {addr}"); if let Err(e) = run_smtp_server(&addr, handler, max_size).await { eprintln!("Server error: {}", e); @@ -65,7 +65,7 @@ async fn main() { let handler = Arc::new(IncomingBeforeQueueHandler::new(config.clone())); let addr = format!("127.0.0.1:{}", config.filtermail_smtp_port_incoming); let max_size = config.max_message_size; - log::debug!("Incoming SMTP server listening on {}", addr); + log::debug!("Incoming SMTP server listening on {addr}"); if let Err(e) = run_smtp_server(&addr, handler, max_size).await { eprintln!("Server error: {}", e); diff --git a/filtermail/src/openpgp.rs b/filtermail/src/openpgp.rs index e221c8fc..04dd85b5 100644 --- a/filtermail/src/openpgp.rs +++ b/filtermail/src/openpgp.rs @@ -71,20 +71,14 @@ fn check_openpgp_payload(payload: &[u8]) -> Result { // Symmetrically Encrypted and Integrity Protected Data Packet (SEIPD) // // This is the only place where this function may return `True`. - log::debug!( - "check_openpgp_payload: i={i} packat_type_id={}", - packet_type_id - ); + log::debug!("check_openpgp_payload: i={i} packat_type_id={packet_type_id}"); return Ok(packet_type_id == 18); } else if ![1, 3].contains(&packet_type_id) { // All packets except the last one must be either // Public-Key Encrypted Session Key Packet (PKESK) // or // Symmetric-Key Encrypted Session Key Packet (SKESK) - log::debug!( - "check_openpgp_payload: i={i} packet_type_id={}", - packet_type_id - ); + log::debug!("check_openpgp_payload: i={i} packet_type_id={packet_type_id}"); return Ok(false); } } diff --git a/filtermail/src/outbound.rs b/filtermail/src/outbound.rs index dee3e60a..85452709 100644 --- a/filtermail/src/outbound.rs +++ b/filtermail/src/outbound.rs @@ -30,7 +30,7 @@ impl OutgoingBeforeQueueHandler { #[async_trait] impl SmtpHandler for OutgoingBeforeQueueHandler { fn handle_mail(&self, address: &str) -> Result<(), String> { - log::info!("handle_MAIL from {}", address); + log::debug!("handle_MAIL from {address}"); let parts: Vec<&str> = address.split('@').collect(); if parts.len() != 2 { @@ -40,15 +40,15 @@ impl SmtpHandler for OutgoingBeforeQueueHandler { let max_sent = self.config.max_user_send_per_minute; let mut limiter = self.send_rate_limiter.lock().unwrap(); if !limiter.is_sending_allowed(address, max_sent) { - log::debug!("Rate limit exceeded for {}", address); - return Err(format!("450 4.7.1: Too much mail from {}", address)); + log::debug!("Rate limit exceeded for {address}"); + return Err(format!("450 4.7.1: Too much mail from {address}")); } Ok(()) } fn check_data(&self, envelope: &Envelope) -> Result<(), String> { - log::info!("Processing DATA message from {}", envelope.mail_from); + log::debug!("Processing DATA message from {}", envelope.mail_from); let message = match parse_mail(&envelope.data) { Ok(m) => m, @@ -76,11 +76,11 @@ impl SmtpHandler for OutgoingBeforeQueueHandler { // Allow encrypted or securejoin messages if mail_encrypted || is_securejoin(&message) { - log::info!("Outgoing: Filtering encrypted mail."); + log::debug!("Outgoing: Filtering encrypted mail."); return Ok(()); } - log::info!("Outgoing: Filtering unencrypted mail."); + log::debug!("Outgoing: Filtering unencrypted mail."); // Allow passthrough senders if self @@ -104,7 +104,7 @@ impl SmtpHandler for OutgoingBeforeQueueHandler { for recipient in &envelope.rcpt_to { if !recipient_matches_passthrough(recipient, &self.config.passthrough_recipients) { - log::info!("Rejected unencrypted mail."); + log::warn!("Rejected unencrypted mail from: {}", envelope.mail_from); return Err(ENCRYPTION_NEEDED_523.to_string()); } } @@ -113,7 +113,7 @@ impl SmtpHandler for OutgoingBeforeQueueHandler { } async fn reinject_mail(&self, envelope: &Envelope) -> Result<(), String> { - log::info!("Re-injecting the mail that passed checks"); + log::debug!("Re-injecting the mail that passed checks"); let mailer = AsyncSmtpTransport::::builder_dangerous("localhost") .port(self.config.postfix_reinject_port) diff --git a/filtermail/src/smtp_server.rs b/filtermail/src/smtp_server.rs index ff59f0f6..431b846f 100644 --- a/filtermail/src/smtp_server.rs +++ b/filtermail/src/smtp_server.rs @@ -28,10 +28,10 @@ pub trait SmtpHandler: Send + Sync { /// Handles the DATA command. async fn handle_data(&self, envelope: &Envelope) -> Result { - log::info!("handle_DATA before-queue"); + log::debug!("handle_DATA before-queue"); self.check_data(envelope)?; self.reinject_mail(envelope).await.map_err(|e| { - log::warn!("Failed to reinject mail: {}", e); + log::warn!("Failed to reinject mail: {e}"); e })?; Ok("250 OK".to_string()) @@ -56,7 +56,7 @@ where let handler = handler.clone(); tokio::spawn(async move { if let Err(e) = handle_connection(socket, handler, max_size).await { - log::error!("Error handling connection: {}", e); + log::error!("Error handling connection: {e}"); } }); } @@ -98,7 +98,7 @@ where break 'connection; }; - log::debug!("Received: {}", cmd); + log::debug!("Received: {cmd}"); if cmd.to_uppercase().starts_with("HELO") || cmd.to_uppercase().starts_with("EHLO") { writer.write_all(b"250 OK\r\n").await?; @@ -115,7 +115,7 @@ where } } } else { - log::debug!("Invalid MAIL FROM command. Can't extract address."); + log::warn!("Invalid MAIL FROM command. Can't extract address. Received: {cmd}"); writer .write_all(b"500 Invalid address in MAIL FROM\r\n") .await?; @@ -159,13 +159,13 @@ where // Process the message match handler.handle_data(&envelope).await { Ok(response) => { - log::debug!("Sent: {}", response); + log::debug!("Sent: {response}"); writer .write_all(format!("{}\r\n", response).as_bytes()) .await?; } Err(e) => { - log::debug!("Sent: {}", e); + log::debug!("Sent: {e}"); writer.write_all(format!("{}\r\n", e).as_bytes()).await?; } }