Skip to content

Commit

Permalink
MailboxLoginError raise, ParamConverter.convert ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
ikvk committed Nov 17, 2021
1 parent fbddf10 commit 6151489
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 59 deletions.
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,9 @@ Big thanks to people who helped develop this library:
`edkedk99 <https://github.com/edkedk99>`_,
`UlisseMini <https://github.com/UlisseMini>`_,
`Nicarex <https://github.com/Nicarex>`_,
`RanjithNair1980 <https://github.com/RanjithNair1980>`_
`RanjithNair1980 <https://github.com/RanjithNair1980>`_,
`NickC-NZ <https://github.com/NickC-NZ>`_,
`mweinelt <https://github.com/mweinelt>`_

Donate
------
Expand Down
5 changes: 5 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.50.0
======
* Fix MailboxLoginError was never raise
* ParamConverter.convert now order search keys by alphabet - guarantees a repeatable result for query builder

0.49.1
======
* Fix support for python 3.5
Expand Down
2 changes: 1 addition & 1 deletion imap_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
from .utils import EmailAddress
from .errors import *

__version__ = '0.49.1'
__version__ = '0.50.0'
3 changes: 2 additions & 1 deletion imap_tools/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def _get_mailbox_client(self) -> imaplib.IMAP4:
raise NotImplementedError

def login(self, username: str, password: str, initial_folder: Optional[str] = 'INBOX') -> 'BaseMailBox':
login_result = self.box.login(username, password)
login_result = self.box._simple_command('LOGIN', username, self.box._quote(password)) # noqa
check_command_status(login_result, MailboxLoginError)
self.box.state = 'AUTH' # logic from self.box.login
self.folder = self.folder_manager_class(self)
if initial_folder is not None:
self.folder.set(initial_folder)
Expand Down
6 changes: 3 additions & 3 deletions imap_tools/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import datetime
import itertools
import functools
from collections import OrderedDict, UserString
from collections import UserString
from typing import Iterable, Optional, Dict, Any, List, Union

from .consts import SHORT_MONTH_NAMES
Expand Down Expand Up @@ -86,7 +86,7 @@ def __init__(
for val in converted_strings:
if not any(isinstance(val, t) for t in (str, UserString)):
raise TypeError('Unexpected type "{}" for converted part, str like obj expected'.format(type(val)))
unconverted_dict = OrderedDict({k: v for k, v in locals().items() if k in SEARCH_KEYS and v is not None})
unconverted_dict = {k: v for k, v in locals().items() if k in SEARCH_KEYS and v is not None}
self.converted_params = ParamConverter(unconverted_dict).convert()
if not any((self.converted_strings, self.converted_params)):
raise ValueError('{} expects params'.format(self.__class__.__name__))
Expand Down Expand Up @@ -154,7 +154,7 @@ def convert(self) -> List[str]:
:return: params in IMAP format
"""
converted = []
for key, raw_val in self.params.items():
for key, raw_val in sorted(self.params.items(), key=lambda x: x[0]):
for val in self._gen_values(key, raw_val):
convert_func = getattr(self, 'convert_{}'.format(key), None)
if not convert_func:
Expand Down
30 changes: 0 additions & 30 deletions tests/messages/plain_emails/raw_email_multiple_from.eml

This file was deleted.

22 changes: 0 additions & 22 deletions tests/messages_data/plain_emails/raw_email_multiple_from.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_logic_operators(self):
'(OR OR OR ON 1-Oct-2019 ON 10-Oct-2019 ON 15-Oct-2019 ON 20-Oct-2019)')
self.assertEqual(
A(OR(from_='[email protected]', text='"the text"'), NOT(OR(A(answered=False), A(new=True))), to='[email protected]'),
'((OR TEXT "\\"the text\\"" FROM "[email protected]") NOT ((OR (UNANSWERED) (NEW))) TO "[email protected]")')
'((OR FROM "[email protected]" TEXT "\\"the text\\"") NOT ((OR (UNANSWERED) (NEW))) TO "[email protected]")')

def test_header(self):
header = H('key1', 'val1')
Expand Down

0 comments on commit 6151489

Please sign in to comment.