Skip to content

Commit

Permalink
MailBoxFolderManager.list result changed: item['flags'] now are tuple…
Browse files Browse the repository at this point in the history
…(str)
  • Loading branch information
ikvk committed Jun 8, 2020
1 parent 545d5a6 commit c0b8fd0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ Actions with mailbox folders
with MailBox('imap.mail.com').login('[email protected]', 'pwd') as mailbox:
# LIST
for folder_info in mailbox.folder.list('INBOX'):
print(folder_info) # {'name': 'INBOX|cats', 'delim': '|', 'flags': '\\Unmarked \\HasChildren'}
print(folder_info) # {'name': 'INBOX|cats', 'delim': '|', 'flags': ('\\Unmarked', '\\HasChildren')}
# SET
mailbox.folder.set('INBOX')
# GET
Expand Down
7 changes: 4 additions & 3 deletions imap_tools/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def exists(self, folder: str) -> bool:
def create(self, folder: str or bytes):
"""
Create folder on the server. D
*Use email box delimitor to separate folders. Example for "|" delimitor: "folder|sub folder"
*Use email box delimiter to separate folders. Example for "|" delimiter: "folder|sub folder"
"""
result = self.mailbox.box._simple_command('CREATE', self._encode_folder(folder))
check_command_status('CREATE', result)
Expand Down Expand Up @@ -96,9 +96,9 @@ def list(self, folder: str or bytes = '', search_args: str = '*', subscribed_onl
% is similar to * but it does not match a hierarchy delimiter
:param subscribed_only: bool - get only subscribed folders
:return: [dict(
flags: str - folder flags,
delim: str - delimitor,
name: str - folder name,
delim: str - delimiter,
flags: tuple(str) - folder flags,
)]
"""
folder_item_re = re.compile(r'\((?P<flags>[\S ]*)\) "(?P<delim>[\S ]+)" (?P<name>.+)')
Expand All @@ -122,5 +122,6 @@ def list(self, folder: str or bytes = '', search_args: str = '*', subscribed_onl
folder_dict['name'] = imap_utf7.decode(folder_item[1])
else:
continue
folder_dict['flags'] = tuple(folder_dict['flags'].split()) # noqa
result.append(folder_dict)
return result
2 changes: 1 addition & 1 deletion imap_tools/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def fetch(self, criteria: str or bytes = 'ALL', charset: str = 'US-ASCII', limit
:param miss_no_uid: miss emails without uid
:param mark_seen: mark emails as seen on fetch
:param reverse: in order from the larger date to the smaller
:param headers_only: get only email headers
:param headers_only: get only email headers (without text, html, attachments)
:return generator: MailMessage
"""
search_result = self.box.search(charset, self._criteria_encoder(criteria, charset))
Expand Down
4 changes: 2 additions & 2 deletions release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
0.16.0
======
* added BaseMailBox.fetch headers_only argument - get only email headers
* BaseMailBox.attachments now returns inline/forwarded nameless attachments

* BaseMailBox.attachments now can returns nameless attachments (inline/forwarded)
* MailBoxFolderManager.list result changed: item['flags'] now are tuple(str)

0.15.0
======
Expand Down
4 changes: 3 additions & 1 deletion tests/test_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ def test_folders(self):
check_folder_set = {mailbox.folder_test_base, mailbox.folder_test_temp1, mailbox.folder_test_temp2}
self.assertTrue(check_folder_set.issubset(set([i['name'] for i in folder_list])))
for folder in folder_list:
self.assertIs(type(folder['flags']), str)
self.assertIs(type(folder['delim']), str)
self.assertIs(type(folder['name']), str)
for flag in folder['flags']:
self.assertIs(type(flag), str)

# SET, GET
mailbox.folder.set(mailbox.folder_test_base)
self.assertEqual(mailbox.folder.get(), mailbox.folder_test_base)
Expand Down

0 comments on commit c0b8fd0

Please sign in to comment.