looking for command-pipe performance advice

Sheila King sheila at spamcop.net
Thu Apr 5 20:57:56 EDT 2001


On 5 Apr 2001 23:45:12 -0000, jason-dated-af27661e5bfe243d at mastaler.com wrote
in comp.lang.python in article
<mailman.986514369.6320.python-list at python.org>:

:Can anyone suggest a more efficient, and/or higher performance method
:of reading in a mail message as standard input, and then feeding the
:message to a command pipe (qmail in my case).
:
:I do need to examine the mail headers, but don't need to look at the
:message body at all.
:
:Here is what I'm doing currently:

Why do you need the cStringIO module/objects? I do something similar with my
email, and don't use that at all.

:--------------------------------------------------------------------
:
:import os, rfc822, cStringIO
:
:raw_message = sys.stdin.read()       
:message = cStringIO.StringIO(raw_message)
:headers = rfc822.Message(message)    
:
:# header examination and processing deleted
:
:inject_message = os.popen('/var/qmail/bin/qmail-inject','w')
:inject_message.write(raw_message)
:inject_message.close()
:
:--------------------------------------------------------------------

Couldn't you just do this?

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

# header examination #

inject_message = os.popen('/var/qmail/bin/qmail-inject', 'w')
inject_message.write(headers+'\n')
inject_message.write(sys.stdin.read())
inject_message.close()


It saves on importing the cStingIO module, and you only have to work with the
body once, fewer variable assignments.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




More information about the Python-list mailing list