summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pykolab/auth/ldap/__init__.py42
-rw-r--r--tests/unit/test-012-wallace_footer.py47
-rw-r--r--wallace/module_footer.py33
3 files changed, 98 insertions, 24 deletions
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 4ad86fa..046c30c 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -647,13 +647,7 @@ class LDAP(Base):
if len(_filter) <= 6:
return None
- config_base_dn = self.config_get('resource_base_dn')
- ldap_base_dn = self._kolab_domain_root_dn(self.domain)
-
- if ldap_base_dn is not None and not ldap_base_dn == config_base_dn:
- resource_base_dn = ldap_base_dn
- else:
- resource_base_dn = config_base_dn
+ resource_base_dn = self._object_base_dn('resource')
_results = self.ldap.search_s(
resource_base_dn,
@@ -801,13 +795,7 @@ class LDAP(Base):
if len(_filter) <= 6:
return None
- config_base_dn = self.config_get('resource_base_dn')
- ldap_base_dn = self._kolab_domain_root_dn(self.domain)
-
- if ldap_base_dn is not None and not ldap_base_dn == config_base_dn:
- resource_base_dn = ldap_base_dn
- else:
- resource_base_dn = config_base_dn
+ resource_base_dn = self._object_base_dn('resource')
_results = self.ldap.search_s(
resource_base_dn,
@@ -1397,7 +1385,7 @@ class LDAP(Base):
log.debug(
_l(
"About to consider the user quota for %r (used: %r, "
- + "imap: %r, ldap: %r, default: %r"
+ + "imap: %r, ldap: %r, default: %r)"
) % (
entry_dn,
used,
@@ -2470,9 +2458,7 @@ class LDAP(Base):
conf_prefix = 'kolab_' if kolabuser else ''
- user_base_dn = self.config_get(conf_prefix + 'user_base_dn')
- if user_base_dn is None:
- user_base_dn = self.config_get('base_dn')
+ user_base_dn = self._object_base_dn('user', conf_prefix)
auth_attrs = self.config_get_list('auth_attributes')
@@ -2684,6 +2670,26 @@ class LDAP(Base):
return domains
+ def _object_base_dn(self, objectType, prefix=''):
+ """
+ Get configured base DN for specified Kolab object type
+ """
+ object_base_dn = self.config_get(prefix + objectType + '_base_dn')
+ config_base_dn = self.config_get('base_dn')
+ ldap_base_dn = self._kolab_domain_root_dn(self.domain)
+
+ if ldap_base_dn is not None and not ldap_base_dn == config_base_dn:
+ base_dn = ldap_base_dn
+ else:
+ base_dn = config_base_dn
+
+ if object_base_dn is None:
+ object_base_dn = base_dn
+ else:
+ object_base_dn = object_base_dn % ({'base_dn': base_dn})
+
+ return object_base_dn
+
def _synchronize_callback(self, *args, **kw):
"""
Determine the characteristics of the callback being placed, and
diff --git a/tests/unit/test-012-wallace_footer.py b/tests/unit/test-012-wallace_footer.py
new file mode 100644
index 0000000..b044852
--- /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
index 7544652..2833a59 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: