On 29Aug2020 16:50, Chris Green <c...@isbd.net> wrote: >However the problem appears to be that internally in Python 3 mailbox >class there is an assumption that it's being given 'ascii'. Here's >the error (and I'm doing no processing of the message at all):- > > Traceback (most recent call last): > File "/home/chris/.mutt/bin/filter.py", line 102, in <module> > mailLib.deliverMboxMsg(dest, msg, log) > File "/home/chris/.mutt/bin/mailLib.py", line 52, in deliverMboxMsg > mbx.add(msg) [...]
Here is the entire save-to-mbox code form my own mailfiler: text = M.as_string(True).replace('\nFrom ', '\n>From ') with open(folderpath, "a") as mboxfp: mboxfp.write(text) where M is the current message, a Message object. Note that this does _not_ assume ASCII output. The process here is: - transcribe the message to a Python 3 str (so Unicode code points) - replace embedded "From " to protect the mbox format - open the mbox for append - the _default_ encoding is utf-8 - write the message in utf-8 because of the open mode This sidesteps the library you're using which may well do something ASCII based. And it has _never_ failed for me. Cheers, Cameron Simpson <c...@cskk.id.au> -- https://mail.python.org/mailman/listinfo/python-list