"Chris Gonnerman" <chris.gonnerman at usa.net> wrote in message news:mailman.987130158.1818.python-list at python.org... > The rfc822 module assumes that everything after the first blank line > is message body, and it does in fact "consume" it. The file object > you give when instantiating the class winds up in the instance > variable fp. > In fact the Message method goes to considerable lengths *not* to consume the data which follows the headers, leaving it up to you to read the body of the message (using the fp instance variable of the message, for consistency). > In other words, your variable named "message_headers" actually > "contains" the entire message, not just the headers. > This should not be the case. The problem is more likely that the code after the call to rfc822.Message is assuming that everything up to end of file is the message body, reading it, and therefore consuming the following message, headers and all. If this is not the case then you are probably reading a mailbox. In which case a look at the mailbox module wouldn't hurt. Certainly you are likely to get problems reading RFC822-compliant mail messages one after the other unless there is some concept of "structure" (such as a mailbox) to help you separate the individual messages. The standard define messages in terms of a data stream which ends at the end of the body. regards Steve > If you want blocks of header-like data without bodies, look at my > QChunk.py module; my key-data pairs are not completely RFC 822 > compliant, but the code might give you some ideas. > > All my projects (including QChunk.py) are at: > > http://newcenturycomputers.net/projects > > On the other hand, if you are processing a mailbox, look into the > mailbox module. It handles multiple messages in a single file or > file-like object. > > ----- Original Message ----- > From: "Graham Guttocks" <graham_guttocks at yahoo.co.nz> > Subject: reusing sys.stdin? > > > > Greetings, > > > > Something I don't understand. In my program I need to access > > sys.stdin from two different functions in the following manner: > > > > import rfc822,sys > > message_headers = rfc822.Message(sys.stdin) > > > > The problem is that after the first Message instance is created, > > sys.stdin seems to be absorbed so that it is no longer around for the > > second call to rfc822.Message(). Why is this, and is there a way to > > keep sys.stdin for disappearing so I can use it a second time? > > > > Regards, > > Graham > > >
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4