Procmail设置,执行PHP脚本 [英] Procmail setup, to execute PHP script

查看:48
本文介绍了Procmail设置,执行PHP脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的procmail设置运行良好,当收到电子邮件时,似乎在执行我的PHP脚本没有问题.

I've got a procmail setup working pretty well, seems to be executing my PHP script no problem when it receives an email.

以下是.procmailrc文件的示例:

Here is an example of the .procmailrc file:

#BEGIN PROCMAIL SCRIPT FOR MAIL PARSING
DEFAULT=$HOME/Maildir/
MAILDIR=$HOME/Maildir
PMDIR=$HOME/.procmail
LOGFILE=$PMDIR/log.`date +%y-%m-%d`
SHELL=/bin/sh

:0
|`/usr/local/php53/bin/php /home/usrmail/email/script.php`

下面的日志输出:

 From x13542053@homiemail-mx22.g.dreamhost.com  Mon Feb 18 20:49:35 2013
 Subject: TEST
  Folder: HELLO                                                            2559
/bin/sh: HELLO: No such file or directory

只是一个简单的 echo"HELLO"; 在php脚本中,似乎工作正常!

Is just a simple echo "HELLO"; in the php script, seems to work fine!

但是,当我尝试使用以下代码实际解析电子邮件时,在日志中出现以下错误:

However when I try to actually parse the email using the following code I get the error below in the log:

$rawEmail = '';
if (($fp = fopen('php://stdin', 'r')) !== false) {
    while (!feof($fp)) {
        $rawEmail .= fread($fp, 1024);
    }
    fclose($fp);
}

 $email = new Zend_Mail_Message(array(
   'raw' => $rawEmail
));

From actualaddress@gmail.com  Mon Feb 18 20:44:36 2013
 Subject: Re: Test
  Folder: Fatal error: Class 'Zend_Mail_Message' not found in /home/sy     2747
/bin/sh: Fatal: No such file or directory

这显然不能正常工作,我不确定为什么.对于其中一个,From标头在这一个标头上执行,但在另一标头上却不执行,这似乎是间歇的.

This isn't working correctly obviously, I'm not sure why. For one, the From header went through on this one but not the other, that seems intermittent.

此外,目录(/home/sy)被截断或某些内容被切断而导致错误.

Also the directory (/home/sy) is either truncated or something is cutting it off to cause an error.

我根本不熟悉Zend或procmail.我很高兴能够走到这一步,只想解析一下电子邮件,以便我可以获取电子邮件的正文并将其放置在某处.有人说服我,这是比仅使用IMAP或其他方法更好的方法,我听了.如果有人有任何出色的解决方案或替代方案,我将为您倾听.谢谢大家!

I'm not familiar with Zend really at all, or procmail. I was happy enough to get this far, just want to parse the email a bit so I can fetch the body of the email and put it somewhere. Someone convinced me this would be a better way than just using IMAP or something and I listened. If anyone's got any wonderful solutions or alternatives I'm all ears. Thanks guys!

推荐答案

您正在混合两种相关但不同的语法.

You are mixing two related but different pieces of syntax.

如果您希望通过管道传输到脚本,则应该只是

If you want to pipe to your script, it should be just

:0
* conditions, maybe
| /path/to/script

或者如果您想使用脚本的输出,则类似

or if you want to use the output of the script, something like

:0
* conditions, maybe
`echo HELLO`

会将文件保存到名为 HELLO 的文件夹中,即,将脚本的输出用作文字.

would file into a folder named HELLO, i.e. use the output from the script as a literal.

对于来自PHP的错误消息,我想您需要在PHP的库路径中添加一些内容(快速谷歌搜索建议您应在 php.ini 中修复 include_path ).

As for the error message from PHP, I imagine you need to add something to PHP's library path (quick googling suggests you should fix the include_path in your php.ini).

不过,您想完成什么?如果您只想将邮件发送到标题说应该去的地方,例如

What are you trying to accomplish, though? If you just want to send the message where the headers say it should be going, something like

:0
* conditions, maybe
! -t

应该可以帮助您.我无法想象您会想要这样做的情况(除非您试图完全解决错误的问题).如果您想发送邮件的截短副本,例如

should get you that. I cannot imagine a situation where you would want to do this (other than if you are trying to solve the wrong problem altogether). If you want to send a truncated copy of the message, something like

:0c
* conditions, maybe
{
    :0fw
    | head -n 10
    :0
    ! -t
}

将消息截断到前十行.如果您想精确地截断为1024个字节,那就不难了.

would truncate the message to the first ten lines. If you want to truncate to 1024 bytes exactly, that's not much harder.

另一方面,如果您只想存储邮件的正文(完整的RFC822正文,即所有MIME附件等都将原样不加解码地包含在内),则可以使用

On the other hand, if you just want to store the message's body (full RFC822 body, i.e. any MIME attachments etc will just be included verbatim, undecoded) you can do that with

:0b
saved/

或者如果您想在那里安装PHP

or maybe if you want PHP there

:0b
| /path/to/script.php

对于它的价值,错误消息被截断了,但这主要是因为您试图将其用作将电子邮件发送到的脚本的名称.如果您删除了反引号,则错误消息应以Procmail的标准错误结尾,而不会被截断.

For what it's worth, the error message is being truncated, but that is mainly because you are trying to use it as the name of the script to deliver the email to. If you take out the backquotes, the error message should end up in Procmail's standard error without truncation.

这篇关于Procmail设置,执行PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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