0

I have a procmail recipe that takes the body of a mail and sends it to a php script. However, procmail complains with an error.

Here is how it works: The user that needs access to hardware parameters has to register via e-mail like this:
Subject:Register
Body:??username:email_address:password??

Procmail then sends the body off to the php script to be processed. The reason I use "??" is to make it easier for me to filter out the garbage of what comes with the body via grep.

Here is the error in procmail.log:

From fetchmail  Fri Nov 25 15:41:36 2016
Subject: Register
Folder: /root/mail/inbox/inbox                     3673
procmail: [20601] Fri Nov 25 15:43:44 2016
procmail: Assigning "DEFAULT=/root/mail/inbox/inbox"
procmail: Assigning "PMDIR=/root/.procmail"
procmail: Match on "^Subject.*[R|r]egister$"
procmail: Executing "/usr/bin/php,-f,/root/data/scripts/register.php"
procmail: Executing "??myusername:me@gmail.com:mypass1??"
/bin/sh: 0: Can't open ??myusername:me@gmail.com:mypass1??

Here is my procmail recipe:

SHELL=/bin/sh
HOME=$HOME
PATH=$HOME/bin:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin
SENDMAIL=/usr/sbin/sendmail
MAILDIR=$HOME/mail
LOGFILE=/var/log/procmail.log
LOGABSTRACT="all"
VERBOSE="on"
DEFAULT=$HOME/mail/inbox/inbox
PMDIR=$HOME/.procmail
:0
* ^Subject.*[R|r]egister$
{
  :0 bf
  | `/usr/bin/php -f /root/data/scripts/register.php`
}

Here is an abbreviated snippet of the register.php script:

#!/usr/bin/php
<?php
while ( false !== ( $user_register = fgets ( STDIN ) ) )
{
  $user_info = preg_match ( "/\?\?.*\?\?/", @$user_register, $new_registration ) ;
  foreach ( $new_registration as $input )
  {
    print ( $input."\n" ) ;
  }
}

I do not think it has anything to do with the php code as I have similarly structured recipes and php code.

Any pointers?

1
  • Remove the backquotes `` from around your php line in the recipe.
    – meuh
    Nov 25 '16 at 18:00
1

The correct syntax is to remove the backquotes around the PHP script, unless its specific purpose is to print the name of the command you want to pipe the message to on its standard output.

In other words,

echo "moo" | `echo wc`

is equivalent to

echo "moo" | wc

There's a number of other simplifications and corrections you can make. Procmail conditions are case-insensitive by default (and I don't think you intend to match |egister though your current code does) and there is no need to use braces just to add some flags.

:0bf
* ^Subject.*register$
| /usr/bin/php -f /root/data/scripts/register.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.