From 0f1b48a5c4a0b096385b1efe9f02da619b85294f Mon Sep 17 00:00:00 2001 From: Thomas Oettli Date: Tue, 9 Jun 2020 10:04:50 +0200 Subject: [PATCH] update headers only if neccessary --- pymodmilter/actions.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pymodmilter/actions.py b/pymodmilter/actions.py index 0c06bf8..6304d11 100644 --- a/pymodmilter/actions.py +++ b/pymodmilter/actions.py @@ -231,6 +231,7 @@ def add_disclaimer(text, html, action, policy, milter, pretend=False, text_content = None html_content = None + update_headers = False try: try: @@ -239,6 +240,9 @@ def add_disclaimer(text, html, action, policy, milter, pretend=False, html_body, html_content = _get_body_content(msg, "html") if text_content is None and html_content is None: raise RuntimeError() + + if not msg.is_multipart(): + update_headers = True except RuntimeError: logger.info( "message does not contain any body part, " @@ -248,6 +252,9 @@ def add_disclaimer(text, html, action, policy, milter, pretend=False, html_body, html_content = _get_body_content(msg, "html") if text_content is None and html_content is None: raise RuntimeError("no message body present after injecting") + + update_headers = True + except Exception as e: logger.warning(e) if policy == "ignore": @@ -270,6 +277,8 @@ def add_disclaimer(text, html, action, policy, milter, pretend=False, raise Exception("no message body present after wrapping, " "give up ...") + update_headers = True + if text_content is not None: logger.info(f"{action} text disclaimer") @@ -325,6 +334,9 @@ def add_disclaimer(text, html, action, policy, milter, pretend=False, milter.replacebody(data[body_pos:]) del data + if not update_headers: + return + fields = { "mime-version": { "field": "MIME-Version",