mirror of
https://github.com/chatmail/relay.git
synced 2026-09-13 19:03:14 +00:00
feat: Add experimental option to disable mailboxes (#108)
Signed-off-by: Jagoda Ślązak <jslazak@jslazak.com>
This commit is contained in:
@@ -72,17 +72,29 @@ impl Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if not encrypted mail is allowed for the given address.
|
/// Check if a specific flag file exists for the given address.
|
||||||
pub fn is_cleartext_ok(&self, addr: &str) -> bool {
|
///
|
||||||
|
/// Returns `default` if the address is invalid.
|
||||||
|
fn check_flag(&self, addr: &str, flag: &str, default: bool) -> bool {
|
||||||
if addr.is_empty() || !addr.contains('@') || addr.contains('/') {
|
if addr.is_empty() || !addr.contains('@') || addr.contains('/') {
|
||||||
return false;
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut enforce_e2ee = self.mailboxes_dir();
|
let mut path = self.mailboxes_dir();
|
||||||
enforce_e2ee.push(addr);
|
path.push(addr);
|
||||||
enforce_e2ee.push("enforceE2EEincoming");
|
path.push(flag);
|
||||||
|
|
||||||
!enforce_e2ee.exists()
|
path.exists()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if not encrypted mail is allowed for the given address.
|
||||||
|
pub fn is_cleartext_ok(&self, addr: &str) -> bool {
|
||||||
|
!self.check_flag(addr, "enforceE2EEincoming", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if the given address is disabled.
|
||||||
|
pub fn is_disabled(&self, addr: &str) -> bool {
|
||||||
|
self.check_flag(addr, "DISABLED", false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Following are needed since serde does not support default literals.
|
// Following are needed since serde does not support default literals.
|
||||||
|
|||||||
@@ -98,6 +98,13 @@ impl SmtpHandler for IncomingBeforeQueueHandler {
|
|||||||
envelope.mail_from = String::new();
|
envelope.mail_from = String::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
envelope.rcpt_to = envelope
|
||||||
|
.rcpt_to
|
||||||
|
.iter()
|
||||||
|
.filter(|s| !self.config.is_disabled(s))
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
|
||||||
let mail_encrypted = check_encrypted(&message, false);
|
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));
|
log::debug!("is_securejoin: {}", is_securejoin(&message));
|
||||||
|
|||||||
@@ -78,6 +78,13 @@ impl SmtpHandler for OutgoingBeforeQueueHandler {
|
|||||||
let from_addr = extract_address(&from_header)
|
let from_addr = extract_address(&from_header)
|
||||||
.ok_or(format!("500 Invalid FROM header: {from_header}"))?;
|
.ok_or(format!("500 Invalid FROM header: {from_header}"))?;
|
||||||
|
|
||||||
|
envelope.rcpt_to = envelope
|
||||||
|
.rcpt_to
|
||||||
|
.iter()
|
||||||
|
.filter(|s| !self.config.is_disabled(s))
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
|
||||||
// MAIL FROM is our source of truth for outbound messages,
|
// MAIL FROM is our source of truth for outbound messages,
|
||||||
// as this address is checked by postfix against the username before sending it
|
// as this address is checked by postfix against the username before sending it
|
||||||
// to filtermail.
|
// to filtermail.
|
||||||
@@ -139,4 +146,22 @@ impl SmtpHandler for OutgoingBeforeQueueHandler {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn handle_data(&self, envelope: &mut Envelope) -> Result<String, String> {
|
||||||
|
log::debug!("handle_DATA before-queue");
|
||||||
|
self.check_data(envelope).await?;
|
||||||
|
if self.config.is_disabled(&envelope.mail_from) {
|
||||||
|
log::warn!("Dropping mail; Sender {} is disabled.", envelope.mail_from);
|
||||||
|
return Ok("250 OK".to_string());
|
||||||
|
}
|
||||||
|
if envelope.rcpt_to.is_empty() {
|
||||||
|
log::warn!("Dropping mail; All recipients disabled.");
|
||||||
|
return Ok("250 OK".to_string());
|
||||||
|
}
|
||||||
|
self.reinject_mail(envelope).await.map_err(|e| {
|
||||||
|
log::warn!("Failed to reinject mail: {e}");
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
Ok("250 OK".to_string())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ pub trait SmtpHandler: Send + Sync {
|
|||||||
async fn handle_data(&self, envelope: &mut Envelope) -> Result<String, String> {
|
async fn handle_data(&self, envelope: &mut Envelope) -> Result<String, String> {
|
||||||
log::debug!("handle_DATA before-queue");
|
log::debug!("handle_DATA before-queue");
|
||||||
self.check_data(envelope).await?;
|
self.check_data(envelope).await?;
|
||||||
|
if envelope.rcpt_to.is_empty() {
|
||||||
|
log::warn!("Dropping mail; All recipients disabled.");
|
||||||
|
return Ok("250 OK".to_string());
|
||||||
|
}
|
||||||
self.reinject_mail(envelope).await.map_err(|e| {
|
self.reinject_mail(envelope).await.map_err(|e| {
|
||||||
log::warn!("Failed to reinject mail: {e}");
|
log::warn!("Failed to reinject mail: {e}");
|
||||||
e
|
e
|
||||||
|
|||||||
Reference in New Issue
Block a user