Can someone explain how to get the send to mail address with procmail and extract all up to @example.com and then create a new folder with the name?
Example: I collect all mail in one account so the addresses [email protected] and [email protected] and so on are in the same account.
Now I want to create a subfolder with the recipient name e.g. hello and welcome as soon as i receive a mail to this address.
My problem is that I just get the sender's address... but I like to get the recipient address.
In this post Automatic procmail filter based on username someone explains how to get senders address; how can I adapt that to my scenario?
If your MTA exposes this information in e.g. the
Delivered-To:header, this is easy enough to extract.As usual in Procmail, the whitespace inside
[ ]should consist of one space and one literal tab character. The regex[^ <>@ ]+matches as many characters as possible which are not space,<,>,@, or tab.This extracts text from the
Delivered-To:header up to just before@and stores that inMATCHby way of the special\/token; then the value of this variable is used as the destination folder to save the message to.It's not clear if you intend for "folder" to mean a mailbox (such as a Berkeley mbox file) or a directory. In the latter case, remove the second colon, and perhaps add a
mkdirif you want to create a maildir structure if it doesn't already exist.Be aware that this is extremely brittle. In the general case, there is no reliable, portable way to make sure that the recipient address is exposed like this. If an incoming message was
Bcc:ed to bothwelcomeandhello, chances are you will get nothing, or two messages, or just one or the other. This is a common FAQ; see also http://www.iki.fi/era/procmail/mini-faq.html#bcc