I'm writing an email parser for python 2.7 that will be invoked via sendmail using an alias, parsed using the email module and then processed and stored into an oracle database:
From /etc/aliases:
myalias: | /my/python/script.py
I'm having trouble "slurping" all of stdin into a string object that I can use with the email module:
import email
# Slurp stdin and store into message
message =
msg = email.message_from_string(message)
# Do something with it
print msg['Subject']
What would be the most efficient way to do this? I've tried stdin.readlines() but it ends up as a list.
Thx for any help. (Sorry if this is noobish... I'm a perl convert and been forced to standardize my tools using python and this is only my second script. Well not really "forced", I've been wanting to do this for some time but not under the gun of a deadline like now)
sys.stdin.readlines()
returns a list of lines. If what you want is one long (multi-line) string, use sys.stdin.read()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With