Skip to content

Commit

Permalink
Merge pull request #46 from smkent/ignore-missing-identity
Browse files Browse the repository at this point in the history
Continue processing email threads on email handle callback error
  • Loading branch information
smkent authored Dec 1, 2023
2 parents 692dc25 + 5834098 commit d7e6a17
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
6 changes: 4 additions & 2 deletions tests/method_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def make_email_event(
)


def make_identity_get_response() -> IdentityGetResponse:
def make_identity_get_response(
email: str = "[email protected]",
) -> IdentityGetResponse:
return IdentityGetResponse(
account_id="u1138",
state="2187",
Expand All @@ -67,7 +69,7 @@ def make_identity_get_response() -> IdentityGetResponse:
Identity(
id="ID1",
name="ness",
email="[email protected]",
email=email,
reply_to="[email protected]",
bcc=None,
text_signature=None,
Expand Down
46 changes: 46 additions & 0 deletions tests/test_waffles.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,52 @@ def test_wafflesbot(
mock_request()


def test_wafflesbot_no_matching_identity(
wafflesbot: Waffles,
mock_request: mock.MagicMock,
mock_events: List[sseclient.Event],
) -> None:
original_email_read = False
original_email_in_inbox = True
wafflesbot.client.live_mode = True
mock_events.append(make_email_event(email_state="1118"))
mock_events.append(make_email_event(email_state="1119"))
expected_calls: List[mock._Call] = []
expected_calls.append(make_mailbox_get_call("pigeonhole"))
expected_calls.append(make_email_changes_call(since_state="1118"))
expected_calls.append(
make_email_get_call(properties=["threadId", "mailboxIds"])
)
expected_calls.append(make_thread_get_call())
expected_calls.append(make_email_get_call(fetch_all_body_values=True))
expected_calls.append(mock.call(IdentityGet()))
mock_responses: List[Any] = []
mock_responses.append(make_mailbox_get_response("MBX50", "pigeonhole"))
mock_responses.append(make_email_changes_response())
mock_responses.append(
make_email_get_response(
is_read=original_email_read,
is_in_inbox=original_email_in_inbox,
additional_mailbox="MBX50",
)
)
mock_responses.append(make_thread_get_response())
mock_responses.append(
make_email_get_response(
is_read=original_email_read,
is_in_inbox=original_email_in_inbox,
)
)
mock_responses.append(
make_identity_get_response(email="[email protected]")
)
mock_request.side_effect = mock_responses
wafflesbot.run(events=True)
assert_or_debug_calls(mock_request.call_args_list, expected_calls)
with pytest.raises(StopIteration):
mock_request()


@pytest.mark.parametrize("dry_run", [True, False], ids=["dry_run", "live"])
@pytest.mark.parametrize(
"in_folder", [True, False], ids=["in_folder", "not_in_folder"]
Expand Down
5 changes: 4 additions & 1 deletion wafflesbot/jmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,10 @@ def _process_email_threads(
for i, email in enumerate(result.data):
if limit and i >= limit:
break
self.new_email_callback(email)
try:
self.new_email_callback(email)
except Exception:
log.error(f"Error handling email {email}")

def _get_reply_address(self, email: Email) -> str:
if email.reply_to:
Expand Down

0 comments on commit d7e6a17

Please sign in to comment.