0

I want a setup where an e-mailaddress like user+foo@example.com redirects mail to the folder foo. I've already got dovecot configured and tested. It is called by postfix with this line in master.cf:

dovecot unix    -       n       n       -       -      pipe
  flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop} -n -m ${extension}

I expect ${extension} to expand to 'foo' but it is always empty.

I've added

recipient_delimiter = +

to my main.cf.

How can I get it to work?

I've got a catch-all alias that redirects @example.com to user@example.com. It seems that the extension is empty because of this. So the question becomes: Can I have a catch-all so that random+ext@example.com redirects to user+ext@example.com without explicitly defining either the random or the ext part?

masegaloeh
  • 18,236
  • 10
  • 57
  • 106
Paul Wagener
  • 173
  • 4

2 Answers2

1

You will need to use a regexp map for this to work.

Here's snippet of a post from Wietse on the matter.

You can use regexp tables instead of fixed-string maps, and do arbitrary address transformations:

/\+([^+]+)@example\.com$/   localuser2+$1localhost 

You can get explanation of regex scheme in regex101. In short, the bracket () will capture the extension and pass it to your alias.

tpml7
  • 479
  • 1
  • 5
  • 21
Drew Bloechl
  • 744
  • 3
  • 6
0

I have a similar setup using Postfix and CourierIMAP. You could try using procmail to handle this. I have a wildcard set up so that all mail goes to one user, and then use procmail rules to filter e-mail into various folders based on the address it was sent to.

For example, this would filter e-mail to adsense or google @domain.com into a Google folder:

:0
* ^(To|CC|BCC).*(adsense|google)\@domain\.com
.Google/

To expand on this for your purpose, you could use a more advance rule like this:

:0
* ^(To|CC|BCC).*user\+\/.*\@domain\.com
.`echo $MATCH | sed 's/\@.*//'`/

However, note that the folder would be case-sensitive, and you would need to make sure the folder has been created. You could get more advanced and just do scripting to create folders when they don't already exist if necessary.

Paul Kroon
  • 2,250
  • 1
  • 16
  • 20