From 4eca415e7b541e55fa5152d39343549c92b80bae Mon Sep 17 00:00:00 2001 From: mdecimus Date: Mon, 20 Jan 2025 17:13:32 +0100 Subject: [PATCH] Update SMTP status codes (#1109) --- crates/jmap/src/api/form.rs | 2 +- crates/smtp/src/inbound/auth.rs | 2 +- crates/smtp/src/inbound/data.rs | 2 +- crates/smtp/src/inbound/mail.rs | 2 +- crates/smtp/src/inbound/rcpt.rs | 8 ++++---- crates/smtp/src/inbound/spawn.rs | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/jmap/src/api/form.rs b/crates/jmap/src/api/form.rs index 48284b2b..7b1da34c 100644 --- a/crates/jmap/src/api/form.rs +++ b/crates/jmap/src/api/form.rs @@ -101,7 +101,7 @@ impl FormHandler for Server { if let Some(domain) = from_email.rsplit_once('@').and_then(|(local, domain)| { if !local.is_empty() && domain.contains('.') - && psl::suffix(domain.as_bytes()).is_some() + && psl::domain(domain.as_bytes()).is_some_and(|d| d.suffix().typ().is_some()) { Some(domain) } else { diff --git a/crates/smtp/src/inbound/auth.rs b/crates/smtp/src/inbound/auth.rs index 3a728f1a..343afccc 100644 --- a/crates/smtp/src/inbound/auth.rs +++ b/crates/smtp/src/inbound/auth.rs @@ -204,7 +204,7 @@ impl Session { SpanId = self.data.session_id, ); - self.write(b"421 4.3.0 Too many authentication errors, disconnecting.\r\n") + self.write(b"455 4.3.0 Too many authentication errors, disconnecting.\r\n") .await?; Err(()) } diff --git a/crates/smtp/src/inbound/data.rs b/crates/smtp/src/inbound/data.rs index dc2ffd08..93678ef1 100644 --- a/crates/smtp/src/inbound/data.rs +++ b/crates/smtp/src/inbound/data.rs @@ -850,7 +850,7 @@ impl Session { Limit = self.data.messages_sent ); - self.write(b"451 4.4.5 Maximum number of messages per session exceeded.\r\n") + self.write(b"452 4.4.5 Maximum number of messages per session exceeded.\r\n") .await?; Ok(false) } diff --git a/crates/smtp/src/inbound/mail.rs b/crates/smtp/src/inbound/mail.rs index 61f85e64..01fec605 100644 --- a/crates/smtp/src/inbound/mail.rs +++ b/crates/smtp/src/inbound/mail.rs @@ -513,7 +513,7 @@ impl Session { ); self.data.mail_from = None; - self.write(b"451 4.4.5 Rate limit exceeded, try again later.\r\n") + self.write(b"452 4.4.5 Rate limit exceeded, try again later.\r\n") .await } } diff --git a/crates/smtp/src/inbound/rcpt.rs b/crates/smtp/src/inbound/rcpt.rs index 5eea7adb..760d620e 100644 --- a/crates/smtp/src/inbound/rcpt.rs +++ b/crates/smtp/src/inbound/rcpt.rs @@ -50,7 +50,7 @@ impl Session { SpanId = self.data.session_id, Limit = self.params.rcpt_max, ); - return self.write(b"451 4.5.3 Too many recipients.\r\n").await; + return self.write(b"455 4.5.3 Too many recipients.\r\n").await; } // Verify parameters @@ -347,7 +347,7 @@ impl Session { return self .write( concat!( - "422 4.2.2 Greylisted, please try ", + "452 4.2.2 Greylisted, please try ", "again in a few moments.\r\n" ) .as_bytes(), @@ -385,7 +385,7 @@ impl Session { self.data.rcpt_to.pop(); return self - .write(b"451 4.4.5 Rate limit exceeded, try again later.\r\n") + .write(b"452 4.4.5 Rate limit exceeded, try again later.\r\n") .await; } @@ -448,7 +448,7 @@ impl Session { if !has_too_many_errors { self.write(response).await } else { - self.write(b"421 4.3.0 Too many errors, disconnecting.\r\n") + self.write(b"451 4.3.0 Too many errors, disconnecting.\r\n") .await?; Err(()) } diff --git a/crates/smtp/src/inbound/spawn.rs b/crates/smtp/src/inbound/spawn.rs index ee1b367d..2ceca007 100644 --- a/crates/smtp/src/inbound/spawn.rs +++ b/crates/smtp/src/inbound/spawn.rs @@ -169,7 +169,7 @@ impl Session { } } else if bytes_read > self.data.bytes_left { self - .write(format!("451 4.7.28 {} Session exceeded transfer quota.\r\n", self.hostname).as_bytes()) + .write(format!("452 4.7.28 {} Session exceeded transfer quota.\r\n", self.hostname).as_bytes()) .await .ok(); @@ -181,7 +181,7 @@ impl Session { break; } else { self - .write(format!("453 4.3.2 {} Session open for too long.\r\n", self.hostname).as_bytes()) + .write(format!("421 4.3.2 {} Session open for too long.\r\n", self.hostname).as_bytes()) .await .ok(); @@ -246,7 +246,7 @@ impl Session { Reason = "Server shutting down", CausedBy = trc::location!() ); - self.write(b"421 4.3.0 Server shutting down.\r\n").await.ok(); + self.write(format!("421 4.3.0 {} Server shutting down.\r\n", self.hostname).as_bytes()).await.ok(); break; } };