summaryrefslogtreecommitdiffstats
path: root/pykolab/plugins/recipientpolicy
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-03-23 13:19:30 +0000
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-03-23 13:19:30 +0000
commitb2c7f60ec0cf67b6510c8126f31e015d316634cb (patch)
tree2ef54fde25d98a5f73e5eba6dabc64a1e417597a /pykolab/plugins/recipientpolicy
parent5e5441ecd228e2fa71d6406ba6a7f1f94422d389 (diff)
downloadpykolab-b2c7f60ec0cf67b6510c8126f31e015d316634cb.tar.gz
The plugins can now make use of the logging facilities,
Have the plugins be passed keywords and reflect that
Diffstat (limited to 'pykolab/plugins/recipientpolicy')
-rw-r--r--pykolab/plugins/recipientpolicy/__init__.py59
1 files changed, 39 insertions, 20 deletions
diff --git a/pykolab/plugins/recipientpolicy/__init__.py b/pykolab/plugins/recipientpolicy/__init__.py
index fbf0179..5d47067 100644
--- a/pykolab/plugins/recipientpolicy/__init__.py
+++ b/pykolab/plugins/recipientpolicy/__init__.py
@@ -17,8 +17,12 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
+import pykolab
+
+conf = pykolab.getConf()
+log = pykolab.getLogger('pykolab.plugins.recipientpolicy')
+
from pykolab import utils
-from pykolab.auth import Auth
from pykolab.translate import _
class KolabRecipientpolicy(object):
@@ -26,8 +30,11 @@ class KolabRecipientpolicy(object):
Example plugin making quota adjustments given arbitrary conditions.
"""
- def __init__(self, conf=None):
- self.conf = conf
+ def __init__(self):
+ pass
+
+ def add_options(self, *args, **kw):
+ pass
#def mail_domain_space_policy_check(self, kw={}, args=()):
#(mail, alternative_mail, domain_name, domain_root_dn) = args
@@ -35,21 +42,24 @@ class KolabRecipientpolicy(object):
## Your actions go here. For example:
#return (mail, alternative_mail)
- def set_primary_mail(self, kw={}, args=()):
+ def set_primary_mail(self, *args, **kw):
"""
The arguments passed to the 'set_user_attrs_mail' hook:
- - current user attributes
- """
+ primary_mail - the policy
+ user_attrs - the current user attributes
+ primary_domain - the domain to use in the primary mail attribute
+ secondary_domains - the secondary domains that are aliases
- (user_attrs, primary_domain, secondary_domains) = args
+ Return the new primary mail address
+ """
- user_attrs = utils.normalize(user_attrs)
+ user_attrs = utils.normalize(kw['user_attrs'])
if not user_attrs.has_key('domain'):
- user_attrs['domain'] = primary_domain
- elif not user_attrs['domain'] == primary_domain:
- user_attrs['domain'] = primary_domain
+ user_attrs['domain'] = kw['primary_domain']
+ elif not user_attrs['domain'] == kw['primary_domain']:
+ user_attrs['domain'] = kw['primary_domain']
try:
mail = kw['primary_mail'] % user_attrs
@@ -58,30 +68,39 @@ class KolabRecipientpolicy(object):
self.conf.log.warning(_("Attribute substitution for 'mail' failed in Recipient Policy"))
return user_attrs['mail'].lower()
- def set_secondary_mail(self, kw={}, args=()):
+ def set_secondary_mail(self, *args, **kw):
"""
The arguments passed to the 'set_user_attrs_alternative_mail' hook:
- - current user attributes
- """
+ primary_mail - the policy
+ user_attrs - the current user attributes
+ primary_domain - the domain to use in the primary mail attribute
+ secondary_domains - the secondary domains that are aliases
- (user_attrs, primary_domain, secondary_domains) = args
+ Return a list of secondary mail addresses
+ """
- user_attrs = utils.normalize(user_attrs)
+ user_attrs = utils.normalize(kw['user_attrs'])
- user_attrs['standard_domain'] = primary_domain
+ if not user_attrs.has_key('domain'):
+ user_attrs['domain'] = kw['primary_domain']
+ elif not user_attrs['domain'] == kw['primary_domain']:
+ user_attrs['domain'] = kw['primary_domain']
- exec("alternative_mail_routines = %s" % kw['secondary_mail'])
+ try:
+ exec("alternative_mail_routines = %s" % kw['secondary_mail'])
+ except Exception, e:
+ log.error(_("Could not parse the alternative mail routines"))
alternative_mail = []
for routine in alternative_mail_routines.keys():
- for _domain in [ primary_domain ] + secondary_domains:
+ for _domain in [ kw['primary_domain'] ] + kw['secondary_domains']:
user_attrs['domain'] = _domain
try:
exec("retval = '%s'.%s" % (routine,alternative_mail_routines[routine] % user_attrs))
except KeyError, e:
- self.conf.log.warning(_("Attribute substitution for 'alternative_mail' failed in Recipient Policy"))
+ log.warning(_("Attribute substitution for 'alternative_mail' failed in Recipient Policy"))
alternative_mail.append(retval)
return alternative_mail