1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

test: Make mail_diff more strict

This patch makes mail_diff more strict in its parsing, to ensure we
catch any encoding issues that may otherwise be masked by the default
compatibility policy.
This commit is contained in:
Alberto Bertogli
2023-12-23 14:08:36 +00:00
parent 7fe1d04f01
commit 5c4d2f9808

View File

@@ -2,6 +2,7 @@
import difflib import difflib
import email.parser import email.parser
import email.policy
import itertools import itertools
import mailbox import mailbox
import sys import sys
@@ -27,7 +28,7 @@ def flexible_eq(expected, got):
posG += 1 posG += 1
continue continue
if c == '*': if c == '*':
while posG < len(got) and got[posG] != '\n': while posG < len(got) and got[posG] != '\t':
posG += 1 posG += 1
continue continue
continue continue
@@ -89,7 +90,14 @@ def msg_equals(expected, msg):
if __name__ == "__main__": if __name__ == "__main__":
f1, f2 = sys.argv[1:3] f1, f2 = sys.argv[1:3]
expected = email.parser.Parser().parse(open(f1)) # We use a custom strict policy to do more strict content validation.
msg = email.parser.Parser().parse(open(f2)) policy = email.policy.EmailPolicy(
utf8=True,
linesep="\r\n",
refold_source='none',
raise_on_defect=True)
expected = email.parser.Parser(policy=policy).parse(open(f1))
msg = email.parser.Parser(policy=policy).parse(open(f2))
sys.exit(0 if msg_equals(expected, msg) else 1) sys.exit(0 if msg_equals(expected, msg) else 1)