[Tutor] parse emails as they come in

Steve Willoughby steve at alchemy.com
Wed Apr 2 11:50:18 CEST 2008


linuxian iandsd wrote:
> well, i don't know how to pipe the file to my script !!

It's how procmail works.  Presuming you looked up how to write
a procmail rule to save the body of your mail into a file, you
should also see right next to it the instructions for piping
the message to a program.  (It also can be found by a quick
Google search, for future reference if you want a quick answer.)

You just put a "|" symbol in front of the script name.

To save the message to a file, you'd say something like

:0:
*Subject:.*pattern to look for
/home/me/temp_input_file$date$time

To pipe it to your script, you'd say something like

:0
*Subject:.*pattern to look for
|/home/me/scriptname

For more information see procmailrc(5) and procmailex(5).

Your Python script will see the message input on stdin.

> 
> On Wed, Apr 2, 2008 at 7:18 AM, Steve Willoughby <steve at alchemy.com> wrote:
> 
>> 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