rgladwell / imap-upload

Python script for uploading a local mbox file to IMAP4 server.
Other
132 stars 31 forks source link

list_boxes error #37

Closed poldy79 closed 2 years ago

poldy79 commented 2 years ago

Using current master (684cd23) with python 3.9.2 on debian bullseye with IMAPClient==2.2.0 option --list_boxes requires --google-takeout. Furthermore it then fails with

IMAP Upload (v2.0.0)
Connecting to mail.your-server.de:993.
Just list mail boxes!
An unknown error has occurred [679]:  cannot use a string pattern on a bytes-like object

It seems that uploader.list_boxes() returns the list of boxes as a byte stream, which has to be decoded to a string.

I suspect, that this is because of a change in IMAPClient. You might add a requirements.txt which states the latest version known to work.

rgladwell commented 2 years ago

That's annoying. Any suggestions for a possible fix?

poldy79 commented 2 years ago

First of all, I would try a old version of IMAPClient, suggestions which version to use? Secondly, we have to figure out the encoding of the returned data, to properly decode them. UTF-8 works for INBOX, but it may depends on the Server... I am not very into the IMAP-Protocol.

Usually these issues arise with a python 2 to 3 migration, as in python 3 strings are always unicode and it strictly distinguishes between strings and byte-arrays (e.g. what a socket returns etc.).

poldy79 commented 2 years ago

ok - i figured out, that box has to be decoded using box = imap_utf7.decode(box) Then --list_boxes will print the folder-structure with german umlauts and ß, e.g. "ößfolder".

I can provide a pull request, but I suspect this is not the only problem of this kind.

poldy79 commented 2 years ago

I have created https://github.com/rgladwell/imap-upload/pull/39 to solve this issue

rgladwell commented 2 years ago

Thanks @poldy79.