-1

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 hello@example.com and welcome@example.com 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?

tripleee
  • 139,311
  • 24
  • 207
  • 268
proc
  • 1
  • I tried to clean up the text but I had to guess some things. Please review, and please still clarify if you can. In particular, we expect you to explain where exactly you are stuck. – tripleee Jan 23 '20 at 08:00

1 Answers1

0

If your MTA exposes this information in e.g. the Delivered-To: header, this is easy enough to extract.

:0:
* ^Delivered-to:[   ]*<?\/[^ <>@    ]+
$MATCH

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 in MATCH by 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 mkdir if 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 both welcome and hello, 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

tripleee
  • 139,311
  • 24
  • 207
  • 268