Procmail content as POST variable

159 Views Asked by At

Procmail should send my emails with the content to my api. No matter what I try, I get the subject etc., but I can't get to the content. The $CONTENT variable is filled with the subject.

:0
{
 :0 w
  | CONTENT= cat

 :0
 | URL=$(curl -d  "content=$CONTENT" -d "title=Logged Activity" https://myapi.de/fetch.php);

}
1

There are 1 best solutions below

0
tripleee On

You have a repeated syntax error;

:0 w
| CONTENT= cat

means assign an empty string to CONTENT for the duration of the cat command. I guess your intent is to assign the message's contents to the variable. The syntax for that would be

CONTENT=| cat    

(not a recipe, so no :0 w is useful, necessary, or correct here); but if you don't use this variable for anything else, there really is no need to assign it separately.

:0
| URL=$(curl -d  "content=$(cat)" -d "title=Logged Activity" https://myapi.de/fetch.php);

As above, this also probably doesn't do what you actually want. If you expect the variable to be assigned within your .procmailrc, try

URL=|curl -d "content=$(cat)" -d "title=Logged Activity" https://myapi.de/fetch.php;

The trailing semicolon (or some other character from SHELLMETAS) is required to force Procmail to run the subprocess in a shell (otherwise it would pass through the literal string content=$(cat) as the value of the option -d).

In some more detail, the recipe

:0
| variable=$(cat)

would run a shell as a subprocess, and assign the message's contents as the value of the shell variable variable, but then immediately exit, which of course loses any effects of variable assignments which happened within that subprocess.