Here the extended version of @sebix's comment above. This untested solution taken directly from dovecot 2 wiki: Pigeonhole Sieve examples.
You need subaddress extension from dovecot sieve to do it. Put it in sieve script. Here the simple example to put email foo+spam@example.org to Spam folder.
require ["fileinto", "envelope", "subaddress"];
if envelope :detail "to" "spam"{
fileinto "Spam";
}
The more advanced example is use regex to capture the address extension and put it in same folder. For example test+A@example.org will delivered on A subfolder, test+B@example.org will delivered on B subfolder and so on
require ["variables", "envelope", "fileinto", "subaddress"];
if envelope :is :user "to" "test" {
if envelope :matches :detail "to" "*" {
/* Save name in ${name} in all lowercase except for the first letter.
* Joe, joe, jOe thus all become 'Joe'.
* Of course you can set into all lowercase letter
*/
set :lower :upperfirst "name" "${1}";
}
if string :is "${name}" "" {
/* Default case to INBOX */
fileinto "INBOX";
} else {
fileinto "${name}";
}
}
To work with Postfix, this requires that the envelope "to" still contains the full address, so pass it with the -a flag.
For local delivery set
mailbox_command = /usr/lib/dovecot/dovecot-lda -a "$RECIPIENT"
or for virtual delivery
dovecot unix - n n - - pipe
flags=DRhu user=mail:mail argv=/usr/local/libexec/dovecot/dovecot-lda
-f ${sender} -d ${user}@${nexthop} -a ${recipient}