[Tutor] Re: File I/O, rfc822, and stdin/stdout

Sheila King sheila@thinkspot.net
Mon, 15 Jan 2001 11:03:10 -0800

This situation has been brought to resolution. The script I was having trouble
with before, quoted below, is now working on my web host, with the MTA
invoking it. I have installed Python 2.0 and am using that now. The web host
only had Python 1.5.1, and I believe that may have been the problem.

Of course, I've had to change the path of the script to point to my install of
Python 2.0.

On Sun, 14 Jan 2001 06:35:28 GMT, Sheila King <sheila@thinkspot.net> wrote in
comp.lang.python in article <m9b26t8f11lvfjg8a59fo8nfdcl1ro9art@4ax.com>:

:Of course, the problem with the above script, is it doesn't give me any easy
:way of handling the message headers, for filtering purposes.
:So, I now tried to combine them, into a script that would be of more use to
:#! /usr/bin/python
:import sys, rfc822
:raw_message = sys.stdin
:print inheaders
:print body
:Supposedly, it should read from stdin, retrieve the headers and body
:separately, and then write them to stdout. But I'm getting no e-mail

I would also like to thank Eric Rahmig, who went to a great deal of trouble to
write a similar script, which will actually be of great use to me, as I work
to my final goal. Here is my adaptation of his script:

#! /my/path/to/Python-2.0/python

import rfc822, sys

origheaders=rfc822.Message(sys.stdin, 0)

for h in origheaders.headers:
	print h,

for line in sys.stdin.readlines():
	print line,
print "This message was passed through a Python script"

He sent me some assistance through e-mail.
The above script is invoked on my system through a .qmail file, with the
following contents:
|/my/path/to/Python-2.0/python /my/path/to/scriptname.py

The script reads in the e-mail from stdin, and then puts it back out to
stdout, adding a short tag. The point is, now I will be able to do what I
want: analyze the headers and decide how to handle the mails.

Thanks to all for their assistance.

Sheila King