解析电子邮件附件的脚本

发布于 2024-09-02 04:45:27 字数 157 浏览 4 评论 0原文

我正在寻找一种方法来监控 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栀子花开つ 2024-09-09 04:45:27

对于这种情况,我将电子邮件通过管道传输到 PHP 脚本,并让 PHP 脚本解析电子邮件。您可以获得即时结果,而不是等待 cronjob 拉取电子邮件,

$stdin = fopen('php://stdin', 'r');
while (!feof($stdin))
{
$input .= fread($stdin, 8192);
}

现在您已在 $input 中拥有整个电子邮件,并且您可以使用边界提取 base64 编码信息,然后 file_put_contents("/ tmp/file.csv",base64_decode($extracted_file_contents))

确保 chmod +x

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文