From 2a61e9daed5d5a378cee46a60597692804e4b70c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 17 Nov 2019 03:33:00 +0100 Subject: Add script handling for postfix --- modules/private/mail/postfix.nix | 55 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'modules/private/mail') diff --git a/modules/private/mail/postfix.nix b/modules/private/mail/postfix.nix index fcb0ce2..a679027 100644 --- a/modules/private/mail/postfix.nix +++ b/modules/private/mail/postfix.nix @@ -1,4 +1,4 @@ -{ lib, pkgs, config, myconfig, ... }: +{ lib, pkgs, config, myconfig, ... }: { config = lib.mkIf config.myServices.mail.enable { services.duplyBackup.profiles.mail.excludeFile = '' @@ -97,6 +97,43 @@ ]; }; services.postfix = { + extraAliases = let + toScript = name: script: pkgs.writeScript name '' + #! ${pkgs.stdenv.shell} + mail=$(${pkgs.coreutils}/bin/cat -) + output=$(echo "$mail" | ${script} 2>&1) + ret=$? + + if [ "$ret" != "0" ]; then + echo "$mail" \ + | ${pkgs.procmail}/bin/formail -i "X-Return-Code: $ret" \ + | /run/wrappers/bin/sendmail -i scripts_error+${name}@mail.immae.eu + + messageId=$(echo "$mail" | ${pkgs.procmail}/bin/formail -x "Message-Id:") + repeat=$(echo "$mail" | ${pkgs.procmail}/bin/formail -X "From:" -X "Received:") + + ${pkgs.coreutils}/bin/cat <