Thanks for your insight Eric! 
I did some googling and experimentation, and found out a way to do this, with Procmail indeed.
Nice thing is: No “fancy rules” to pull the username and foldername from the address are required, because Postfix already supplies the extension, i.e. everything after the (configurable) character “+”, in an environment variable named $EXTENSION when calling external programs for local delivery.
So, first Postfix needs to be reconfigured to pass the extension in a variable to Procmail. That’s done by changing the mailbox delivery command to:
/usr/bin/procmail-wrapper -o -a $DOMAIN -a "$EXTENSION" -d $LOGNAME
Thus, $DOMAIN will be passed as $1 in .procmailrc (although I think this variable isn’t even used right now, at least I could find no reference to it in Virtualmin’s Procmail config) and $EXTENSION will become $2.
IMPORTANT! The extension needs to be put in quotes, because it can be empty, and that would break the command like ("-a -a -d …" which causes Procmail to fail).
CAVEAT and BUG in Webmin: The Procmail module will remove the quotes in that command line when I enter it through the Local Delivery input mask; I had to directly edit the /etc/postfix/main.cf
file!
Then I put this in the user’s .procmailrc
:
[code]EXT=$2
:0
- EXT ?? ^^test1^^|^^test2^^
$HOME/Maildir/.$EXT/[/code]
The first line unconditionally puts the second passed parameter into the local Procmail variable “EXT”. Needs to be done, cause you can’t access the $2 directly. Then it will do a regular expression check if the extension is “test1” or “test2” (don’t want email senders to be able to create arbitrary IMAP folders for the user!
). If so, the mail is filed into the subdirectory .$EXT
of the user’s Maildir.
Have not yet tried IMAP subfolders. Might work if you use the dot character that separates the subfolder directory names in the email address, like “user+folder.subfolder@domain”.
Then, the folder names must be all lowercase, because Postfix seems to have a bug which causes the extension text to be converted to lowercase when it is applied to the virtual domain mapping table.