Do you have a question? Post it now! No Registration Necessary. Now with pictures!
August 7, 2009, 2:03 pm
rate this thread
Rewriting a python email handling script into PHP (because the rest
of the application is PHP and better to use all the associated PHP
classes), I've hit a snag and hope someone can offer advice.
The original python script read an email message from STDIN, and use
python's email.parser.Parser to retrieve some components. After
processing and doing some database actions, the whole message
structure could be resent with modified headers to different
I started out by using PEAR::Mail_mimeDecode to parse the email from
STDIN, which works quite well. However, I cannot find a method to
modify and re-encode the message to resend. It is necessary for the
final recipients (who are determined by the database) to receive the
mime message fully intact.
One idea is to modify the headers using string replacement on the
original message string (not the mime structure from mimeDecode) and
hand it back to PHP's built-in mail(), but I am concerned about email
header injection on headers left unmodified.
I would prefer to rebuild the message from the mimeDecode
structure. Can anyone tell me if other mailer libraries are able to
make that two-way trip (decode and re-encode)?
Another option is to handle some of this work using Procmail, but I
prefer not to add the dependency. It's better if all handled inside
Thanks for any advice,
- » exec() has a syntax error, need an index.php page, cURL script
- — Previous thread in » PHP Scripting Forum