Changeset View
Changeset View
Standalone View
Standalone View
pykolab/imap/__init__.py
Show All 37 Lines | class IMAP(object): | ||||
def __init__(self): | def __init__(self): | ||||
# Pool of named IMAP connections, by hostname | # Pool of named IMAP connections, by hostname | ||||
self._imap = {} | self._imap = {} | ||||
# Place holder for the current IMAP connection | # Place holder for the current IMAP connection | ||||
self.imap = None | self.imap = None | ||||
def cleanup_acls(self, aci_subject): | def cleanup_acls(self, aci_subject): | ||||
lm_suffix = "" | |||||
log.info( | log.info( | ||||
_("Cleaning up ACL entries for %s across all folders") % ( | _("Cleaning up ACL entries for %s across all folders") % ( | ||||
aci_subject | aci_subject | ||||
) | ) | ||||
) | ) | ||||
lm_suffix = "" | |||||
if len(aci_subject.split('@')) > 1: | if len(aci_subject.split('@')) > 1: | ||||
lm_suffix = "@%s" % (aci_subject.split('@')[1]) | lm_suffix = "@%s" % (aci_subject.split('@')[1]) | ||||
shared_folders = self.imap.lm( | shared_folders = self.imap.lm( | ||||
"shared/*%s" % (lm_suffix) | "shared/*%s" % (lm_suffix) | ||||
) | ) | ||||
user_folders = self.imap.lm( | user_folders = self.imap.lm( | ||||
"user/*%s" % (lm_suffix) | "user/*%s" % (lm_suffix) | ||||
) | ) | ||||
log.debug( | |||||
_("Cleaning up ACL entries referring to identifier %s") % ( | |||||
aci_subject | |||||
), | |||||
level=5 | |||||
) | |||||
# For all folders (shared and user), ... | # For all folders (shared and user), ... | ||||
folders = user_folders + shared_folders | folders = user_folders + shared_folders | ||||
log.debug(_("Iterating over %d folders") % (len(folders)), level=5) | log.debug(_("Iterating over %d folders") % (len(folders)), level=5) | ||||
# ... loop through them and ... | # ... loop through them and ... | ||||
for folder in folders: | for folder in folders: | ||||
# ... list the ACL entries -- but only if the folder still exists | try: | ||||
if self.imap.has_folder(folder): | # ... list the ACL entries | ||||
vanmeeuwenUnsubmitted Done Inline Actionsvanmeeuwen: ```
try:
``` | |||||
acls = self.imap.lam(folder) | acls = self.imap.lam(folder) | ||||
# For each ACL entry, see if we think it is a current, valid | # For each ACL entry, see if we think it is a current, valid | ||||
# entry | # entry | ||||
for acl_entry in acls.keys(): | for acl_entry in acls.keys(): | ||||
# If the key 'acl_entry' does not exist in the dictionary | # If the key 'acl_entry' does not exist in the dictionary | ||||
# of valid ACL entries, this ACL entry has got to go. | # of valid ACL entries, this ACL entry has got to go. | ||||
if acl_entry == aci_subject: | if acl_entry == aci_subject: | ||||
# Set the ACL to '' (effectively deleting the ACL | # Set the ACL to '' (effectively deleting the ACL | ||||
# entry) | # entry) | ||||
log.debug( | log.debug( | ||||
_( | _( | ||||
"Removing acl %r for subject %r from folder %r" | "Removing acl %r for subject %r from folder %r" | ||||
) % ( | ) % ( | ||||
acls[acl_entry], | acls[acl_entry], | ||||
acl_entry, | acl_entry, | ||||
folder | folder | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
self.set_acl(folder, acl_entry, '') | self.set_acl(folder, acl_entry, '') | ||||
else: | |||||
log.debug( | except Exception, errmsg: | ||||
_("Folder %r disappeared (ACL cleanup for %r") % ( | log.error( | ||||
_("Failed to read/set ACL on folder %s: %r") % ( | |||||
folder, | folder, | ||||
aci_subject | errmsg | ||||
), | ) | ||||
level=8 | |||||
) | ) | ||||
def connect(self, uri=None, server=None, domain=None, login=True): | def connect(self, uri=None, server=None, domain=None, login=True): | ||||
""" | """ | ||||
Connect to the appropriate IMAP backend. | Connect to the appropriate IMAP backend. | ||||
Supply a domain (name space) configured in the configuration file | Supply a domain (name space) configured in the configuration file | ||||
as a section, with a setting 'imap_uri' to connect to a domain | as a section, with a setting 'imap_uri' to connect to a domain | ||||
▲ Show 20 Lines • Show All 1,135 Lines • Show Last 20 Lines |