Improve filtermail checks for encrypted messages

Ensure that first part only contains "Version: 1"
and second part only contains base64 payload
enclosed in "-----BEGIN PGP MESSAGE-----"
and "-----END PGP MESSAGE-----".
This commit is contained in:
link2xt
2024-06-11 16:18:39 +00:00
parent 044ebfb9a2
commit 1ce0a2b0ba
3 changed files with 38 additions and 2 deletions
+3 -1
View File
@@ -68,7 +68,9 @@ def maildata(request):
assert datadir.exists(), datadir
def maildata(name, from_addr, to_addr):
data = datadir.joinpath(name).read_text()
# Using `.read_bytes().decode()` instead of `.read_text()` to preserve newlines.
data = datadir.joinpath(name).read_bytes().decode()
text = data.format(from_addr=from_addr, to_addr=to_addr)
return BytesParser(policy=policy.default).parsebytes(text.encode())