From c0391046dc0d4859841c56788d53fb37c7e84e15 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 5 May 2022 23:53:26 +0200 Subject: surtr: ... --- hosts/surtr/email/default.nix | 20 +++++++++++++++----- hosts/surtr/postgresql.nix | 6 ++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/hosts/surtr/email/default.nix b/hosts/surtr/email/default.nix index 8889991c..b3306ece 100644 --- a/hosts/surtr/email/default.nix +++ b/hosts/surtr/email/default.nix @@ -146,11 +146,6 @@ in { dbname = email query = SELECT 1 FROM virtual_mailbox_mapping WHERE lookup = '%s' ''}''; - lmtp_generic_maps = ''pgsql:${pkgs.writeText "virtual_mailbox_maps.cf" '' - hosts = postgresql:///email - dbname = email - query = SELECT mailbox FROM virtual_mailbox_mapping WHERE lookup = '%s' - ''}''; virtual_transport = "lmtp:unix:/run/postfix/dovecot-lmtp"; }; masterConfig = { @@ -349,6 +344,21 @@ in { args = ${dovecotSqlConf} } + protocol lmtp { + userdb { + driver = sql + args = ${pkgs.writeText "dovecot-sql.conf" '' + driver = pgsql + connect = dbname=email + user_query = SELECT DISTINCT ON (local IS NULL) "user", quota_rule, 'dovecot2' as uid, 'dovecot2' as gid FROM lmtp_mapping WHERE (local = '%n' AND domain = '%d') OR (local IS NULL AND domain = '%d') ORDER BY (local IS NULL ASC) + ''} + + skip = never + result_failure = return-fail + result_internalfail = return-fail + } + } + mail_plugins = $mail_plugins quota mailbox_list_index = yes postmaster_address = postmaster@yggdrasil.li diff --git a/hosts/surtr/postgresql.nix b/hosts/surtr/postgresql.nix index c1993431..4899b972 100644 --- a/hosts/surtr/postgresql.nix +++ b/hosts/surtr/postgresql.nix @@ -50,6 +50,12 @@ in { CREATE VIEW imap_user ("user", quota_rule) AS SELECT mailbox AS "user", (CASE WHEN quota_bytes IS NULL THEN '*:ignore' ELSE '*:bytes=' || quota_bytes END) AS quota_rule FROM mailbox; COMMIT; + + BEGIN; + SELECT _v.register_patch('001-lmtp-mapping', ARRAY['000-base'], null); + + CREATE VIEW lmtp_mapping ("user", quota_rule, local, domain) AS SELECT mailbox.mailbox AS "user", (CASE WHEN quota_bytes IS NULL THEN '*:ignore' ELSE '*:bytes=' || quota_bytes END) AS quota_rule FROM mailbox INNER JOIN mailbox_mapping ON mailbox.id = mailbox_mapping.mailbox; + COMMIT; ''} ''; }; -- cgit v1.2.3