Re: Reading EmailMessage from file

2018-07-16 Thread Roel Schroeven
Skip Montanaro schreef op 16/07/2018 3:31: So, problem solved. The example I originally referred to clearly requires the caller know the encoding of the input file. When you don't know the encoding, you need bytes. The BytesParser gave me that. Also, I must admit to having not completely read th

Re: Reading EmailMessage from file

2018-07-16 Thread Jon Ribbens
On 2018-07-16, Skip Montanaro wrote: >> What are you actually trying to do? You're talking like you're trying >> to read an existing RFC822 email-with-headers from a file, but you're >> showing code that creates a new email with body content set from >> a file, which is a completely different thin

Re: Reading EmailMessage from file

2018-07-16 Thread Paul Moore
On 16 July 2018 at 02:31, Skip Montanaro wrote: >> What are you actually trying to do? You're talking like you're trying >> to read an existing RFC822 email-with-headers from a file, but you're >> showing code that creates a new email with body content set from >> a file, which is a completely dif

Re: Reading EmailMessage from file

2018-07-15 Thread Richard Damon
A raw email message should be treated as a ‘bag of bytes’, and in processing it, the encoding of the various sections determined by headers in the message (or taking defined defaults if not specified). I suspect that means that you should read as a binary file. I would hope that the module has t

Re: Reading EmailMessage from file

2018-07-15 Thread Skip Montanaro
> What are you actually trying to do? You're talking like you're trying > to read an existing RFC822 email-with-headers from a file, but you're > showing code that creates a new email with body content set from > a file, which is a completely different thing. Yes, that's exactly what I'm trying to

Re: Reading EmailMessage from file

2018-07-15 Thread Cameron Simpson
On 15Jul2018 23:34, Jon Ribbens wrote: On 2018-07-15, Skip Montanaro wrote: I have an email message in a file (see attached). Attachments don't work here. something like this should construct an email message from the file: from email.message import EmailMessage msg = EmailMessage() fp =

Re: Reading EmailMessage from file

2018-07-15 Thread Jon Ribbens
On 2018-07-15, Skip Montanaro wrote: > I have an email message in a file (see attached). Attachments don't work here. > something like this should construct an email message from the file: > from email.message import EmailMessage msg = EmailMessage() fp = open("/home/skip/tmp/7948

Reading EmailMessage from file

2018-07-15 Thread Skip Montanaro
I have an email message in a file (see attached). According to this page: https://docs.python.org/3/library/email.examples.html something like this should construct an email message from the file: >>> from email.message import EmailMessage >>> msg = EmailMessage() >>> fp = open("/home/skip/tmp/7