Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51739

Re: email 8bit encoding

Newsgroups comp.lang.python
Date 2013-08-01 08:20 -0700
References <36aa5535-a821-4d7e-8414-1e40820705e4@googlegroups.com> <mailman.12.1375272464.1251.python-list@python.org>
Message-ID <1672c141-7d90-477a-a62c-8e0e97bda9be@googlegroups.com> (permalink)
Subject Re: email 8bit encoding
From rurpy@yahoo.com

Show all headers | View raw


On 07/29/2013 02:52 PM, Antoon Pardon wrote:
> Op 29-07-13 01:41, rurpy@yahoo.com schreef:
>> How, using Python-3.3's email module, do I "flatten" (I think
>> that's the right term) a Message object to get utf-8 encoded
>> body with the headers:
>>   Content-Type: text/plain; charset=UTF-8
>>   Content-Transfer-Encoding: 8bit
>> when the message payload was set to a python (unicode) string?
>>
> 
> I am just trying out some things for my self on python 3.2 so
> be sure to test this out but you could try the following.
> 
> msg.set_charset('utf-8')
> msg['Content-Transfer-Encoding'] = '8bit'

You can do that but the problem occurs when you call 
email.generator.flatten (or it is called on your behalf by 
somthing like smtplib.send_message) with such a message.  
flatten always assumes a 7bit encoding and uses the ascii 
codec to encode the message resulting in a UnicodeEncode 
exception when it hits an 8 bit character.  So gymnastics 
like W. Trevor King implemented are necessary.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

email 8bit encoding rurpy@yahoo.com - 2013-07-28 16:41 -0700
  Re: [python] email 8bit encoding "W. Trevor King" <wking@tremily.us> - 2013-07-28 23:16 -0700
    Re: [python] email 8bit encoding rurpy@yahoo.com - 2013-07-29 20:56 -0700
  Re: email 8bit encoding Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-07-29 22:52 +0200
    Re: email 8bit encoding rurpy@yahoo.com - 2013-08-01 08:20 -0700
      Re: email 8bit encoding Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-02 13:19 +0200
      Re: email 8bit encoding Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-02 14:12 +0200

csiph-web