1

I have a procmail recipe which sends the body of a mail to a script. Works well but procmail then sends the mail without the body to my default folder.

:0
* ^Subject.*Telemetry rotate$
{
:0 bf
! `/usr/bin/php -f /path/to/script/script.php`
}

How can I have procmail send the body to my script without deleting it or send a copy to a folder and then delete the original.

janos
  • 11,341
Danny
  • 175
  • Do the backticks work like a command substitution in the procmail config? I can't remember... Why would you want to use a command substitution there? – Kusalananda Dec 18 '18 at 17:45
  • As far as I can (also) remember the backticks serves to "escape" the command – Danny Dec 18 '18 at 17:53
  • The ! forwards the mail to the address that the PHP script outputs. That's what the ! at the start does. Is this what you intend? Did you intend to use | instead? Check the promailrc manual... – Kusalananda Dec 18 '18 at 18:02
  • I would regard it as surprising but not necessarily a bug that you can use the f flag with an ! action. This is a corner case I have never seen before. I'm pretty sure the recipe doesn't do at all what you want; but your question really should spell out more explicitly what you do want. The idea that backticks "escape" a command is certainly nonsense. – tripleee Dec 18 '18 at 19:56
  • yes, I want to pass the body to a script but also want a copy/original to be passed/sent to a folder for record purposes – Danny Dec 19 '18 at 11:27

1 Answers1

1

You have some errors here. The f flag says to replace the message with the output from the filter (though the b restricts this action to just the body). The braces are also superfluous here. So I'd go with

:0b
* ^Subject.*Telemetry rotate$
! `php -f /path/to/script/script.php`

if indeed the plan is to (1) pass the body to the PHP script, (2) capture the script's output (this is what the `backticks` do) and (3) forward the message to the address captured (that's wat the ! action does).

If your intention is merely to pass the body to your script, that would be

:0b
* ^Subject.*Telemetry rotate$
| php -f /path/to/script/script.php

maybe also with a c flag if you want to continue to process the message after this point.

You'll notice that I took out the hard-coded path /usr/bin; hardcoding the path makes the script less portable, and makes it impossible (or at least extremely cumbersome) to replace php with a wrapper for debugging purposes. I'd recommend to simply make sure you set up your PATH correctly in production.

tripleee
  • 7,699