Thread: [Postfixadmin-devel] DB schema question
Brought to you by:
christian_boltz,
gingerdog
From: Richard H. <ri...@wa...> - 2024-11-30 05:57:07
|
Hi all, I notice that the mailbox table has username and domain columns, where the username is the full email address including the domain name. Are the domain names in both places guaranteed to be the same? If they are always the same, then the example db query for virtual_alias_domain_mailbox_maps could be significantly simplified. If not - under what circumstances? Thanks, Richard |
From: Christian B. <pos...@cb...> - 2024-11-30 12:58:33
|
Hello, Am Samstag, 30. November 2024, 06:18 schrieb Richard Hector: > I notice that the mailbox table has username and domain columns, where > the username is the full email address including the domain name. Are > the domain names in both places guaranteed to be the same? Nobody can stop you from doing a silly INSERT or UPDATE query directly in the database. That said - as long as you only use PostfixAdmin to modify the database, the domain column and the domain in the mailbox name are guaranteed to be the same. > If they are always the same, then the example db query for > virtual_alias_domain_mailbox_maps could be significantly simplified. Alias domains have a few special cases and pitfalls, but nevertheless, I'm looking forward for your proposal ;-) Regards, Christian Boltz -- I usually explain databases as 2TB sized global variables with a weird access method and concurrent access. [https://twitter.com/isotopp/status/1352618340871778308] |
From: Richard H. <ri...@wa...> - 2024-12-03 11:09:15
|
On 1/12/24 01:40, Christian Boltz wrote: > Hello, > > Am Samstag, 30. November 2024, 06:18 schrieb Richard Hector: >> I notice that the mailbox table has username and domain columns, where >> the username is the full email address including the domain name. Are >> the domain names in both places guaranteed to be the same? > > Nobody can stop you from doing a silly INSERT or UPDATE query directly > in the database. > > That said - as long as you only use PostfixAdmin to modify the database, > the domain column and the domain in the mailbox name are guaranteed to > be the same. > >> If they are always the same, then the example db query for >> virtual_alias_domain_mailbox_maps could be significantly simplified. > > Alias domains have a few special cases and pitfalls, but nevertheless, > I'm looking forward for your proposal ;-) So maybe this is where I show my ignorance, but: SELECT maildir from mailbox m JOIN alias_domain ad ON m.domain = ad.target_domain WHERE ad.alias_domain = '%d' and m.active and ad.active No concatenations required. Get rid of the table aliases if you like. I don't know whether those booleans work like that in mysql/maria - they do in PostgreSQL. Also, we don't need maildir here, right? "SELECT 1 FROM ..." would work just as well, and avoid confusing people (well, me) as to what it's being used for :-) Feel free to tell me I've got it wrong :-) Cheers, Richard |
From: Christian B. <pos...@cb...> - 2024-12-04 21:18:54
|
Hello, Am Dienstag, 3. Dezember 2024, 12:09 schrieb Richard Hector: > On 1/12/24 01:40, Christian Boltz wrote: > > Am Samstag, 30. November 2024, 06:18 schrieb Richard Hector: > >> If they are always the same, then the example db query for > >> virtual_alias_domain_mailbox_maps could be significantly > >> simplified. > > > > Alias domains have a few special cases and pitfalls, but > > nevertheless, I'm looking forward for your proposal ;-) > > So maybe this is where I show my ignorance, but: > > SELECT maildir from mailbox m JOIN alias_domain ad ON m.domain = > ad.target_domain WHERE ad.alias_domain = '%d' and m.active and > ad.active This query only checks the domain (%d), but not the mailbox name (%u). It will give you a list of maildirs for all mailboxes on that domain, but not (only) the maildir for the specified mailbox. It will even give you a list of maildirs if you query for a non-existing mailbox. (Always assuming that %d is an alias domain.) > No concatenations required. Only because your query doesn't specify which mailbox to look for ;-) The lookup needs to be done for user@targetdomain, and there's no variable for it (%s is user@aliasdomain - which doesn't exist because it's meant to be rewritten to user@targetdomain). That's why we concat %u (localpart) + the target domain so that the query finds the right mailbox. (For the records: these variables are explained in man 5 mysql_table.) > Get rid of the table aliases if you like. There's nothing wrong with specifying which table you want to use ;-) > I don't know whether those booleans work like that in mysql/maria - > they do in PostgreSQL. Good question, I didn't try before. I just tested on MariaDB 11.5.2, and it indeed handles the booleans as expected. (No idea if older MariaDB versions or MySQL also accepts this syntax.) > Also, we don't need maildir here, right? "SELECT 1 FROM ..." would > work just as well, and avoid confusing people (well, me) as to what > it's being used for :-) Well, it depends how you deliver mails. If you let Postfix write the mail into the maildir, then - surprise - it will need to know the maildir. If you deliver via Dovecot lmtp, then Postfix of course doesn't need to know the maildir. > Feel free to tell me I've got it wrong :-) As requested ;-) - I hope my explanation makes it clear why the query is written the way it is. Regards, Christian Boltz -- Maybe (as it's just repackaging), it could even run on some ppc64 obs-servers that must be quite depressed and have worn down their thumbs quite a lot from twiddling them, chronically having nothing to do ... [David Haller in opensuse-packaging] |
From: Richard H. <ri...@wa...> - 2024-12-05 13:21:01
|
On 5/12/24 10:18, Christian Boltz wrote: > Hello, > > Am Dienstag, 3. Dezember 2024, 12:09 schrieb Richard Hector: >> On 1/12/24 01:40, Christian Boltz wrote: >> > Am Samstag, 30. November 2024, 06:18 schrieb Richard Hector: > >> >> If they are always the same, then the example db query for >> >> virtual_alias_domain_mailbox_maps could be significantly >> >> simplified. >> > >> > Alias domains have a few special cases and pitfalls, but >> > nevertheless, I'm looking forward for your proposal ;-) >> >> So maybe this is where I show my ignorance, but: >> >> SELECT maildir from mailbox m JOIN alias_domain ad ON m.domain = >> ad.target_domain WHERE ad.alias_domain = '%d' and m.active and >> ad.active > > This query only checks the domain (%d), but not the mailbox name (%u). > It will give you a list of maildirs for all mailboxes on that domain, > but not (only) the maildir for the specified mailbox. It will even give > you a list of maildirs if you query for a non-existing mailbox. > (Always assuming that %d is an alias domain.) > >> No concatenations required. > > Only because your query doesn't specify which mailbox to look for ;-) Aah ... I shouldn't have done that from memory, in a hurry :-) Checking %u against m.local_part would be necessary, at least - but I'm again short of time, so I'll have another look later. Thank you for your patience :-) > > The lookup needs to be done for user@targetdomain, and there's no > variable for it (%s is user@aliasdomain - which doesn't exist because > it's meant to be rewritten to user@targetdomain). That's why we concat > %u (localpart) + the target domain so that the query finds the right > mailbox. > > (For the records: these variables are explained in man 5 mysql_table.) > >> Get rid of the table aliases if you like. > > There's nothing wrong with specifying which table you want to use ;-) > >> I don't know whether those booleans work like that in mysql/maria - >> they do in PostgreSQL. > > Good question, I didn't try before. > > I just tested on MariaDB 11.5.2, and it indeed handles the booleans as > expected. > (No idea if older MariaDB versions or MySQL also accepts this syntax.) > >> Also, we don't need maildir here, right? "SELECT 1 FROM ..." would >> work just as well, and avoid confusing people (well, me) as to what >> it's being used for :-) > > Well, it depends how you deliver mails. > > If you let Postfix write the mail into the maildir, then - surprise - it > will need to know the maildir. > > If you deliver via Dovecot lmtp, then Postfix of course doesn't need to > know the maildir. Yes, I guess this is the right query to provide that info to Postfix. And you're right, I'm using dovecot (actually deliver/lda, but planning to switch to lmtp), so wasn't fully thinking about that. >> Feel free to tell me I've got it wrong :-) > > As requested ;-) - I hope my explanation makes it clear why the query is > written the way it is. Many thanks (also for your responses on IRC), Richard |