Log up to 2,5kB of message headers

This commit is contained in:
Piotr F. Mieszkowski 2022-12-14 20:26:46 +01:00
parent 3c1544e423
commit 1cdca1d06d
2 changed files with 12 additions and 0 deletions

View File

@ -2,6 +2,7 @@
import logging
import lacre
from lacre.text import DOUBLE_EOL_BYTES
import lacre.config as conf
import sys
from aiosmtpd.controller import Controller
@ -39,6 +40,7 @@ class MailEncryptionProxy:
start = time.process_time()
try:
keys = await self._keyring.freeze_identities()
LOG.debug('Parsing message: %s', self._beginning(envelope))
message = email.message_from_bytes(envelope.original_content)
if message.defects:
@ -65,6 +67,15 @@ class MailEncryptionProxy:
return RESULT_OK
def _beginning(self, e: Envelope) -> bytes:
double_eol_pos = e.original_content.find(DOUBLE_EOL_BYTES)
if double_eol_pos < 0:
limit = len(e.original_content)
else:
limit = double_eol_pos
end = min(limit, 2560)
return e.original_content[0:end]
def _extract_headers(self, message: email.message.Message):
return {
'mime' : message.get_content_type(),

View File

@ -9,6 +9,7 @@ from email.message import Message
# The standard way to encode line-ending in email:
EOL = "\r\n"
EOL_BYTES = b"\r\n"
DOUBLE_EOL_BYTES = EOL_BYTES*2
PGP_INLINE_BEGIN = EOL_BYTES + b"-----BEGIN PGP MESSAGE-----" + EOL_BYTES
PGP_INLINE_END = EOL_BYTES + b"-----END PGP MESSAGE-----" + EOL_BYTES