update headers only if neccessary
This commit is contained in:
@@ -231,6 +231,7 @@ def add_disclaimer(text, html, action, policy, milter, pretend=False,
|
|||||||
|
|
||||||
text_content = None
|
text_content = None
|
||||||
html_content = None
|
html_content = None
|
||||||
|
update_headers = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
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")
|
html_body, html_content = _get_body_content(msg, "html")
|
||||||
if text_content is None and html_content is None:
|
if text_content is None and html_content is None:
|
||||||
raise RuntimeError()
|
raise RuntimeError()
|
||||||
|
|
||||||
|
if not msg.is_multipart():
|
||||||
|
update_headers = True
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
logger.info(
|
logger.info(
|
||||||
"message does not contain any body part, "
|
"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")
|
html_body, html_content = _get_body_content(msg, "html")
|
||||||
if text_content is None and html_content is None:
|
if text_content is None and html_content is None:
|
||||||
raise RuntimeError("no message body present after injecting")
|
raise RuntimeError("no message body present after injecting")
|
||||||
|
|
||||||
|
update_headers = True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(e)
|
logger.warning(e)
|
||||||
if policy == "ignore":
|
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, "
|
raise Exception("no message body present after wrapping, "
|
||||||
"give up ...")
|
"give up ...")
|
||||||
|
|
||||||
|
update_headers = True
|
||||||
|
|
||||||
if text_content is not None:
|
if text_content is not None:
|
||||||
logger.info(f"{action} text disclaimer")
|
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:])
|
milter.replacebody(data[body_pos:])
|
||||||
del data
|
del data
|
||||||
|
|
||||||
|
if not update_headers:
|
||||||
|
return
|
||||||
|
|
||||||
fields = {
|
fields = {
|
||||||
"mime-version": {
|
"mime-version": {
|
||||||
"field": "MIME-Version",
|
"field": "MIME-Version",
|
||||||
|
|||||||
Reference in New Issue
Block a user