imapcp icon indicating copy to clipboard operation
imapcp copied to clipboard

Folder names with spaces result in an Assertion error

Open FMJansen opened this issue 8 years ago • 6 comments

When syncing between two Dovecot servers, of which the first has a folder with a name containing a space and the second has no content, something like the following happens:

Syncing b'Deleted items' into b'Deleted items'
Traceback (most recent call last):
  File "imapcp.py", line 244, in <module>
    app.run()
  File "imapcp.py", line 171, in run
    assert res == 'OK', (res, data)
AssertionError: ('NO', [b"Mailbox doesn't exist: Deleted"])

FMJansen avatar Jan 04 '18 19:01 FMJansen

Apparently, it needs to be surrounded by quotes (thanks to Max).

Changing line 142 and 143 from...

srcfolder = f.name
dstfolder = f.getPathBytes(dsttype, trim=options.trim)

...to the following solves the problem (of course this isn’t the prettiest code like, though).

srcfolder = '"{}"'.format(f.name.decode("utf-8"))
dstfolder = '"{}"'.format(f.getPathBytes(dsttype, trim=options.trim).decode("utf-8"))

FMJansen avatar Jan 04 '18 19:01 FMJansen

That's what I was just writing: dovecot usually likes quoting, so adding that as a quick fix will work.

Anyway, to support different IMAP servers, some additional if/then login will be needed.

gtozzi avatar Jan 04 '18 19:01 gtozzi

Nice haha, but then I guess a PR with these changes wouldn’t really help, right?

FMJansen avatar Jan 04 '18 19:01 FMJansen

If you can add some if to apply that only when the mailserver is dovecot, I will happily merge it

gtozzi avatar Jan 04 '18 20:01 gtozzi

Ooh, right. I’ll look into that! Just found out this breaks the exclude option though, since match doesn’t like it.

Traceback (most recent call last):
  File "imapcp.py", line 243, in <module>
    app.run()
  File "imapcp.py", line 153, in run
    if e.match(srcfolder):
TypeError: can't use a bytes pattern on a string-like object

FMJansen avatar Jan 04 '18 20:01 FMJansen

ANOTHER

That fix also solves the above error

mbithy avatar Aug 06 '18 11:08 mbithy