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

StackOverflow https://stackoverflow.com/questions/18447924

  •  26-06-2022
  •  | 
  •  

Question

I'm on a Red Hat installation. 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.

  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.

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.

Thanks Rob

Was it helpful?

Solution

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. The a flag on the following recipe specifies that it will only be used if the preceding recipe was used and completed successfully.

The h flag on that recipe specifies that only the headers should be sent to the perl script. This probably won't affect it, since you say that it's getting the message from the mbox file rather than from the pipe; 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. 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; 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. There is no real specification for the mbox format, and there are many different interpretations of how it should work. 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). That's not even getting into the issues with locking of mbox files.

OTHER TIPS

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.

Whew...what a pain...two days wasted on a simple solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top