Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/mailparser/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import re


REGXIP = re.compile(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")

JUNK_PATTERN = r"[ \(\)\[\]\t\n]+"
Expand All @@ -39,7 +38,7 @@
# envelope-from and -sender seem to optionally have space and/or
# ( before them other clauses must have whitespace before
(
r"(?:[^-]by\s+(?P<by>.+?)(?:\s*[(]?envelope-from|\s*"
r"(?:[^-\.]by\s+(?P<by>.+?)(?:\s*[(]?envelope-from|\s*"
r"[(]?envelope-sender|\s+from|\s+with"
r"(?! cipher)|\s+id|\s+for|\s+via|;))"
),
Expand All @@ -48,7 +47,7 @@
r"envelope-sender|\s+from|\s+by|\s+id|\s+for|\s+via|;))"
),
(
r"[^\w](?:id\s+(?P<id>.+?)(?:\s*[(]?envelope-from|\s*"
r"[^\w\.](?:id\s+(?P<id>.+?)(?:\s*[(]?envelope-from|\s*"
r"[(]?envelope-sender|\s+from|\s+by|\s+with"
r"(?! cipher)|\s+for|\s+via|;))"
),
Expand Down
42 changes: 42 additions & 0 deletions tests/test_mail_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,48 @@ def test_ported_string(self):
s = ported_string(raw_data)
self.assertEqual(s, "test")

def test_parse_domain_with_tld_dot_id(self):
"""Support for .id tld (Indonesia)"""
received = """
from web.myhost.id
by smtp.domain.id (Proxmox) with ESMTPS id SOMEIDHERE
for <email@example.id>; Wed, 19 Feb 2025 15:00:00 +0700 (WIB)
""".strip()

expected = {
"from": "web.myhost.id",
"by": "smtp.domain.id (Proxmox)",
"with": "ESMTPS",
"id": "SOMEIDHERE",
"for": "<email@example.id>",
"date": "Wed, 19 Feb 2025 15:00:00 +0700 (WIB)",
}

values_by_clause = parse_received(received)

self.assertEqual(expected, values_by_clause)

def test_parse_domain_with_tld_dot_by(self):
"""Support for .by tld (Belarus)"""
received = """
from web.myhost.by
by smtp.domain.by (Proxmox) with ESMTPS id SOMEIDHERE
for <email@example.by>; Wed, 19 Feb 2025 15:00:00 +0700 (WIB)
""".strip()

expected = {
"from": "web.myhost.by",
"by": "smtp.domain.by (Proxmox)",
"with": "ESMTPS",
"id": "SOMEIDHERE",
"for": "<email@example.by>",
"date": "Wed, 19 Feb 2025 15:00:00 +0700 (WIB)",
}

values_by_clause = parse_received(received)

self.assertEqual(expected, values_by_clause)

def test_standard_outlook(self):
"""Verify a basic outlook received header works."""
received = """
Expand Down