Skip to content

Commit

Permalink
Fixed bug in folder.MailBoxFolderManager.exists/list on folder names …
Browse files Browse the repository at this point in the history
…with " and \ chars
  • Loading branch information
ikvk committed Apr 23, 2020
1 parent 071c58e commit e6672d3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
18 changes: 13 additions & 5 deletions imap_tools/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,21 @@ def list(self, folder: str or bytes = '', search_args: str = '*', subscribed_onl
typ, data = self.mailbox.box._simple_command(
command, self._encode_folder(folder), self._encode_folder(search_args))
typ, data = self.mailbox.box._untagged_response(typ, data, command)
result = list()
result = []
for folder_item in data:
if not folder_item:
continue
folder_match = re.search(folder_item_re, imap_utf7.decode(folder_item))
folder_dict = folder_match.groupdict()
if folder_dict['name'].startswith('"') and folder_dict['name'].endswith('"'):
folder_dict['name'] = folder_dict['name'][1:-1]
if type(folder_item) is bytes:
folder_match = re.search(folder_item_re, imap_utf7.decode(folder_item))
folder_dict = folder_match.groupdict()
if folder_dict['name'].startswith('"') and folder_dict['name'].endswith('"'):
folder_dict['name'] = folder_dict['name'][1:-1]
elif type(folder_item) is tuple:
# when name has " or \ chars
folder_match = re.search(folder_item_re, imap_utf7.decode(folder_item[0]))
folder_dict = folder_match.groupdict()
folder_dict['name'] = imap_utf7.decode(folder_item[1])
else:
continue
result.append(folder_dict)
return result
4 changes: 4 additions & 0 deletions release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.14.2
======
* Fixed bug in folder.MailBoxFolderManager.exists/list on folder names with " and \ chars

0.14.1
======
* Fixed bug on folders names with space in folder.MailBoxFolderManager.exists/list
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='imap_tools',
version='0.14.1',
version='0.14.2',
packages=setuptools.find_packages(),
url='https://github.com/ikvk/imap_tools',
license='Apache-2.0',
Expand Down
2 changes: 0 additions & 2 deletions todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ try to imitate long poll by NOOP
check https://docs.python.org/release/3.8.1/library/email.utils.html

check possibility to implement SOCKS without/with dependencies

folder.list fails on names with \\ "" chars

0 comments on commit e6672d3

Please sign in to comment.