mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-18 14:47:03 +00:00
This patch adds checks that verify: - The envelope from must match the authenticated user. This prevents impersonation at the envelope level (while still allowing bounces, of course). - If the destination is remote, then the user must have completed authentication. This prevents unauthorized relaying. The patch ends up adjusting quite a few tests, as they were not written considering these restrictions so they have to be changed accordingly.
40 lines
863 B
Python
Executable File
40 lines
863 B
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import difflib
|
|
import email.parser
|
|
import mailbox
|
|
import sys
|
|
|
|
f1, f2 = sys.argv[1:3]
|
|
|
|
expected = email.parser.Parser().parse(open(f1))
|
|
|
|
mbox = mailbox.mbox(f2, create=False)
|
|
msg = mbox[0]
|
|
|
|
diff = False
|
|
|
|
for h, val in expected.items():
|
|
if h not in msg:
|
|
print("Header missing: %r" % h)
|
|
diff = True
|
|
continue
|
|
if msg[h] != val:
|
|
print("Header %r differs: %r != %r" % (h, val, msg[h]))
|
|
diff = True
|
|
|
|
if expected.get_payload() != msg.get_payload():
|
|
diff = True
|
|
|
|
if expected.is_multipart() != msg.is_multipart():
|
|
print("Multipart differs, expected %s, got %s" % (
|
|
expected.is_multipart(), msg.is_multipart()))
|
|
elif not msg.is_multipart():
|
|
exp = expected.get_payload().splitlines()
|
|
got = msg.get_payload().splitlines()
|
|
print("Payload differs:")
|
|
for l in difflib.ndiff(exp, got):
|
|
print(l)
|
|
|
|
sys.exit(0 if not diff else 1)
|