diff --git a/README.rst b/README.rst index 70525d4..979e4eb 100644 --- a/README.rst +++ b/README.rst @@ -258,3 +258,4 @@ Thanks to: * `Mitrich3000 `_ * `audemed44 `_ * `mkalioby `_ +* `atlas0fd00m `_ diff --git a/imap_tools/folder.py b/imap_tools/folder.py index f80ba10..2a5bfe8 100644 --- a/imap_tools/folder.py +++ b/imap_tools/folder.py @@ -104,15 +104,16 @@ def list(self, folder: str or bytes = '', search_args: str = '*', subscribed_onl """ folder_item_re = re.compile(r'\((?P[\S ]*)\) "(?P[\S ]+)" (?P.+)') command = 'LSUB' if subscribed_only else 'LIST' - typ, data = self.mailbox.box._simple_command(command, self._encode_folder(folder), search_args) + 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() for folder_item in data: if not folder_item: continue folder_match = re.search(folder_item_re, imap_utf7.decode(folder_item)) - folder = folder_match.groupdict() - if folder['name'].startswith('"') and folder['name'].endswith('"'): - folder['name'] = folder['name'][1:len(folder['name']) - 1] - result.append(folder) + folder_dict = folder_match.groupdict() + if folder_dict['name'].startswith('"') and folder_dict['name'].endswith('"'): + folder_dict['name'] = folder_dict['name'][1:-1] + result.append(folder_dict) return result diff --git a/imap_tools/imap_utf7.py b/imap_tools/imap_utf7.py index 2fc9c7b..b3e8809 100644 --- a/imap_tools/imap_utf7.py +++ b/imap_tools/imap_utf7.py @@ -12,8 +12,8 @@ # ENCODING # -------- -def _modified_base64(s): - return binascii.b2a_base64(s.encode('utf-16be')).rstrip(b'\n=').replace(b'/', b',') +def _modified_base64(value: str): + return binascii.b2a_base64(value.encode('utf-16be')).rstrip(b'\n=').replace(b'/', b',') def _do_b64(_in, r): @@ -22,45 +22,45 @@ def _do_b64(_in, r): del _in[:] -def encode(s: str) -> bytes: +def encode(value: str) -> bytes: res = [] _in = [] - for c in s: - ord_c = ord(c) + for char in value: + ord_c = ord(char) if 0x20 <= ord_c <= 0x25 or 0x27 <= ord_c <= 0x7e: _do_b64(_in, res) - res.append(c.encode()) - elif c == '&': + res.append(char.encode()) + elif char == '&': _do_b64(_in, res) res.append(b'&-') else: - _in.append(c) + _in.append(char) _do_b64(_in, res) return b''.join(res) # DECODING # -------- -def _modified_unbase64(s): - return binascii.a2b_base64(s.replace(b',', b'/') + b'===').decode('utf-16be') +def _modified_unbase64(value: bytearray): + return binascii.a2b_base64(value.replace(b',', b'/') + b'===').decode('utf-16be') -def decode(s: bytes) -> str: +def decode(value: bytes) -> str: res = [] decode_arr = bytearray() - for c in s: - if c == ord('&') and not decode_arr: + for char in value: + if char == ord('&') and not decode_arr: decode_arr.append(ord('&')) - elif c == ord('-') and decode_arr: + elif char == ord('-') and decode_arr: if len(decode_arr) == 1: res.append('&') else: res.append(_modified_unbase64(decode_arr[1:])) decode_arr = bytearray() elif decode_arr: - decode_arr.append(c) + decode_arr.append(char) else: - res.append(chr(c)) + res.append(chr(char)) if decode_arr: res.append(_modified_unbase64(decode_arr[1:])) return ''.join(res) diff --git a/release_notes.rst b/release_notes.rst index b9b9bf2..46eb120 100644 --- a/release_notes.rst +++ b/release_notes.rst @@ -1,3 +1,7 @@ +0.14.1 +====== +* Fixed bug on folders names with space in folder.MailBoxFolderManager.exists/list + 0.14.0 ====== * Improved parse logic for message.MailMessage.flags diff --git a/setup.py b/setup.py index 5f4709a..b8aa49e 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name='imap_tools', - version='0.14.0', + version='0.14.1', packages=setuptools.find_packages(), url='https://github.com/ikvk/imap_tools', license='Apache-2.0', diff --git a/todo.txt b/todo.txt index 364fdd0..d6225d9 100644 --- a/todo.txt +++ b/todo.txt @@ -3,3 +3,5 @@ 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