Changeset View
Changeset View
Standalone View
Standalone View
pykolab/plugins/recipientpolicy/__init__.py
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | def set_primary_mail(self, *args, **kw): | ||||
primary_domain - the domain to use in the primary mail attribute | primary_domain - the domain to use in the primary mail attribute | ||||
secondary_domains - the secondary domains that are aliases | secondary_domains - the secondary domains that are aliases | ||||
Return the new primary mail address | Return the new primary mail address | ||||
""" | """ | ||||
user_attrs = utils.normalize(kw['entry']) | user_attrs = utils.normalize(kw['entry']) | ||||
if not user_attrs.has_key('domain'): | if 'domain' not in user_attrs: | ||||
user_attrs['domain'] = kw['primary_domain'] | user_attrs['domain'] = kw['primary_domain'] | ||||
elif not user_attrs['domain'] == kw['primary_domain']: | elif not user_attrs['domain'] == kw['primary_domain']: | ||||
user_attrs['domain'] = kw['primary_domain'] | user_attrs['domain'] = kw['primary_domain'] | ||||
if not user_attrs.has_key('preferredlanguage'): | if 'preferredlanguage' not in user_attrs: | ||||
default_locale = conf.get(user_attrs['domain'], 'default_locale') | default_locale = conf.get(user_attrs['domain'], 'default_locale') | ||||
if default_locale == None: | if default_locale == None: | ||||
default_locale = conf.get('kolab', 'default_locale') | default_locale = conf.get('kolab', 'default_locale') | ||||
if default_locale == None: | if default_locale == None: | ||||
default_locale = 'en_US' | default_locale = 'en_US' | ||||
user_attrs['preferredlanguage'] = default_locale | user_attrs['preferredlanguage'] = default_locale | ||||
try: | try: | ||||
mail = kw['primary_mail'] % user_attrs | mail = kw['primary_mail'] % user_attrs | ||||
mail = utils.translate(mail, user_attrs['preferredlanguage']) | mail = utils.translate(mail, user_attrs['preferredlanguage']) | ||||
mail = mail.lower() | mail = mail.lower() | ||||
return mail | return mail | ||||
except KeyError: | except KeyError: | ||||
log.warning(_("Attribute substitution for 'mail' failed in Recipient Policy")) | log.warning(_("Attribute substitution for 'mail' failed in Recipient Policy")) | ||||
if user_attrs.has_key('mail'): | if 'mail' in user_attrs: | ||||
return user_attrs['mail'] | return user_attrs['mail'] | ||||
else: | else: | ||||
return None | return None | ||||
def set_secondary_mail(self, *args, **kw): | def set_secondary_mail(self, *args, **kw): | ||||
""" | """ | ||||
The arguments passed to the 'set_user_attrs_alternative_mail' hook: | The arguments passed to the 'set_user_attrs_alternative_mail' hook: | ||||
primary_mail - the policy | primary_mail - the policy | ||||
user_attrs - the current user attributes | user_attrs - the current user attributes | ||||
primary_domain - the domain to use in the primary mail attribute | primary_domain - the domain to use in the primary mail attribute | ||||
secondary_domains - the secondary domains that are aliases | secondary_domains - the secondary domains that are aliases | ||||
Return a list of secondary mail addresses | Return a list of secondary mail addresses | ||||
""" | """ | ||||
user_attrs = utils.normalize(kw['entry']) | user_attrs = utils.normalize(kw['entry']) | ||||
if not user_attrs.has_key('domain'): | if 'domain' not in user_attrs: | ||||
user_attrs['domain'] = kw['primary_domain'] | user_attrs['domain'] = kw['primary_domain'] | ||||
elif not user_attrs['domain'] == kw['primary_domain']: | elif not user_attrs['domain'] == kw['primary_domain']: | ||||
user_attrs['domain'] = kw['primary_domain'] | user_attrs['domain'] = kw['primary_domain'] | ||||
if not user_attrs.has_key('preferredlanguage'): | if 'preferredlanguage' not in user_attrs: | ||||
default_locale = conf.get(user_attrs['domain'], 'default_locale') | default_locale = conf.get(user_attrs['domain'], 'default_locale') | ||||
if default_locale == None: | if default_locale == None: | ||||
default_locale = conf.get(user_attrs['domain'], 'default_locale') | default_locale = conf.get(user_attrs['domain'], 'default_locale') | ||||
if default_locale == None: | if default_locale == None: | ||||
default_locale = 'en_US' | default_locale = 'en_US' | ||||
user_attrs['preferredlanguage'] = default_locale | user_attrs['preferredlanguage'] = default_locale | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |