Nicholas Cole wrote: >On Wed, Sep 24, 2008 at 8:25 PM, Nicholas Cole <[EMAIL PROTECTED]> wrote: >> My naive attempt to convert a MIMEText message part to quoted >> printable (having read the documentation) looked something like this: >> >> E = email.mime.text.MIMEText("This is some text") >> email.encoders.encode_quopri(E) >> print E.as_string() >> >> But it yields a message with two Content-Transfer-Encoding headers.
We do E = email.mime.text.MIMEText("This is some text") del E.['content-transfer_encoding'] email.encoders.encode_quopri(E) >> I'm assuming that this is not a bug - but what is "The Right Way"(TM) >> to change the encoding of text? > >I can't see that this isn't a bug - in that encode_quopri is (as the >documentation says) adding a header, but not replacing the one that >was there already. > >But I am confused. Doing this results in a truly mangled message, >suggesting that encode_quopri is not as aware of existing encoding as >I thought: > >E = email.mime.text.MIMEText("This is some text") >email.encoders.encode_quopri(E) >email.encoders.encode_quopri(E) Yes, doubly encoding the payload will result in a payload that has to be doubly decoded. I suppose the ideal solution to all of this is that the encoder should first look at the existing Content-Transfer_Encoding header if any to see if the payload is already encoded, and if no header, encode and add the header; if existing header with target encoding, do nothing, and if existing header with other encoding, decode, encode and replace the header. However it doesn't work that way. >So, it looks like I'm going to be better off using the quopri module >directly... Consider this email.Charset.add_charset('us-ascii', body_enc=email.Charset.QP) E = email.mime.text.MIMEText("This is some text") print E.as_string() -- Mark Sapiro <[EMAIL PROTECTED]> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan _______________________________________________ Email-SIG mailing list Email-SIG@python.org Your options: http://mail.python.org/mailman/options/email-sig/archive%40mail-archive.com