Skip to content

Commit 4170a01

Browse files
authored
bug(parse_received): support for .id & .by tlds (#131)
Signed-off-by: vmeyet <vivien@qevlar.com>
1 parent 31a08c2 commit 4170a01

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

src/mailparser/const.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# envelope-from and -sender seem to optionally have space and/or
3838
# ( before them other clauses must have whitespace before
3939
(
40-
r"(?:[^-]by\s+(?P<by>.+?)(?:\s*[(]?envelope-from|\s*"
40+
r"(?:[^-\.]by\s+(?P<by>.+?)(?:\s*[(]?envelope-from|\s*"
4141
r"[(]?envelope-sender|\s+from|\s+with"
4242
r"(?! cipher)|\s+id|\s+for|\s+via|;))"
4343
),
@@ -46,7 +46,7 @@
4646
r"envelope-sender|\s+from|\s+by|\s+id|\s+for|\s+via|;))"
4747
),
4848
(
49-
r"[^\w](?:id\s+(?P<id>.+?)(?:\s*[(]?envelope-from|\s*"
49+
r"[^\w\.](?:id\s+(?P<id>.+?)(?:\s*[(]?envelope-from|\s*"
5050
r"[(]?envelope-sender|\s+from|\s+by|\s+with"
5151
r"(?! cipher)|\s+for|\s+via|;))"
5252
),

tests/test_mail_parser.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,48 @@ def test_ported_string(self):
549549
s = ported_string(raw_data)
550550
self.assertEqual(s, "test")
551551

552+
def test_parse_domain_with_tld_dot_id(self):
553+
"""Support for .id tld (Indonesia)"""
554+
received = """
555+
from web.myhost.id
556+
by smtp.domain.id (Proxmox) with ESMTPS id SOMEIDHERE
557+
for <email@example.id>; Wed, 19 Feb 2025 15:00:00 +0700 (WIB)
558+
""".strip()
559+
560+
expected = {
561+
"from": "web.myhost.id",
562+
"by": "smtp.domain.id (Proxmox)",
563+
"with": "ESMTPS",
564+
"id": "SOMEIDHERE",
565+
"for": "<email@example.id>",
566+
"date": "Wed, 19 Feb 2025 15:00:00 +0700 (WIB)",
567+
}
568+
569+
values_by_clause = parse_received(received)
570+
571+
self.assertEqual(expected, values_by_clause)
572+
573+
def test_parse_domain_with_tld_dot_by(self):
574+
"""Support for .by tld (Belarus)"""
575+
received = """
576+
from web.myhost.by
577+
by smtp.domain.by (Proxmox) with ESMTPS id SOMEIDHERE
578+
for <email@example.by>; Wed, 19 Feb 2025 15:00:00 +0700 (WIB)
579+
""".strip()
580+
581+
expected = {
582+
"from": "web.myhost.by",
583+
"by": "smtp.domain.by (Proxmox)",
584+
"with": "ESMTPS",
585+
"id": "SOMEIDHERE",
586+
"for": "<email@example.by>",
587+
"date": "Wed, 19 Feb 2025 15:00:00 +0700 (WIB)",
588+
}
589+
590+
values_by_clause = parse_received(received)
591+
592+
self.assertEqual(expected, values_by_clause)
593+
552594
def test_standard_outlook(self):
553595
"""Verify a basic outlook received header works."""
554596
received = """

0 commit comments

Comments
 (0)