Instead of calling sys.stdin.readlines() , then sys.stdin.readlines() over and passing the strings to email.FeedParser.FeedParser().feed() , as suggested by Michael, you should pass the file object directly to the email parser.
The standard library provides the conveinience function, email.message_from_file(fp) , for this purpose. Thus, your code becomes much simpler:
import email msg = email.message_from_file(sys.stdin)
lfaraone
source share