Skip to content

Commit

Permalink
fix: amazon handle arriving early emails (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
firstof9 authored Dec 3, 2021
2 parents fc09eb5 + efce7ce commit 45cc52f
Show file tree
Hide file tree
Showing 5 changed files with 1,599 additions and 2 deletions.
2 changes: 1 addition & 1 deletion custom_components/mail_and_packages/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
AMAZON_HUB_SUBJECT = "ready for pickup from Amazon Hub Locker"
AMAZON_HUB_SUBJECT_SEARCH = "(You have a package to pick up)(.*)(\\d{6})"
AMAZON_HUB_BODY = "(Your pickup code is <b>)(\\d{6})"
AMAZON_TIME_PATTERN = "will arrive:,estimated delivery date is:,guaranteed delivery date is:,Arriving:,Arriverà:"
AMAZON_TIME_PATTERN = "will arrive:,estimated delivery date is:,guaranteed delivery date is:,Arriving:,Arriverà:,arriving:"
AMAZON_EXCEPTION_SUBJECT = "Delivery update:"
AMAZON_EXCEPTION_BODY = "running late"
AMAZON_EXCEPTION = "amazon_exception"
Expand Down
4 changes: 3 additions & 1 deletion custom_components/mail_and_packages/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,9 @@ def get_items(

start = email_msg.find(search) + len(search)
end = -1
if email_msg.find("Track your") != -1:
if email_msg.find("Previously expected:") != -1:
end = email_msg.find("Previously expected:")
elif email_msg.find("Track your") != -1:
end = email_msg.find("Track your")
elif email_msg.find("Per tracciare il tuo pacco") != -1:
end = email_msg.find("Per tracciare il tuo pacco")
Expand Down
25 changes: 25 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,31 @@ def mock_imap_amazon_shipped_alt():
yield mock_conn


@pytest.fixture()
def mock_imap_amazon_shipped_alt_2():
"""Mock imap class values."""
with patch(
"custom_components.mail_and_packages.helpers.imaplib"
) as mock_imap_amazon_shipped_alt_2:
mock_conn = mock.Mock(spec=imaplib.IMAP4_SSL)
mock_imap_amazon_shipped_alt_2.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_shipped_alt_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_it():
"""Mock imap class values."""
Expand Down
Loading

0 comments on commit 45cc52f

Please sign in to comment.