This commit is contained in:
mwiegand 2021-06-14 18:33:23 +02:00
parent 4d721b33e3
commit bcd2286de2
7 changed files with 25 additions and 16 deletions

View file

@ -0,0 +1,19 @@
DROP TABLE users; DROP TABLE domains;
CREATE TABLE domains (
"id" BIGSERIAL PRIMARY KEY,
"name" varchar(255) UNIQUE NOT NULL
);
CREATE INDEX ON domains ("name");
CREATE TABLE users (
"id" BIGSERIAL PRIMARY KEY,
"name" varchar(255) NOT NULL,
"domain_id" BIGSERIAL NOT NULL,
CONSTRAINT "fk_domain"
FOREIGN KEY("domain_id")
REFERENCES domains("id"),
"password" varchar(255) NOT NULL,
"redirect" varchar(255) DEFAULT NULL
);
CREATE UNIQUE INDEX ON users ("name", "domain_id") WHERE "redirect" IS NULL;

View file

@ -41,9 +41,9 @@ mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
virtual_mailbox_domains = psql:/etc/postfix/virtual_mailbox_domains.cf
virtual_mailbox_maps = psql:/etc/postfix/virtual_mailbox_maps.cf
virtual_alias_maps = psql:/etc/postfix/virtual_alias_maps.cf,psql:/etc/postfix/email2email.cf
virtual_mailbox_domains = psql:/etc/postfix/virtual_domains.cf
virtual_mailbox_maps = psql:/etc/postfix/virtual_mailboxes.cf
virtual_alias_maps = psql:/etc/postfix/virtual_aliases.cf,psql:/etc/postfix/virtual_mailboxes.cf
virtual_transport = lmtp:unix:private/dovecot-lmtp
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

View file

@ -2,4 +2,4 @@ hosts = ${host}
dbname = ${name}
user = ${user}
password = ${password}
query = SELECT destination FROM redirections LEFT JOIN domains ON redirections.domain_id = domains.id WHERE CONCAT_WS('@', redirections.source, domains.name) = '%s'
query = SELECT redirect FROM users LEFT JOIN domains ON users.domain_id = domains.id WHERE users.name = SPLIT_PART('%s', '@', 1) AND domains.name = SPLIT_PART('%s', '@', 2)

View file

@ -2,4 +2,4 @@ hosts = ${host}
dbname = ${name}
user = ${user}
password = ${password}
query = SELECT 1 FROM domains WHERE name='%s'
query = SELECT name FROM domains WHERE name='%s'

View file

@ -2,4 +2,4 @@ hosts = ${host}
dbname = ${name}
user = ${user}
password = ${password}
query = SELECT 1 FROM users LEFT JOIN domains ON users.domain_id=domains.id WHERE CONCAT_WS('@', users.user, domains.name) = '%s'
query = SELECT CONCAT(users.name, '@', domains.name) AS email FROM users LEFT JOIN domains ON users.domain_id = domains.id WHERE users.name = SPLIT_PART('%s', '@', 1) AND domains.name = SPLIT_PART('%s', '@', 2)

View file

@ -1,5 +0,0 @@
hosts = ${host}
dbname = ${name}
user = ${user}
password = ${password}
query = SELECT CONCAT_WS('@', users.user, domains.name) AS email FROM users JOIN domains ON users.domain_id = domains.id WHERE CONCAT_WS('@', users.user, domains.name)='%s'

View file

@ -32,11 +32,6 @@ files = {
'context': node.metadata.get('mailserver/database'),
**file_options,
},
'/etc/postfix/virtual_redirects.cf': {
'content_type': 'mako',
'context': node.metadata.get('mailserver/database'),
**file_options,
},
}
svc_systemd['postfix'] = {