I am looking for a way to monitor a Linux mbox email account, when an email arrives I would like to download an attachment from the email and save the attachment (CSV file) so that it may be used by a PHP script. Wh开发者_运维知识库at would be the best way of going about this? I have looked at PHP's IMAP functions but this does not appear to be the most appropriate method when a simple bash script may be all that is required?
For this situation I pipe the email to a PHP script and let the PHP script parse the email. You get instant results versus waiting for a cronjob to pull emails down
$stdin = fopen('php://stdin', 'r');
while (!feof($stdin))
{
$input .= fread($stdin, 8192);
}
now you have the entire email in $input
and you can use the boundries to extract the base64 encoded information and then file_put_contents("/tmp/file.csv",base64_decode($extracted_file_contents))
make sure you chmod +x
精彩评论