脚本解析为附件的电子邮件 [英] Script to parse emails for attachments

查看:131
本文介绍了脚本解析为附件的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一种方式来监控Linux的MBOX电子邮件帐户,当邮件到达我想下载从电子邮件附件,保存附件(CSV文件),以便它可以由一个PHP脚本中使用。什么会是要对这个的最好方法?我看过PHP的IMAP功能,但这并不似乎是最合适的方法,当一个简单的bash脚本可能是需要呢?

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. What 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?

推荐答案

对于这种情况我管的电子邮件PHP脚本,让PHP脚本解析电子邮件。你得到立竿见影的效果与等待一个cronjob拉下来电子邮件

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);
}

现在你有 $输入完整的电子邮件键,您可以使用边界值提取的base64 EN codeD的信息,然后的file_put_contents (/tmp/file.csv\",base64_de$c$c($extracted_file_contents))

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))

请确保您使用chmod + X

make sure you chmod +x

这篇关于脚本解析为附件的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆