Allow folder names with atom specials

This patch allows using folders with atom-specials like
"(", ")", spaces,...

We need quotes the folder name if it includes this special
characters.

Closes #4
This commit is contained in:
Rodolfo García Peñas (kix) 2020-10-11 23:01:08 +02:00
parent 011cfbc670
commit 01c621d86c
2 changed files with 21 additions and 1 deletions

View File

@ -91,7 +91,7 @@ class IMAPFolder(BaseFolder):
name = self.getfullname() name = self.getfullname()
if self.repository.account.utf_8_support: if self.repository.account.utf_8_support:
name = imaputil.utf8_IMAP(name) name = imaputil.utf8_IMAP(name)
return name return imaputil.foldername_to_imapname(name)
# Interface from BaseFolder # Interface from BaseFolder
def suggeststhreads(self): def suggeststhreads(self):

View File

@ -435,3 +435,23 @@ def imap4_utf_7(name):
codecs.register(imap4_utf_7) codecs.register(imap4_utf_7)
def foldername_to_imapname(folder_name):
"""
This function returns the folder_name ready to send to the
IMAP server. It tests if the folder_name has special characters
Then, quote it.
Args:
folder_name: Folder's name
Returns: The folder_name quoted if needed
"""
# If name includes some of these characters, quote it
atom_specials = [' ', '/', '(', ')', '{', '}']
if any((c in atom_specials) for c in folder_name):
folder_name = '"' + folder_name + '"'
return folder_name