From ecc88b5539d16fe1b64ebc09b986361e8c365c8b Mon Sep 17 00:00:00 2001 From: Gonne Date: Wed, 26 Mar 2025 07:30:12 +0100 Subject: [PATCH] Add `Delivered-To` headers --- packages/alias-to-sieve/src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/alias-to-sieve/src/lib.rs b/packages/alias-to-sieve/src/lib.rs index a398846..35ebea2 100644 --- a/packages/alias-to-sieve/src/lib.rs +++ b/packages/alias-to-sieve/src/lib.rs @@ -134,7 +134,7 @@ where /// Addresses are sorted according to the order on `OrdEmailAddress`. pub fn generate_sieve_script(redirects: AliasMap) -> String { let mut script: String = - "require [\"variables\", \"copy\", \"vnd.stalwart.expressions\", \"envelope\"]; + "require [\"variables\", \"copy\", \"vnd.stalwart.expressions\", \"envelope\", \"editheader\"]; let \"i\" \"0\"; while \"i < count(envelope.to)\" { @@ -145,19 +145,23 @@ while \"i < count(envelope.to)\" { script += format!( // inspired by https://github.com/stalwartlabs/mail-server/issues/916#issuecomment-2474844389 " if eval \"eq_ignore_case(envelope.to[i], '{}')\" {{ + addheader \"Delivered-To\" \"{}\"; {} + deleteheader :index 1 :is \"Delivered-To\" \"{}\"; let \"redirected\" \"true\"; }} ", + redirect.0, redirect.0, { let mut subscript: String = String::new(); destinations.sort(); for destination in destinations.iter() { - subscript += format!(" redirect :copy \"{}\";", destination.0).as_str(); + subscript += format!(" redirect :copy \"{}\";\n", destination.0).as_str(); } subscript - } + }, + redirect.0 ) .as_str(); }