From 01c621d86c06cfaabc5256ea45a4945694e3efd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Sun, 11 Oct 2020 23:01:08 +0200 Subject: [PATCH] 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 --- offlineimap/folder/IMAP.py | 2 +- offlineimap/imaputil.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index 53004a8..342c102 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -91,7 +91,7 @@ class IMAPFolder(BaseFolder): name = self.getfullname() if self.repository.account.utf_8_support: name = imaputil.utf8_IMAP(name) - return name + return imaputil.foldername_to_imapname(name) # Interface from BaseFolder def suggeststhreads(self): diff --git a/offlineimap/imaputil.py b/offlineimap/imaputil.py index 8509edf..4083d34 100644 --- a/offlineimap/imaputil.py +++ b/offlineimap/imaputil.py @@ -435,3 +435,23 @@ def imap4_utf_7(name): 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 \ No newline at end of file