mail-parser 4.10.0__tar.gz → 4.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mail_parser-4.10.0 → mail_parser-4.11.0}/PKG-INFO +11 -1
- {mail_parser-4.10.0 → mail_parser-4.11.0}/README.md +10 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/src/mailparser/core.py +11 -1
- {mail_parser-4.10.0 → mail_parser-4.11.0}/src/mailparser/version.py +1 -1
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_security_recovery.py +1 -1
- mail_parser-4.11.0/tests/test_subject_unfolding.py +108 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.agents/rfc-review/report-template.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.agents/rfc-review/rfc-scope.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.agents/rfc-review/workflow.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.agents/skills/mail-rfc-assessment/SKILL.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.agents/skills/mail-rfc-assessment/agents/openai.yaml +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.agents/skills/mail-rfc-diff/SKILL.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.agents/skills/mail-rfc-diff/agents/openai.yaml +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.claude/agents/security-reviewer.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.github/FUNDING.yml +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.github/copilot-instructions.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.github/instructions/containerization-docker-best-practices.instructions.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.github/instructions/github-actions-ci-cd-best-practices.instructions.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.github/instructions/markdown.instructions.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.github/instructions/python.instructions.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.github/workflows/main.yml +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.gitignore +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.markdownlint.json +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/.pre-commit-config.yaml +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/AGENTS.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/CLAUDE.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/Dockerfile +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/GLOSSARY.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/LICENSE.txt +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/Makefile +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/NOTICE.txt +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/docker-compose.yml +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/docs/adr/0001-bounded-forensic-recovery.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/docs/images/Bitcoin SpamScope.jpg +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/docs/rfc-review-skills.md +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/pyproject.toml +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/src/mailparser/__init__.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/src/mailparser/__main__.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/src/mailparser/addresses.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/src/mailparser/const.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/src/mailparser/dates.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/src/mailparser/exceptions.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/src/mailparser/received.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/src/mailparser/serialization.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/src/mailparser/utils.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/fixtures/corpus_expected.json +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_malformed_1 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_malformed_2 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_malformed_3 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_outlook_1 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_1 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_10 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_11 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_12 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_13 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_14 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_15 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_16 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_17 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_18 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_19 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_2 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_3 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_4 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_5 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_6 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_7 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_8 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/mails/mail_test_9 +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_address_recovery.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_corpus_regression.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_date_recovery.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_encoded_word_context.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_improved_received_patterns.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_inline_body.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_input_octet_preservation.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_international_addresses.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_mail_parser.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_main.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_mime_unicode_metadata.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_received_corpus.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_received_envelope.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_received_lexical.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/test_utils.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/tests/work_budget.py +0 -0
- {mail_parser-4.10.0 → mail_parser-4.11.0}/uv.lock +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mail-parser
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.11.0
|
|
4
4
|
Summary: A tool that parses emails by enhancing the Python standard library, extracting all details into a comprehensive object.
|
|
5
5
|
Project-URL: Homepage, https://spamscope.ai/en/
|
|
6
6
|
Project-URL: Source, https://github.com/SpamScope/mail-parser
|
|
@@ -218,6 +218,16 @@ This versatile architecture makes mail-parser exceptionally powerful for diverse
|
|
|
218
218
|
security analysis and forensics to email migration, compliance auditing, and automated processing
|
|
219
219
|
pipelines.
|
|
220
220
|
|
|
221
|
+
`mail.subject` removes folding CRLF followed by a space or tab, as specified
|
|
222
|
+
by [RFC 5322 §2.2.3](https://www.rfc-editor.org/rfc/rfc5322.html#section-2.2.3),
|
|
223
|
+
before decoding encoded words. LF-only folds are also accepted for local
|
|
224
|
+
message copies; this is a tolerance extension to the CRLF unfolding rule.
|
|
225
|
+
Surrounding spaces and tabs are preserved; bare CR is not unfolded.
|
|
226
|
+
The same value appears in `headers` and parsed mail/JSON output; other headers
|
|
227
|
+
retain their existing behavior. `mail.subject_raw` (a JSON list) and
|
|
228
|
+
`mail.message` preserve the original folding. If encoded-word decoding fails,
|
|
229
|
+
the complete literal Subject is retained with `header_decoding_defects`.
|
|
230
|
+
|
|
221
231
|
**Standard RFC Headers** (directly accessible as properties):
|
|
222
232
|
|
|
223
233
|
- `bcc` - Blind carbon copy recipients
|
|
@@ -186,6 +186,16 @@ This versatile architecture makes mail-parser exceptionally powerful for diverse
|
|
|
186
186
|
security analysis and forensics to email migration, compliance auditing, and automated processing
|
|
187
187
|
pipelines.
|
|
188
188
|
|
|
189
|
+
`mail.subject` removes folding CRLF followed by a space or tab, as specified
|
|
190
|
+
by [RFC 5322 §2.2.3](https://www.rfc-editor.org/rfc/rfc5322.html#section-2.2.3),
|
|
191
|
+
before decoding encoded words. LF-only folds are also accepted for local
|
|
192
|
+
message copies; this is a tolerance extension to the CRLF unfolding rule.
|
|
193
|
+
Surrounding spaces and tabs are preserved; bare CR is not unfolded.
|
|
194
|
+
The same value appears in `headers` and parsed mail/JSON output; other headers
|
|
195
|
+
retain their existing behavior. `mail.subject_raw` (a JSON list) and
|
|
196
|
+
`mail.message` preserve the original folding. If encoded-word decoding fails,
|
|
197
|
+
the complete literal Subject is retained with `header_decoding_defects`.
|
|
198
|
+
|
|
189
199
|
**Standard RFC Headers** (directly accessible as properties):
|
|
190
200
|
|
|
191
201
|
- `bcc` - Blind carbon copy recipients
|
|
@@ -22,6 +22,7 @@ import importlib.util
|
|
|
22
22
|
import ipaddress
|
|
23
23
|
import json
|
|
24
24
|
import logging
|
|
25
|
+
import re
|
|
25
26
|
from bisect import bisect_right
|
|
26
27
|
from email.feedparser import BytesFeedParser
|
|
27
28
|
|
|
@@ -521,7 +522,16 @@ class MailParser:
|
|
|
521
522
|
if header in ADDRESSES_HEADERS:
|
|
522
523
|
continue
|
|
523
524
|
diagnostics = []
|
|
524
|
-
|
|
525
|
+
source = value
|
|
526
|
+
if header == "subject":
|
|
527
|
+
# RFC 5322 2.2.3, plus LF-only local message copies.
|
|
528
|
+
# Before decoding: encoded newlines are not wire folds.
|
|
529
|
+
source = re.sub(r"\r?\n(?=[ \t])", "", value)
|
|
530
|
+
decoded = decode_header_part(source, defects=diagnostics)
|
|
531
|
+
if diagnostics and source != value:
|
|
532
|
+
# Failed decoding retains the complete original evidence.
|
|
533
|
+
diagnostics.clear()
|
|
534
|
+
decoded = decode_header_part(value, defects=diagnostics)
|
|
525
535
|
if part_index == 0:
|
|
526
536
|
self._decoded_headers.setdefault(header, []).append(decoded)
|
|
527
537
|
for detail in diagnostics:
|
|
@@ -216,7 +216,7 @@ def test_nul_charset_in_mime_recovers_payload(metadata, factory, tmp_path):
|
|
|
216
216
|
"value, expected",
|
|
217
217
|
[
|
|
218
218
|
("=?iso-8859-1?q?caf=E9?=\r\n \t=?utf-8?q?_ok?=", "café ok"),
|
|
219
|
-
("one\r\n \r\n two", "one
|
|
219
|
+
("one\r\n \r\n two", "one two"),
|
|
220
220
|
],
|
|
221
221
|
ids=["valid-encoded-fold", "obsolete-consecutive-folds"],
|
|
222
222
|
)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Subject unfolding preserves raw evidence and other header semantics."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
import mailparser
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.mark.parametrize("route", ["string", "bytes", "file"])
|
|
13
|
+
@pytest.mark.parametrize(
|
|
14
|
+
"value, expected",
|
|
15
|
+
[
|
|
16
|
+
("a\r\n b", "a b"),
|
|
17
|
+
("a\r\n\tb", "a\tb"),
|
|
18
|
+
("a \r\n \t b", "a \t b"),
|
|
19
|
+
("a\r\n \r\n b", "a b"),
|
|
20
|
+
(
|
|
21
|
+
"Re: =?UTF-8?Q?R=C3=A9union?= demain\r\n matin",
|
|
22
|
+
"Re: Réunion demain matin",
|
|
23
|
+
),
|
|
24
|
+
("=?utf-8?q?one?=\r\n =?utf-8?q?two?=", "onetwo"),
|
|
25
|
+
("a\n b", "a b"),
|
|
26
|
+
("a\n\tb", "a\tb"),
|
|
27
|
+
("a \n \t b", "a \t b"),
|
|
28
|
+
("a\n \r\n b", "a b"),
|
|
29
|
+
("a\r b", "a\r b"),
|
|
30
|
+
("=?utf-8?q?a=0D=0A_b?=", "a\r\n b"),
|
|
31
|
+
("=?utf-8?q?a=0A_b?=", "a\n b"),
|
|
32
|
+
],
|
|
33
|
+
)
|
|
34
|
+
def test_subject_unfolding(route, value, expected, tmp_path):
|
|
35
|
+
"""Unfold wire CRLF/LF before decoding, preserving other evidence."""
|
|
36
|
+
raw = f"Subject: {value}\r\nComments: a\r\n b\r\nTo: good@example.com\r\n\r\nbody"
|
|
37
|
+
if route == "string":
|
|
38
|
+
parsed = mailparser.parse_from_string(raw)
|
|
39
|
+
elif route == "bytes":
|
|
40
|
+
parsed = mailparser.parse_from_bytes(raw.encode())
|
|
41
|
+
else:
|
|
42
|
+
path = tmp_path / "subject.eml"
|
|
43
|
+
path.write_bytes(raw.encode())
|
|
44
|
+
parsed = mailparser.parse_from_file(path)
|
|
45
|
+
assert parsed.subject == expected
|
|
46
|
+
assert parsed.headers["Subject"] == expected
|
|
47
|
+
assert isinstance(parsed.subject_json, str)
|
|
48
|
+
assert json.loads(parsed.subject_json) == expected
|
|
49
|
+
assert json.loads(parsed.mail_json)["subject"] == expected
|
|
50
|
+
assert parsed.mail_partial["subject"] == expected
|
|
51
|
+
assert isinstance(parsed.subject_raw, str)
|
|
52
|
+
assert json.loads(parsed.subject_raw) == [value]
|
|
53
|
+
assert parsed.message is not None
|
|
54
|
+
assert parsed.message.get_all("Subject") == [value]
|
|
55
|
+
assert parsed.comments == "a\r\n b"
|
|
56
|
+
assert parsed.to == [("", "good@example.com")]
|
|
57
|
+
assert parsed.body == "body"
|
|
58
|
+
assert not parsed.has_defects
|
|
59
|
+
assert parsed.header_decoding_defects == []
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@pytest.mark.parametrize("newline", ["\r\n", "\n"])
|
|
63
|
+
def test_repeated_subjects_keep_occurrences_and_decode_failure(newline):
|
|
64
|
+
"""Literal decode failures retain the whole evidence and diagnostics."""
|
|
65
|
+
bad = f"=?no-such-codec?q?test?={newline} evidence"
|
|
66
|
+
parsed = mailparser.parse_from_string(f"sUbJeCt: a\r\n b\r\nSubject: {bad}\r\n\r\n")
|
|
67
|
+
assert parsed.subject == ["a b", bad]
|
|
68
|
+
assert isinstance(parsed.subject_raw, str)
|
|
69
|
+
assert json.loads(parsed.subject_raw) == ["a\r\n b", bad]
|
|
70
|
+
assert parsed.has_defects
|
|
71
|
+
assert repr(bad) in parsed.defects[0]["header-decoding"][0]
|
|
72
|
+
assert parsed.header_decoding_defects == [
|
|
73
|
+
{
|
|
74
|
+
"reason": "invalid-encoded-word",
|
|
75
|
+
"raw": bad,
|
|
76
|
+
"header": "subject",
|
|
77
|
+
"occurrence": 1,
|
|
78
|
+
"part": 0,
|
|
79
|
+
"recovered": True,
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@pytest.mark.parametrize("newline", ["\r\n", "\n"])
|
|
85
|
+
def test_subject_unfolding_from_cli_stdin(newline):
|
|
86
|
+
"""The issue's mixed encoded/literal Subject unfolds through stdin."""
|
|
87
|
+
raw = newline.join(
|
|
88
|
+
[
|
|
89
|
+
"From: a@b.c",
|
|
90
|
+
"To: d@e.f",
|
|
91
|
+
"Subject: Re: =?UTF-8?Q?R=C3=A9union?= demain",
|
|
92
|
+
" matin",
|
|
93
|
+
"Date: Thu, 05 Mar 2026 10:00:00 -0500",
|
|
94
|
+
"",
|
|
95
|
+
"body",
|
|
96
|
+
]
|
|
97
|
+
)
|
|
98
|
+
result = subprocess.run(
|
|
99
|
+
[sys.executable, "-m", "mailparser", "-k", "-j"],
|
|
100
|
+
input=raw.encode(),
|
|
101
|
+
capture_output=True,
|
|
102
|
+
check=True,
|
|
103
|
+
timeout=10,
|
|
104
|
+
)
|
|
105
|
+
parsed = json.loads(result.stdout)
|
|
106
|
+
assert parsed["subject"] == "Re: Réunion demain matin"
|
|
107
|
+
assert parsed["to"] == [["", "d@e.f"]]
|
|
108
|
+
assert parsed["body"] == "body"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mail_parser-4.10.0 → mail_parser-4.11.0}/.agents/skills/mail-rfc-assessment/agents/openai.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|