summaryrefslogtreecommitdiffstats
path: root/wallace
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2021-11-03 15:46:27 +0100
committerAleksander Machniak <machniak@kolabsys.com>2021-11-03 15:46:27 +0100
commit2f9201192934bad08e188001cd6e7622d9a1f453 (patch)
tree470c5be02759a4d6ad9b9873bd11b0e21fe9384a /wallace
parentf0a02b4484360617baa434bada6c651b8b0b5d30 (diff)
downloadpykolab-2f9201192934bad08e188001cd6e7622d9a1f453.tar.gz
Add footer_position option, so the added footer content can be also placed on top
Reviewers: #pykolab_developers, vanmeeuwen Reviewed By: #pykolab_developers, vanmeeuwen Subscribers: #pykolab_developers Differential Revision: https://git.kolab.org/D2996
Diffstat (limited to 'wallace')
-rw-r--r--wallace/module_footer.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/wallace/module_footer.py b/wallace/module_footer.py
index 7544652..73916fb 100644
--- a/wallace/module_footer.py
+++ b/wallace/module_footer.py
@@ -18,6 +18,7 @@
#
import os
+import re
import tempfile
import time
@@ -42,6 +43,29 @@ def __init__():
def description():
return """Append a footer to messages."""
+def append_footer(content, footer, position=None, isHtml=False):
+ if (isHtml):
+ append = "\n<!-- footer appended by Wallace -->\n" + footer + "\n<!-- footer end -->\n"
+ if position == 'top':
+ match = re.search('(<body[^>]*>)', content, re.IGNORECASE | re.DOTALL)
+ if match:
+ content = content.replace(match.group(0), match.group(0) + append)
+ else:
+ content = "<html><body>" + append + content + "</body></html>"
+ else:
+ match = re.search('(</body>)', content, re.IGNORECASE | re.DOTALL)
+ if match:
+ content = content.replace(match.group(0), append + match.group(0))
+ else:
+ content = "<html><body>" + content + append + "</body></html>"
+ else:
+ if position == 'top':
+ content = footer + "\n\n" + content
+ else:
+ content += "\n\n-- \n" + footer
+
+ return content
+
def set_part_content(part, content):
# Reset old encoding and use quoted-printable (#5414)
del part['Content-Transfer-Encoding']
@@ -87,6 +111,7 @@ def execute(*args, **kw):
footer = {}
+ footer_position = conf.get('wallace', 'footer_position')
footer_html_file = conf.get('wallace', 'footer_html')
footer_text_file = conf.get('wallace', 'footer_text')
@@ -140,16 +165,12 @@ def execute(*args, **kw):
if content_type == "text/plain":
content = part.get_payload(decode=True)
- content += "\n\n-- \n%s" % (footer['plain'])
+ content = append_footer(content, footer['plain'], footer_position, false)
footer_added = set_part_content(part, content)
elif content_type == "text/html":
content = part.get_payload(decode=True)
- append = "\n<!-- footer appended by Wallace -->\n" + footer['html']
- if "</body>" in content:
- content = content.replace("</body>", append + "</body>")
- else:
- content = "<html><body>" + content + append + "</body></html>"
+ content = append_footer(content, footer['html'], footer_position, true)
footer_added = set_part_content(part, content)
if footer_added: