Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117757556
D2996.1775207902.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
D2996.1775207902.diff
View Options
diff --git a/tests/unit/test-012-wallace_footer.py b/tests/unit/test-012-wallace_footer.py
new file mode 100644
--- /dev/null
+++ b/tests/unit/test-012-wallace_footer.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+
+import os
+import pykolab
+import unittest
+
+from wallace import module_footer as Footer
+
+conf = pykolab.getConf()
+
+if not hasattr(conf, 'defaults'):
+ conf.finalize_conf()
+
+
+class TestWallaceFooter(unittest.TestCase):
+
+ def test_001_append_footer_plain(self):
+ # bottom
+ content = Footer.append_footer('test', 'footer')
+ self.assertEqual('test\n\n-- \nfooter', content)
+
+ # top
+ content = Footer.append_footer('test', 'footer', 'top')
+ self.assertEqual('footer\n\ntest', content)
+
+ def test_001_append_footer_html(self):
+ foot = "\n<!-- footer appended by Wallace -->\nfooter\n<!-- footer end -->\n"
+
+ # bottom
+ content = Footer.append_footer('<p>test</p>', 'footer', None, True)
+ self.assertEqual('<html><body><p>test</p>' + foot + '</body></html>', content)
+
+ content = Footer.append_footer('<body><p>test</p></body>', 'footer', None, True)
+ self.assertEqual('<body><p>test</p>' + foot + '</body>', content)
+
+ content = Footer.append_footer('<BODY><p>test</p></BODY>', 'footer', None, True)
+ self.assertEqual('<BODY><p>test</p>' + foot + '</BODY>', content)
+
+ # top
+ content = Footer.append_footer('<p>test</p>', 'footer', 'top', True)
+ self.assertEqual('<html><body>' + foot + '<p>test</p></body></html>', content)
+
+ content = Footer.append_footer('<body color=red"><p>test</p>', 'footer', 'top', True)
+ self.assertEqual('<body color=red">' + foot + '<p>test</p>', content)
+
+ content = Footer.append_footer('<BODY\ncolor=red"><p>test</p>', 'footer', 'top', True)
+ self.assertEqual('<BODY\ncolor=red">' + foot + '<p>test</p>', content)
diff --git a/wallace/module_footer.py b/wallace/module_footer.py
--- 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 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 @@
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 @@
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:
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 3, 9:18 AM (15 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18821889
Default Alt Text
D2996.1775207902.diff (4 KB)
Attached To
Mode
D2996: Add footer_position option, so the added footer content can be also placed on top
Attached
Detach File
Event Timeline