From 7806d8c32af119559819d9f83307aa9ab289db7e Mon Sep 17 00:00:00 2001 From: "Piotr F. Mieszkowski" Date: Fri, 1 Mar 2024 20:28:51 +0100 Subject: [PATCH] Log message headers on a hard error When we know we need to bounce a message and [daemon]log_headers is enabled, we record up to 2.5kB of message headers at ERROR level. This could help diagnosing issues later. Also: no longer record MIME Type, Charset and Content-Transfer-Encoding, as the issues related to these properties no longer occur. --- lacre/daemon.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lacre/daemon.py b/lacre/daemon.py index 4c93edd..09af75f 100644 --- a/lacre/daemon.py +++ b/lacre/daemon.py @@ -59,8 +59,10 @@ class MailEncryptionProxy: except: LOG.exception('Unexpected exception caught, bouncing message') + if conf.should_log_headers(): - LOG.info('Message headers: %s', self._extract_headers(message)) + LOG.error('Erroneous message headers: %s', self._beginning(envelope)) + return xport.RESULT_ERRORR return xport.RESULT_OK @@ -78,13 +80,6 @@ class MailEncryptionProxy: end = min(limit, 2560) return e.original_content[0:end] - def _extract_headers(self, message: email.message.Message): - return { - 'mime' : message.get_content_type(), - 'charsets' : message.get_charsets(), - 'cte' : message['Content-Transfer-Encoding'] - } - def _seconds_between(self, start_ms, end_ms) -> float: return (end_ms - start_ms) * 1000