Pipe to PHP Script from Evolution

Posted on April 4th, 2010 in PHP, system admin, system administration by Russ

Here’s a quick example of how to pipe a message to a PHP script from Evolution (the gnome-tastic email client).

First, write a script, using very clear paths. And use php://stdin to capture the input stream:


#!/usr/bin/php -q
< ?php
include_once( dirname(__FILE__).'/includeme.php' );
$input='';
$fh=fopen( 'php://stdin', 'r' );
while( ! feof( $fh ) ) {
$input .= fread( $fh, 4096);
}
fclose( $fh );

Do whatever you need to with the $input variable. I had subscribed to a newsletter, and was using PHP to parse out the interesting bits of the newsletter (everything between the h1, h2 and h3 tags, so I knew if I needed to read it), and remail that to a more-frequently checked email address.

You can test your file with a shell command of "cat (testfile) | $somescript.php "

When it's perfect, then go to your evolution program and use the "message filters" to "pipe a message to a program." And pipe it to this one (including of course the explicit paths).

The things to take away here are the php://stdin slurp, and the fact that you have to use explicit paths (and you'll have a dickens of a time tracking down any errors).

Hope that helps ya!

Leave a comment