简体   繁体   English

PROCMAIL ::如何在邮件发送到MBox后执行perl脚本

[英]PROCMAIL:: How do I get a perl script to execute AFTER having the mail delivered to the MBox

I'm on a Red Hat installation. 我正在安装Red Hat。 What I'm running into is that: 我遇到的是:

  1. The perl script looks into the mailbox using Modules to look for message #0 or the delieved mail but it isn't there yet. perl脚本使用模块查看邮箱以查找消息#0或已发送的邮件,但它尚未存在。

  2. If I make a COPY of the mail using the C flag I still get the same response that it does not deliver it to the mailbox. 如果我使用C标志对邮件进行复制,我仍然得到相同的响应,它不会将其传递到邮箱。

So what I need to know is a procmail recipe which delivers it to the mailbox then fires the script to process the delivered email. 所以我需要知道的是一个procmail配方,它将它传递到邮箱然后激活脚本来处理传递的电子邮件。

Thanks Rob 谢谢Rob

As I noted in a comment above, this seems like a bad way to do this. 正如我在上面的评论中所指出的,这似乎是一种不好的方法。 But, you should be able to use something like: 但是,你应该可以使用类似的东西:

:0c:
* Whatever condition
/path/to/mbox

  :0ahi
  | /path/to/perl/script

or equivalently 或者等价的

:0
* whatever condition
{
  :0c:
  /path/to/mbox
  :0ahi
  | /path/to/perl/script
}

The first recipe will cause the message to be delivered to the mbox file, but because the c flag is used processing will continue after that recipe. 第一个配方将导致消息传递到mbox文件,但由于使用了c标志,处理将在该配方之后继续。 The a flag on the following recipe specifies that it will only be used if the preceding recipe was used and completed successfully. 以下配方中的a标志指定仅在前面的配方使用并成功完成时才使用它。

The h flag on that recipe specifies that only the headers should be sent to the perl script. 该配方上的h标志指定只应将标头发送到perl脚本。 This probably won't affect it, since you say that it's getting the message from the mbox file rather than from the pipe; 这可能不会影响它,因为你说它是从mbox文件而不是从管道获取消息; but it does reduce the amount of data that needs to be sent over the pipe. 但它确实减少了需要通过管道发送的数据量。

The i flag specifies that procmail shouldn't complain if it can't send everything to the script. i标志指定如果procmail无法将所有内容发送到脚本,则不应该抱怨。 Since the script likely isn't reading from its standard input, it's possible that the pipe buffers would fill up causing procmail to receive a write error; 由于脚本可能不是从其标准输入读取,因此管道缓冲区可能会填满,导致procmail收到写入错误; although this is very unlikely to happen when sending only the headers of the message. 虽然在仅发送消息的标题时不太可能发生这种情况。

If you really need to use the Mail::Box family of modules for processing the messages, rather than something that could parse a message from the standard input, I'd suggest that you at least use a Maildir mail box rather than mbox. 如果你真的需要使用Mail :: Box系列模块来处理消息,而不是可以从标准输入解析消息的东西,我建议你至少使用Maildir邮箱而不是mbox。 There is no real specification for the mbox format, and there are many different interpretations of how it should work. mbox格式没有真正的规范,对它应该如何工作有许多不同的解释。 The differences tend to be subtle, so things could seem to be working fine until you receive a message which happens to trigger an incompatibility between different implementations (such as having a line starting with From ). 差异往往是微妙的,所以事情似乎工作得很好,直到你收到一个消息,恰好触发不同实现之间的不兼容(例如有一个以From开头的行)。 That's not even getting into the issues with locking of mbox files. 这甚至没有涉及锁定mbox文件的问题。

So I was able to come up with the simple but although probably not the best answer. 所以我能够想出简单但却可能不是最好的答案。 Since I have control over when the emails are coming in I decided to remove the lock on the process and it worked fine. 由于我可以控制电子邮件何时进入,因此我决定删除该进程的锁定并且工作正常。

So without the second colon and the "c" option it now runs the script and can see the email in the mailbox. 因此,如果没有第二个冒号和“c”选项,它现在运行脚本并可以看到邮箱中的电子邮件。

Whew...what a pain...two days wasted on a simple solution. 哇......真是一种痛苦......两天浪费在一个简单的解决方案上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM