Changeset View
Changeset View
Standalone View
Standalone View
pykolab/auth/ldap/__init__.py
Show First 20 Lines • Show All 668 Lines • ▼ Show 20 Lines | def find_folder_resource(self, folder="*", exclude_entry_id=None): | ||||
_entry_dns = [] | _entry_dns = [] | ||||
for _result in _results: | for _result in _results: | ||||
(_entry_id, _entry_attrs) = _result | (_entry_id, _entry_attrs) = _result | ||||
_entry_dns.append(_entry_id) | _entry_dns.append(_entry_id) | ||||
return _entry_dns | return _entry_dns | ||||
def find_recipient(self, address="*", exclude_entry_id=None): | def find_recipient(self, address="*", exclude_entry_id=None, search_attrs=None): | ||||
""" | """ | ||||
Given an address string or list of addresses, find one or more valid | Given an address string or list of addresses, find one or more valid | ||||
recipients. | recipients. | ||||
Use this function only to detect whether an address is already in | Use this function only to detect whether an address is already in | ||||
use by any entry in the tree. | use by any entry in the tree. | ||||
Specify an additional entry_id to exclude to exclude matches against | Specify an additional entry_id to exclude to exclude matches against | ||||
the current entry. | the current entry. | ||||
In search_attrs you can specify list of search attributes. By default | |||||
mail_attributes are used. | |||||
""" | """ | ||||
self._bind() | self._bind() | ||||
if not exclude_entry_id == None: | if not exclude_entry_id == None: | ||||
__filter_prefix = "(&" | __filter_prefix = "(&" | ||||
__filter_suffix = "(!(%s=%s)))" % ( | __filter_suffix = "(!(%s=%s)))" % ( | ||||
self.config_get('unique_attribute'), | self.config_get('unique_attribute'), | ||||
exclude_entry_id | exclude_entry_id | ||||
) | ) | ||||
else: | else: | ||||
__filter_prefix = "" | __filter_prefix = "" | ||||
__filter_suffix = "" | __filter_suffix = "" | ||||
kolab_filter = self._kolab_filter() | kolab_filter = self._kolab_filter() | ||||
recipient_address_attrs = self.config_get_list("mail_attributes") | |||||
result_attributes = [] | if search_attrs is not None: | ||||
recipient_address_attrs = search_attrs | |||||
for recipient_address_attr in recipient_address_attrs: | else: | ||||
result_attributes.append(recipient_address_attr) | recipient_address_attrs = self.config_get_list("mail_attributes") | ||||
result_attributes = recipient_address_attrs | |||||
result_attributes.append(self.config_get('unique_attribute')) | result_attributes.append(self.config_get('unique_attribute')) | ||||
_filter = "(|" | _filter = "(|" | ||||
for recipient_address_attr in recipient_address_attrs: | for recipient_address_attr in recipient_address_attrs: | ||||
if isinstance(address, basestring): | if isinstance(address, basestring): | ||||
_filter += "(%s=%s)" % (recipient_address_attr, address) | _filter += "(%s=%s)" % (recipient_address_attr, address) | ||||
else: | else: | ||||
▲ Show 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | def recipient_policy(self, entry): | ||||
primary_mail_address.split('@')[0], | primary_mail_address.split('@')[0], | ||||
i, | i, | ||||
primary_mail_address.split('@')[1] | primary_mail_address.split('@')[1] | ||||
) | ) | ||||
primary_mail_address = _primary_mail | primary_mail_address = _primary_mail | ||||
### | ### | ||||
### FIXME | ### FIXME | ||||
Lint: PEP8 E266: too many leading '#' for block comment | |||||
### | ### | ||||
if not primary_mail_address == None: | if not primary_mail_address == None: | ||||
if not entry.has_key(primary_mail_attribute): | if not entry.has_key(primary_mail_attribute): | ||||
self.set_entry_attribute(entry, primary_mail_attribute, primary_mail_address) | self.set_entry_attribute(entry, primary_mail_attribute, primary_mail_address) | ||||
entry_modifications[primary_mail_attribute] = primary_mail_address | entry_modifications[primary_mail_attribute] = primary_mail_address | ||||
else: | else: | ||||
if not primary_mail_address == entry[primary_mail_attribute]: | if not primary_mail_address == entry[primary_mail_attribute]: | ||||
self.set_entry_attribute(entry, primary_mail_attribute, primary_mail_address) | self.set_entry_attribute(entry, primary_mail_attribute, primary_mail_address) | ||||
▲ Show 20 Lines • Show All 357 Lines • ▼ Show 20 Lines | def user_quota(self, entry_id, folder): | ||||
if not new_quota == current_imap_quota: | if not new_quota == current_imap_quota: | ||||
self.imap.set_quota(folder, new_quota) | self.imap.set_quota(folder, new_quota) | ||||
else: | else: | ||||
if not new_quota == None: | if not new_quota == None: | ||||
self.imap.set_quota(folder, new_quota) | self.imap.set_quota(folder, new_quota) | ||||
### | ### | ||||
### API depth level increasing! | ### API depth level increasing! | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### | ### | ||||
def _bind(self, bind_dn=None, bind_pw=None): | def _bind(self, bind_dn=None, bind_pw=None): | ||||
# If we have no LDAP, we have no previous state. | # If we have no LDAP, we have no previous state. | ||||
if self.ldap is None: | if self.ldap is None: | ||||
self.bind = None | self.bind = None | ||||
self.connect() | self.connect() | ||||
▲ Show 20 Lines • Show All 1,281 Lines • ▼ Show 20 Lines | |||||
# if not self.imap.user_mailbox_exists(entry[result_attribute]): | # if not self.imap.user_mailbox_exists(entry[result_attribute]): | ||||
# folder = self.imap.user_mailbox_create( | # folder = self.imap.user_mailbox_create( | ||||
# entry[result_attribute] | # entry[result_attribute] | ||||
# ) | # ) | ||||
# | # | ||||
# server = self.imap.user_mailbox_server(folder) | # server = self.imap.user_mailbox_server(folder) | ||||
### | ### | ||||
### Backend search functions | ### Backend search functions | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### | ### | ||||
def _persistent_search(self, | def _persistent_search(self, | ||||
base_dn, | base_dn, | ||||
scope=ldap.SCOPE_SUBTREE, | scope=ldap.SCOPE_SUBTREE, | ||||
filterstr="(objectClass=*)", | filterstr="(objectClass=*)", | ||||
attrlist=None, | attrlist=None, | ||||
attrsonly=0, | attrsonly=0, | ||||
▲ Show 20 Lines • Show All 409 Lines • Show Last 20 Lines |
too many leading '#' for block comment