Skip to content

Commit

Permalink
fix: amazon uk email format change
Browse files Browse the repository at this point in the history
* fixes #575
  • Loading branch information
firstof9 committed Nov 17, 2021
1 parent d4484d3 commit 9855502
Show file tree
Hide file tree
Showing 4 changed files with 1,520 additions and 0 deletions.
9 changes: 9 additions & 0 deletions custom_components/mail_and_packages/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,15 @@ def get_items(
)
continue
email_msg = email_msg.decode("utf-8", "ignore")

# Check message body for order number
if (
(found := pattern.findall(email_msg))
and len(found) > 0
and found[0] not in order_number
):
order_number.append(found[0])

searches = const.AMAZON_TIME_PATTERN.split(",")
for search in searches:
_LOGGER.debug("Looking for: %s", search)
Expand Down
25 changes: 25 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,31 @@ def mock_imap_amazon_shipped_uk():
yield mock_conn


@pytest.fixture()
def mock_imap_amazon_shipped_uk_2():
"""Mock imap class values."""
with patch(
"custom_components.mail_and_packages.helpers.imaplib"
) as mock_imap_amazon_shipped:
mock_conn = mock.Mock(spec=imaplib.IMAP4_SSL)
mock_imap_amazon_shipped.IMAP4_SSL.return_value = mock_conn

mock_conn.login.return_value = (
"OK",
[b"[email protected] authenticated (Success)"],
)
mock_conn.list.return_value = (
"OK",
[b'(\\HasNoChildren) "/" "INBOX"'],
)
mock_conn.search.return_value = ("OK", [b"1"])
f = open("tests/test_emails/amazon_uk_shipped_2.eml", "r")
email_file = f.read()
mock_conn.fetch.return_value = ("OK", [(b"", email_file.encode("utf-8"))])
mock_conn.select.return_value = ("OK", [])
yield mock_conn


@pytest.fixture()
def mock_imap_amazon_shipped_alt():
"""Mock imap class values."""
Expand Down
Loading

0 comments on commit 9855502

Please sign in to comment.