Log more parse errors, and log the original header

This commit is contained in:
John Whitlock 2024-07-12 16:51:10 -05:00
Родитель 5146151e42
Коммит d351216619
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 082C735D154FB750
4 изменённых файлов: 33 добавлений и 6 удалений

Просмотреть файл

@ -73,6 +73,7 @@ class RelayHeaderRegistry(PythonHeaderRegistry):
as_unstructured = as_unstructured_cls(name, value)
# Avoid mypy attr-defined error for setting a dynamic attribute
setattr(header_instance, "as_unstructured", as_unstructured)
setattr(header_instance, "as_raw", value)
return header_instance

Просмотреть файл

@ -668,7 +668,7 @@ class SNSNotificationIncomingTest(SNSNotificationTestBase):
'"Norton I.", Emperor of the United States'
" <norton@sf.us.example.com>"
),
"unstructured_value": (
"raw_value": (
"Norton I., Emperor of the United States"
" <norton@sf.us.example.com>"
),
@ -718,7 +718,7 @@ class SNSNotificationIncomingTest(SNSNotificationTestBase):
"parsed_value": (
"<[d7c5838b5ab944f89e3f0c1b85674aef====@example.com]>"
),
"unstructured_value": (
"raw_value": (
"<[d7c5838b5ab944f89e3f0c1b85674aef====@example.com]>"
),
},
@ -747,7 +747,22 @@ class SNSNotificationIncomingTest(SNSNotificationTestBase):
assert self.ra.num_forwarded == 1
assert self.ra.last_used_at
assert (datetime.now(tz=UTC) - self.ra.last_used_at).seconds < 2.0
mock_logger.warning.assert_not_called()
expected_header_errors = {
"incoming": [
(
"Subject",
{
"defect_count": 1,
"parsed_value": "An encoded newline\n",
"raw_value": "An =?UTF-8?Q?encoded_newline=0A?=",
},
)
]
}
mock_logger.warning.assert_called_once_with(
"_handle_received: forwarding issues",
extra={"issues": {"headers": expected_header_errors}},
)
class SNSNotificationRepliesTest(SNSNotificationTestBase):

Просмотреть файл

@ -34,7 +34,7 @@ class EmailHeaderExceptionOnWriteIssue(TypedDict):
class EmailHeaderDefectIssue(TypedDict):
defect_count: int
parsed_value: str
unstructured_value: str
raw_value: str
EmailHeaderIssue = (

Просмотреть файл

@ -1042,7 +1042,18 @@ def _replace_headers(
{
"defect_count": len(value.defects),
"parsed_value": str(value),
"unstructured_value": str(value.as_unstructured),
"raw_value": str(value.as_raw),
},
)
)
elif getattr(getattr(value, "_parse_tree", None), "all_defects", []):
issues["incoming"].append(
(
header,
{
"defect_count": len(value._parse_tree.all_defects),
"parsed_value": str(value),
"raw_value": str(value.as_raw),
},
)
)
@ -1083,7 +1094,7 @@ def _replace_headers(
{
"defect_count": len(parsed_value.defects),
"parsed_value": str(parsed_value),
"unstructured_value": str(parsed_value.as_unstructured),
"raw_value": str(parsed_value.as_raw),
},
)
)