Python 3 how to convert a list of bytes objects to a list of strings?

Richard Damon Richard at Damon-Family.org
Fri Aug 28 10:09:18 EDT 2020


On 8/28/20 8:44 AM, Chris Green wrote:
> Stefan Ram <ram at zedat.fu-berlin.de> wrote:
>> Chris Green <cl at isbd.net> writes:
>>> Therein lies the problem, the incoming byte stream *isn't* ASCII, it's
>>> an E-Mail message which may, for example, have UTF-8 or other encoded
>>> characters in it.  Hopefully it will have an encoding given in the
>>> header but that's only if the sender is 'well behaved', one needs to
>>> be able to handle almost anything and it must be done without 'manual'
>>> interaction.
>>   I would make a difference between "scoring" and "transport":
>>
>>   To transfer a message into an mbox it can be transferred as it is.
>>   Just the bytes from the POP3 server. Let mutt deal with them.
>>
> That's what I do at present in Python 2, the problem is that Python 3
> complains when I use the standard library to put the message into the
> mbox.
>
> I want to transport the message into my mbox and Python 3 won't do it
> without knowing how it's encoded whereas Python 2 just stuffed it in
> there 'as is'.
>
> I want Python 3's mailbox class to juyst put what I tell it (even if
> mis-formatted or mis-encoded) into the mbox.
>
It looks like the mailbox class has gotten 'pickier' in Python 3, and
won't accept a message as a byte string, just as either a email message
or a real string. My guess would be that 'simplest' path would be to
convert your message into a parsed Message class, and add that.

-- 
Richard Damon



More information about the Python-list mailing list