Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56416
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <antoon.pardon@rece.vub.ac.be> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'encoding': 0.05; 'binary': 0.07; 'sys': 0.07; 'utf-8': 0.07; 'ascii': 0.09; 'data):': 0.09; 'msg': 0.09; 'subject:parsing': 0.09; 'python': 0.11; 'def': 0.12; 'accepts': 0.16; 'andreas': 0.16; 'feed(self,': 0.16; 'received:192.168.1.4': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'trying': 0.19; 'import': 0.22; 'header:User-Agent:1': 0.23; 'looks': 0.24; "i've": 0.25; 'this:': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'work.': 0.31; 'code': 0.31; "skip:' 10": 0.31; 'class': 0.32; 'url:python': 0.33; 'skip:# 10': 0.33; 'subject:from': 0.34; "can't": 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'there': 0.35; 'doubt': 0.36; 'url:org': 0.36; 'feed': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'read': 0.60; 'mentioned': 0.61; 'url:3': 0.61; 'pardon': 0.84; 'received:195.238': 0.84; 'received:195.238.6': 0.84; 'received:belgacom.be': 0.84; 'received:isp.belgacom.be': 0.84 |
| X-Belgacom-Dynamic | yes |
| X-IronPort-Anti-Spam-Filtered | true |
| X-IronPort-Anti-Spam-Result | ApMBAOAjVFJbtpUq/2dsb2JhbAANTIM/wXWBNYMZAQEBBDhAEQsYCRYPCQMCAQIBRRMIAogOpyqKHIkUjXmBUBaEDQOYAYEvk3eBbw |
| Date | Tue, 08 Oct 2013 17:25:40 +0200 |
| From | Antoon Pardon <antoon.pardon@rece.vub.ac.be> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130922 Icedove/17.0.9 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: parsing email from stdin |
| References | <5253F884.7020306@rece.vub.ac.be> <525415B4.1030208@gmail.com> |
| In-Reply-To | <525415B4.1030208@gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.858.1381246032.18130.python-list@python.org> (permalink) |
| Lines | 36 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1381246032 news.xs4all.nl 15971 [2001:888:2000:d::a6]:38143 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:56416 |
Show key headers only | View raw
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