#70 subfolder delivery option

open
nobody
5
2013-01-23
2010-02-12
toomuchcookies
No

Postfix's 'virtual' delivery process is able to deliver emails to a subfolder of a maildir, if one instructs it to do that. For that purpose 'maildir' has to look like '/var/vmail/domain/user/.subfolder/'. This is usefull for extension based email sorting obviously (letting a mailing list send you emails at user-subfolder@domain). BUT virtual doesn't look for a .forward-... file (which the other delivery process 'local' does). Instead postfix searches for the full email address (avec extension) and in the case it doesn't find it looks for the email address without the extension. So writing a simple line into the mailbox-table that contains the email address user-subfolder@domain and the maildir /domain/user/.subfolder/ would actually do the job.

I think it would be nice to have a feature implemented that enables users (or at least admins) to add extension based subfolder-delivery to their mail delivery.

While we're at it, we could have a general domain-based option that would enable postfix to autocreate subfolders in maildirs. A simple column 'autofolder' could be parsed in the postfix query to determine, if extension-based automatic subfolders would be generated (i admit, this could be a security issue). Here is a postfix query, that i'm using to get the job done at the moment (having added the 'autofolder' manually). First it tries to find the exact email address with the extension. When it doesn't find it, it looks at 'autofolder'. If 'autofolder' is <>'1' then it will not instruct postfix to autodeliver to a subfolder, but rather returns the standard folder for this mailbox (sans extension). If 'autofolder' is '1', then the query would build a folderstructure with the extension(s) as subfolder(s).

Hope you like!

SELECT COALESCE (
(SELECT maildir from mailbox where
username='%s' and active=1),
(SELECT IF (
(SELECT count(*) from domain where domain = SUBSTRING_INDEX( '%s', '@',-1) and active=1 and autofolder=1)>0,
NULL,
(SELECT maildir FROM mailbox WHERE username=
CONCAT( SUBSTRING_INDEX( SUBSTRING_INDEX( '%s', '@', 1), '+',1), '@', SUBSTRING_INDEX( '%s', '@',-1))
AND active=1)
)),
(SELECT CONCAT(
(SELECT maildir FROM mailbox WHERE username=
CONCAT( SUBSTRING_INDEX( SUBSTRING_INDEX( '%s', '@', 1), '+',1), '@', SUBSTRING_INDEX( '%s', '@',-1))
AND active=1),
(SELECT CONCAT(
'.',
REPLACE(SUBSTRING('%s',LOCATE('+','%s')+1,(SELECT '%s' REGEXP '\\+') * LOCATE('@','%s')-LOCATE('+','%s')-1),'+','/.'),
'/')
)
))
) as maildir

Discussion