On Tue, May 16, 2017 at 12:42:32PM +1000, Cameron Simpson wrote: > On 16May2017 16:14, Yubin Ruan <ablacktsh...@gmail.com> wrote: > >On Sun, May 14, 2017 at 09:33:46AM +1000, Cameron Simpson wrote: > >>The other common solution for IMAP mail accounts is offlineimap, which will > >>mirror IMAP accounts to local storage. > [...] > >Yes offlineimap _is_ very tricky to setup. It cannot handle non-ascii > >characters correctly. I have several folders on the Gamil server whose name > >is in Chinese. > >I setup a `nametrans' in the .offlineimaprc: > > nametrans = lambda foldername: > > foldername.decode('imap4-utf-7').encode('utf-8') > > You also have a reverse name trans, yes? Both are needed. And one should > take care that they really are the reverse of each other.
Hmm...turns out that I have too many accounts set up so that I forget one of the reverse namestrans. > > >it works great in the first download, but will throw some encoding/decoding > >errors > >in the sync afterwards: > > 'ascii' codec can't decode byte 0xe9 in position 8: ordinal not in > > range(128) > > > >I don't know why a software would only support ascii in the 21st century... > > The offlineimap authors are definitely not pure Western > can-get-by-with-ASCII people, so I expect they're aware of this shortcoming. > > Is imap4-utf-7 a known encoding? My local Python 3 says: > > % python3 -c 'print(repr(b"foo".decode("imap4-utf-7")))' > Traceback (most recent call last): > File "<string>", line 1, in <module> > LookupError: unknown encoding: imap4-utf-7 > > It is possible that your exception above comes from another part of the > code; what is the stack trace? It would also be useful to hack things to > print the repr of the undecodable string: do you know it is a mailbox name? > > IIRC offlineimap uses python 2, which is a bit vague in distinguishing > strings and bytes. Here is the encode/decode python script I use currently: https://gist.github.com/gauteh/5402888 -- Yubin