Skip to content

Commit

Permalink
🚑️ Allow isodate in mail log parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
pajowu committed Jan 8, 2025
1 parent 961164b commit 2377a5c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion froide/helper/email_log_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PostfixLogfileParser(collections.abc.Iterator):

DEFAULT_RELEVANT_FIELDS = {"message-id", "from", "to", "status", "removed"}
QUEUE_ID_REGEX = r"(?P<queue_id>[0-9A-F]{6,}|[0-9a-zA-Z]{12,})"
TIMESTAMP_RE = r"(?P<timestamp>\w{3}\s+\d+\s+\d+:\d+:\d+)"
TIMESTAMP_RE = r"(?P<timestamp>(\w{3}\s+\d+\s+\d+:\d+:\d+)|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)))"
USER_RE = r"(?P<user>[^ ]+)"
PROCESS_RE = r"(?P<process>[^:]+)"
FIELDS_RE = r"(?P<fields>.*)"
Expand Down
15 changes: 15 additions & 0 deletions froide/helper/tests/test_email_log_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,18 @@ def test_bouncing_email(req_with_msgs: FoiRequest):
assert (
ProblemReport.objects.filter(message=msg).count() == problem_reports_before + 1
)


def test_isodate():
invocations = []

def callback(**kwargs):
invocations.append(kwargs)

email_left_queue.connect(callback)
assert len(invocations) == 0
with tempfile.TemporaryDirectory() as dir:
check_delivery_from_log([p("maillog_007.txt")], Path(dir + "/mail_log.offset"))
assert len(invocations) == 1

assert invocations[0]["message_id"] == MAIL_1_ID
10 changes: 10 additions & 0 deletions froide/helper/tests/testdata/maillog_007.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
2025-01-01T00:01:02.456789+01:00 mail postfix/smtpd[1234567]: 163CB3EE5E7F: client=localhost.localdomain[127.0.0.1], sasl_method=PLAIN, [email protected]
2025-01-08T10:29:21.062584+01:00 mail postfix/cleanup[2345678]: 163CB3EE5E7F: message-id=<foirequest/[email protected]>
2025-01-01T00:01:02.456789+01:00 mail opendkim[2345678]: 163CB3EE5E7F: DKIM-Signature field added (s=mail, d=example.com)
2025-01-01T00:01:02.456789+01:00 mail postfix/qmgr[2345678]: 163CB3EE5E7F: from=<bounce+asdadasd=+132kl12j31n12d1190+a.foo=example.com@example.com>, size=12321, nrcpt=1 (queue active)
2025-01-01T00:01:02.456789+01:00 mail postfix/smtp[2345678]: 163CB3EE5E7F: to=<[email protected]>, relay=example.com[123.456.789.123]:25, delay=0.67, delays=0.1/0.37/0.13/0.07, dsn=2.0.0, status=sent (250 Requested mail action okay, completed: id=aaaaa-bbbbb-ccccc-ddddd
)
2025-01-01T00:01:02.456789+01:00 mail postfix/qmgr[2345678]: 163CB3EE5E7F: removed
2025-01-01T00:01:02.456789+01:00 mail postfix/smtpd[2345678]: 065AB16D682C: client=localhost.localdomain[127.0.0.1], sasl_method=PLAIN, [email protected]
2025-01-01T00:01:02.456789+01:00 mail postfix/cleanup[2345678]: 065AB16D682C: message-id=<[email protected]>
2025-01-01T00:01:02.456789+01:00 mail opendkim[2345678]: 065AB16D682C: DKIM-Signature field added (s=mail, d=example.com)

0 comments on commit 2377a5c

Please sign in to comment.