Limit rate of MDNs

New ratelimiter module counts number of sent messages and calculates
the time until more messages can be sent.

Rate limiter is currently applied only to MDNs. Other messages are
sent without rate limiting even if quota is exceeded, but MDNs are not
sent until ratelimiter allows sending again.
This commit is contained in:
link2xt
2022-06-04 20:33:44 +00:00
parent e993b37f1e
commit c0a17df344
7 changed files with 202 additions and 31 deletions

View File

@@ -32,6 +32,11 @@ impl Smtp {
message: &[u8],
rowid: i64,
) -> Result<()> {
// Notify ratelimiter about sent message regardless of whether quota is exceeded or not.
// Checking whether sending is allowed for low-priority messages should be done by the
// caller.
context.ratelimit.write().await.send();
let message_len_bytes = message.len();
let mut chunk_size = DEFAULT_MAX_SMTP_RCPT_TO;