Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56416
| Date | 2013-10-08 17:25 +0200 |
|---|---|
| From | Antoon Pardon <antoon.pardon@rece.vub.ac.be> |
| Subject | Re: parsing email from stdin |
| References | <5253F884.7020306@rece.vub.ac.be> <525415B4.1030208@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.858.1381246032.18130.python-list@python.org> (permalink) |
Op 08-10-13 16:24, Andreas Perstinger schreef:
> On 08.10.2013 14:20, Antoon Pardon wrote:
>> As I don't know what encoding these messages will be in, I thought it
>> would be prudent to read stdin as binary data.
>>
>> Using python 3.3 on a debian box I have the following code.
>>
>> #!/usr/bin/python3
>>
>> import sys
>> from email import message_from_file
>>
>> sys.stdin = sys.stdin.detach()
>> msg = message_from_file(sys.stdin)
>
> Looking at the docs, I've found there is also "message_from_binary_file"
> which works for me with your code.
>
> http://docs.python.org/3/library/email.parser.html#email.message_from_binary_file
>
I can't try that out right now, but I had a look at the code and the
ByteParser that is mentioned their looks like this:
class BytesFeedParser(FeedParser):
"""Like FeedParser, but feed accepts bytes."""
def feed(self, data):
super().feed(data.decode('ascii', 'surrogateescape'))
Somehow I doubt that trying to decode my utf-8 stream as if it was
ascii will work.
--
Antoon Pardon
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: parsing email from stdin Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-10-08 17:25 +0200
csiph-web