Configurable sieve script directory
(cherry picked from commit c00fc587f5
)
This commit is contained in:
parent
c1eb866805
commit
fb1cc04c0a
3 changed files with 24 additions and 16 deletions
|
@ -452,6 +452,14 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sieveDirectory = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
default = "/var/sieve";
|
||||||
|
description = ''
|
||||||
|
Where to store the sieve scripts.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
virusScanning = mkOption {
|
virusScanning = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
|
|
|
@ -217,8 +217,8 @@ in
|
||||||
|
|
||||||
plugin {
|
plugin {
|
||||||
sieve_plugins = sieve_imapsieve sieve_extprograms
|
sieve_plugins = sieve_imapsieve sieve_extprograms
|
||||||
sieve = file:/var/sieve/%u/scripts;active=/var/sieve/%u/active.sieve
|
sieve = file:${cfg.sieveDirectory}/%u/scripts;active=${cfg.sieveDirectory}/%u/active.sieve
|
||||||
sieve_default = file:/var/sieve/%u/default.sieve
|
sieve_default = file:${cfg.sieveDirectory}/%u/default.sieve
|
||||||
sieve_default_name = default
|
sieve_default_name = default
|
||||||
|
|
||||||
# From elsewhere to Spam folder
|
# From elsewhere to Spam folder
|
||||||
|
|
|
@ -35,31 +35,31 @@ let
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Create directory to store user sieve scripts if it doesn't exist
|
# Create directory to store user sieve scripts if it doesn't exist
|
||||||
if (! test -d "/var/sieve"); then
|
if (! test -d "${sieveDirectory}"); then
|
||||||
mkdir "/var/sieve"
|
mkdir "${sieveDirectory}"
|
||||||
chown "${vmailUserName}:${vmailGroupName}" "/var/sieve"
|
chown "${vmailUserName}:${vmailGroupName}" "${sieveDirectory}"
|
||||||
chmod 770 "/var/sieve"
|
chmod 770 "${sieveDirectory}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Copy user's sieve script to the correct location (if it exists). If it
|
# Copy user's sieve script to the correct location (if it exists). If it
|
||||||
# is null, remove the file.
|
# is null, remove the file.
|
||||||
${lib.concatMapStringsSep "\n" ({ name, sieveScript }:
|
${lib.concatMapStringsSep "\n" ({ name, sieveScript }:
|
||||||
if lib.isString sieveScript then ''
|
if lib.isString sieveScript then ''
|
||||||
if (! test -d "/var/sieve/${name}"); then
|
if (! test -d "${sieveDirectory}/${name}"); then
|
||||||
mkdir -p "/var/sieve/${name}"
|
mkdir -p "${sieveDirectory}/${name}"
|
||||||
chown "${vmailUserName}:${vmailGroupName}" "/var/sieve/${name}"
|
chown "${vmailUserName}:${vmailGroupName}" "${sieveDirectory}/${name}"
|
||||||
chmod 770 "/var/sieve/${name}"
|
chmod 770 "${sieveDirectory}/${name}"
|
||||||
fi
|
fi
|
||||||
cat << 'EOF' > "/var/sieve/${name}/default.sieve"
|
cat << 'EOF' > "${sieveDirectory}/${name}/default.sieve"
|
||||||
${sieveScript}
|
${sieveScript}
|
||||||
EOF
|
EOF
|
||||||
chown "${vmailUserName}:${vmailGroupName}" "/var/sieve/${name}/default.sieve"
|
chown "${vmailUserName}:${vmailGroupName}" "${sieveDirectory}/${name}/default.sieve"
|
||||||
'' else ''
|
'' else ''
|
||||||
if (test -f "/var/sieve/${name}/default.sieve"); then
|
if (test -f "${sieveDirectory}/${name}/default.sieve"); then
|
||||||
rm "/var/sieve/${name}/default.sieve"
|
rm "${sieveDirectory}/${name}/default.sieve"
|
||||||
fi
|
fi
|
||||||
if (test -f "/var/sieve/${name}.svbin"); then
|
if (test -f "${sieveDirectory}/${name}.svbin"); then
|
||||||
rm "/var/sieve/${name}/default.svbin"
|
rm "${sieveDirectory}/${name}/default.svbin"
|
||||||
fi
|
fi
|
||||||
'') (map (user: { inherit (user) name sieveScript; })
|
'') (map (user: { inherit (user) name sieveScript; })
|
||||||
(lib.attrValues loginAccounts))}
|
(lib.attrValues loginAccounts))}
|
||||||
|
|
Loading…
Reference in a new issue