View | Details | Raw Unified | Return to bug 42804
Collapse All | Expand All

(-)a/mail/univention-mail-postfix/share/listfilter.py (-5 / +7 lines)
 Lines 37-42    Link Here 
37
import re
37
import re
38
import traceback
38
import traceback
39
import syslog
39
import syslog
40
41
from ldap.filter import filter_format
40
from univention.config_registry import ConfigRegistry
42
from univention.config_registry import ConfigRegistry
41
43
42
usage = "help"
44
usage = "help"
 Lines 79-85   def listfilter(attrib): Link Here 
79
			# try the ldap stuff, if that fails send email anyway
81
			# try the ldap stuff, if that fails send email anyway
80
			# get recipient restriction
82
			# get recipient restriction
81
			ldap_attr = ["univentionAllowedEmailGroups", "univentionAllowedEmailUsers"]
83
			ldap_attr = ["univentionAllowedEmailGroups", "univentionAllowedEmailUsers"]
82
			ldap_filter = '(&(mailPrimaryAddress=%s)(|(objectclass=univentionMailList)(objectclass=posixGroup)))' % recipient
84
			ldap_filter = filter_format('(&(mailPrimaryAddress=%s)(|(objectclass=univentionMailList)(objectclass=posixGroup)))', [recipient])
83
			result = ldap.search(base=options.ldap_base, filter=ldap_filter, attr=ldap_attr)
85
			result = ldap.search(base=options.ldap_base, filter=ldap_filter, attr=ldap_attr)
84
86
85
			if result:
87
			if result:
 Lines 99-111   def listfilter(attrib): Link Here 
99
101
100
					# get dn and groups of sender
102
					# get dn and groups of sender
101
					if check_sasl_username:
103
					if check_sasl_username:
102
						ldap_filter = '(&(uid=%s)(objectclass=posixAccount))' % sender
104
						ldap_filter = filter_format('(&(uid=%s)(objectclass=posixAccount))', [sender])
103
					else:
105
					else:
104
						ldap_filter = '(&(|(mailPrimaryAddress=%s)(mailAlternativeAddress=%s)(mail=%s))(objectclass=posixAccount))' % (sender, sender, sender)
106
						ldap_filter = filter_format('(&(|(mailPrimaryAddress=%s)(mailAlternativeAddress=%s)(mail=%s))(objectclass=posixAccount))', (sender, sender, sender))
105
					user_result = ldap.search(base=options.ldap_base, filter=ldap_filter, attr=["dn"])
107
					user_result = ldap.search(base=options.ldap_base, filter=ldap_filter, attr=["dn"])
106
					if user_result:
108
					if user_result:
107
						user_dn = user_result[0][0]
109
						user_dn = user_result[0][0]
108
						ldap_filter = '(uniqueMember=%s)' % user_dn
110
						ldap_filter = filter_format('(uniqueMember=%s)', [user_dn])
109
						group_result = ldap.search(base=options.ldap_base, filter=ldap_filter, attr=["dn"])
111
						group_result = ldap.search(base=options.ldap_base, filter=ldap_filter, attr=["dn"])
110
						if group_result:
112
						if group_result:
111
							for i in group_result:
113
							for i in group_result:
 Lines 136-142   def listfilter(attrib): Link Here 
136
					return "DUNNO no restrictions"
138
					return "DUNNO no restrictions"
137
			else:
139
			else:
138
				return "DUNNO no group found for %s" % recipient
140
				return "DUNNO no group found for %s" % recipient
139
		except Exception:
141
		except Exception:  # FIXME: never catch everything
140
			return "WARN Error with attrib={}, check_sasl_username={}, traceback={}".format(
142
			return "WARN Error with attrib={}, check_sasl_username={}, traceback={}".format(
141
				attrib, check_sasl_username, traceback.format_exc().replace("\n", " "))
143
				attrib, check_sasl_username, traceback.format_exc().replace("\n", " "))
142
144

Return to bug 42804