Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when creating folders with spaces on GMail's IMAP server #58

Closed
piyueh opened this issue Mar 10, 2021 · 3 comments · Fixed by #80
Closed

Error when creating folders with spaces on GMail's IMAP server #58

piyueh opened this issue Mar 10, 2021 · 3 comments · Fixed by #80

Comments

@piyueh
Copy link
Contributor

piyueh commented Mar 10, 2021

General informations

Configuration file offlineimaprc

[general]
metadata = $HOME/offlineimap_tmp
accounts = test

[Account test]
localrepository = test-local
remoterepository = test-remote

[Repository test-local]
type = GmailMaildir
localfolders = $HOME/offlineimap_test
sep = .

[Repository test-remote]
type = Gmail
remoteuser = <account>
auth_mechanisms = XOAUTH2
oauth2_client_id = <id>
oauth2_client_secret = <secret>
oauth2_access_token = <token>
folderfilter = lambda folder: folder  == "Test ABC"

Logs, error

OfflineIMAP 7.3.0
  Licensed under the GNU GPL v2 or any later version (with an OpenSSL exception)
imaplib2 v3.06, Python v3.9.2, OpenSSL 1.1.1j  16 Feb 2021
Account sync test:
 *** Processing account test
 Establishing connection to imap.gmail.com:993 (test-remote)
 Creating folder Test ABC[test-remote]
 ERROR: While attempting to sync account 'test'
  CREATE command error: BAD [b'Could not parse command']. Data: b'HENK8 CREATE Test ABC\r\n'
 *** Finished account 'test' in 0:00
ERROR: Exceptions occurred during the run!
ERROR: While attempting to sync account 'test'
  CREATE command error: BAD [b'Could not parse command']. Data: b'HENK8 CREATE Test ABC\r\n'

Traceback:
  File "/usr/lib/python3.9/site-packages/offlineimap/accounts.py", line 298, in syncrunner
    self.__sync()
  File "/usr/lib/python3.9/site-packages/offlineimap/accounts.py", line 377, in __sync
    remoterepos.sync_folder_structure(localrepos, statusrepos)
  File "/usr/lib/python3.9/site-packages/offlineimap/repository/Base.py", line 349, in sync_folder_structure
    remote_repo.makefolder(remote_name)
  File "/usr/lib/python3.9/site-packages/offlineimap/repository/IMAP.py", line 816, in makefolder
    self.makefolder_single(folder_path)
  File "/usr/lib/python3.9/site-packages/offlineimap/repository/IMAP.py", line 839, in makefolder_single
    result = imapobj.create(foldername)
  File "/usr/lib/python3.9/site-packages/imaplib2/imaplib2.py", line 767, in create
    return self._simple_command('CREATE', mailbox, **kw)
  File "/usr/lib/python3.9/site-packages/imaplib2/imaplib2.py", line 1705, in _simple_command
    return self._command_complete(self._command(name, *args), kw)
  File "/usr/lib/python3.9/site-packages/imaplib2/imaplib2.py", line 1452, in _command_complete
    raise self.error('%s command error: %s %s. Data: %.100s' % (rqb.name, typ, dat, rqb.data))

Steps to reproduce the error

Step 1: create a test maildir
$ mkdir -p \
    $HOME/offlineimap_test/Test\ ABC/cur
    $HOME/offlineimap_test/Test\ ABC/new
    $HOME/offlineimap_test/Test\ ABC/tmp
Step 2: run offlineimap
$ offlineimap -o -a test -c ${HOME}/config.test

Description

When offlineimap tried to create a folder on GMail's IMAP server, and when that folder had spaces in its folder name, the creation failed.

Temporary solution

I have a workaround on my machine: wrapping folder names with double-quotes. However, I believe this workaround is not robust. If a folder name already has double-quotes in its name, I don't know if this workaround is going to work (though I doubt how many people have quotation marks in their folders' names). Here's my workaround:

Replace line 839 in repository/IMAP.py:

result = imapobj.create(foldername)

with

result = imapobj.create("\"{}\"".format(foldername))
@nicolas33
Copy link
Member

This trick might be ok in usual python code. However, this requires to check how it's translated by imaplib2 and if this is IMAP-compliant.

thekix added a commit to thekix/offlineimap3 that referenced this issue Aug 7, 2021
This patch adds support to create and delete folders with the space
character.

When the folder includes spaces, all the folder name must be quoted.

Close: OfflineIMAP#58

Signed-off-by: Rodolfo García Peñas (kix) <kix@kix.es>
@thekix thekix closed this as completed in #80 Aug 7, 2021
@thekix
Copy link
Member

thekix commented Aug 7, 2021

Hi @piyueh !

please, could you try now?

Thanks a lot,
Best regards,
kix

@piyueh
Copy link
Contributor Author

piyueh commented Aug 9, 2021

@thekix Yes, it works for me now! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants