Another 2 to 3 mail encoding problem
Peter Otten
__peter__ at web.de
Thu Aug 27 05:12:04 EDT 2020
Chris Green wrote:
> To add a little to this, the problem is definitely when I receive a
> message with UTF8 (or at least non-ascci) characters in it. My code
> is basically very simple, the main program reads an E-Mail message
> received from .forward on its standard input and makes it into an mbox
> message as follows:-
>
> msg = mailbox.mboxMessage(sys.stdin.read())
>
> it then does various tests (but doesn't change msg at all) and at the
> end delivers the message to my local mbox with:-
>
> mbx.add(msg)
>
> where mbx is an instance of mailbox.mbox.
>
>
> So, how is one supposed to handle this, should I encode the incoming
> message somewhere?
>
This is what I'd try. Or just read the raw bytes:
data = sys.stdin.detach().read()
msg = mailbox.mboxMessage(data)
More information about the Python-list
mailing list