Log up to 2,5kB of message headers
This commit is contained in:
parent
25ee52b034
commit
d47d91c174
|
@ -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(),
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue