[Tutor] parse emails as they come in

Steve Willoughby steve at alchemy.com
Wed Apr 2 09:18:00 CEST 2008

linuxian iandsd wrote:
> ok - as i mentioned in my first email i use procmail to put THE BODY of all
> incoming mail into a file (that is one per incoming email as i use the
> variable $date-$time in the name).
> now this file can contain only one email but it can also contain 2 or more
> (this happens if for example there is a dns problem in the internet, so mail
> can't make it, but once internet recovers from the dns problem mail rushes
> in & we may have multiple messages per file. this is also true is i do this

Using $date-$time is insufficient since I'll wager a dozen doughnuts
that the resolution of $time isn't small enough compared to the speed
messages can arrive.

But as I tried to explain in my previous mail, this is a problem you
don't have to solve.  By choosing to use procmail to dump a file with
a non-unique name, you create a race condition you then have to deal
with in your code.

If, on the other hand, you use procmail to _filter_ the message
through your script, this cannot possibly happen.  You'll get an
invocation of your script per message every time.  If you have
your script directly dump the data into MySQL you never need to
write any disk files at all.

More information about the Tutor mailing list