Changeset View
Changeset View
Standalone View
Standalone View
wallace/module_invitationpolicy.py
Show First 20 Lines • Show All 768 Lines • ▼ Show 20 Lines | try: | ||||
imap.login_plain(admin_login, admin_password, user_rec[mail_attribute]) | imap.login_plain(admin_login, admin_password, user_rec[mail_attribute]) | ||||
except Exception, errmsg: | except Exception, errmsg: | ||||
log.error(_("IMAP proxy authentication failed: %r") % (errmsg)) | log.error(_("IMAP proxy authentication failed: %r") % (errmsg)) | ||||
return False | return False | ||||
return True | return True | ||||
def list_user_folders(user_rec, type): | def list_user_folders(user_rec, _type): | ||||
""" | """ | ||||
Get a list of the given user's private calendar/tasks folders | Get a list of the given user's private calendar/tasks folders | ||||
""" | """ | ||||
global imap | global imap | ||||
# return cached list | # return cached list | ||||
if user_rec.has_key('_imap_folders'): | if '_imap_folders' in user_rec: | ||||
return user_rec['_imap_folders'] | return user_rec['_imap_folders'] | ||||
result = [] | result = [] | ||||
if not imap_proxy_auth(user_rec): | if not imap_proxy_auth(user_rec): | ||||
return result | return result | ||||
folders = imap.list_folders('*') | folders = imap.get_metadata('*') | ||||
log.debug(_("List %r folders for user %r: %r") % (type, user_rec['mail'], folders), level=8) | |||||
log.debug( | |||||
_("List %r folders for user %r: %r") % ( | |||||
_type, | |||||
user_rec['mail'], | |||||
folders | |||||
), | |||||
level=8 | |||||
) | |||||
machniak: We need only two annotations. Wouldn't be possible to extend get_metadata() to fetch only these? | |||||
Not Done Inline ActionsYes it could, but that's an efficiency parameter that is otherwise unrelated to the particular ticket this attempts to resolve. vanmeeuwen: Yes it could, but that's an efficiency parameter that is otherwise unrelated to the particular… | |||||
(ns_personal, ns_other, ns_shared) = imap.namespaces() | (ns_personal, ns_other, ns_shared) = imap.namespaces() | ||||
for folder in folders: | _folders = {} | ||||
# exclude shared and other user's namespace | |||||
if ns_other is not None and folder.startswith(ns_other) and '_delegated_mailboxes' in user_rec: | # Filter the folders by type relevance | ||||
# allow shared folders from delegators | for folder, metadata in folders.items(): | ||||
if len([_mailbox for _mailbox in user_rec['_delegated_mailboxes'] if folder.startswith(ns_other + _mailbox + '/')]) == 0: | key = '/shared' + FOLDER_TYPE_ANNOTATION | ||||
if key in metadata: | |||||
if metadata[key].startswith(_type): | |||||
_folders[folder] = metadata | |||||
key = '/private' + FOLDER_TYPE_ANNOTATION | |||||
if key in metadata: | |||||
if metadata[key].startswith(_type): | |||||
_folders[folder] = metadata | |||||
Not Done Inline ActionsI think we could just store the folder type (with subtype) here, giving the private annotation a prio over shared. Making all checks below much more simpler. machniak: I think we could just store the folder type (with subtype) here, giving the private annotation… | |||||
Not Done Inline ActionsChanging the definition of what is stored, and how it is stored will be a cause of great confusion later down the line. Note that we don't mutate data here, and we don't mutate the data structure either -- we're just filtering out irrelevant entries. vanmeeuwen: Changing the definition of what is stored, and how it is stored will be a cause of great… | |||||
for folder, metadata in _folders.items(): | |||||
folder_delegated = False | |||||
# Exclude shared and other user's namespace | |||||
# | |||||
# First, test if this is another users folder | |||||
if ns_other is not None and folder.startswith(ns_other): | |||||
# If we have no delegated mailboxes, we can skip this entirely | |||||
if '_delegated_mailboxes' not in user_rec: | |||||
continue | |||||
for _m in user_rec['_delegated_mailboxes']: | |||||
if folder.startswith(ns_other + _m + '/'): | |||||
folder_delegated = True | |||||
if not folder_delegated: | |||||
continue | continue | ||||
# TODO: list shared folders the user has write privileges ? | # TODO: list shared folders the user has write privileges ? | ||||
if ns_shared is not None and len([_ns for _ns in ns_shared if folder.startswith(_ns)]) > 0: | if ns_shared is not None: | ||||
if len([_ns for _ns in ns_shared if folder.startswith(_ns)]) > 0: | |||||
continue | continue | ||||
metadata = imap.get_metadata(folder) | key = '/shared' + FOLDER_TYPE_ANNOTATION | ||||
log.debug(_("IMAP metadata for %r: %r") % (folder, metadata), level=9) | if key in metadata: | ||||
if metadata.has_key(folder) and ( \ | if metadata[key].startswith(_type): | ||||
metadata[folder].has_key('/shared' + FOLDER_TYPE_ANNOTATION) and metadata[folder]['/shared' + FOLDER_TYPE_ANNOTATION].startswith(type) \ | result.append(folder) | ||||
or metadata[folder].has_key('/private' + FOLDER_TYPE_ANNOTATION) and metadata[folder]['/private' + FOLDER_TYPE_ANNOTATION].startswith(type)): | |||||
key = '/private' + FOLDER_TYPE_ANNOTATION | |||||
if key in metadata: | |||||
if metadata[key].startswith(_type): | |||||
result.append(folder) | result.append(folder) | ||||
if metadata[folder].has_key('/private' + FOLDER_TYPE_ANNOTATION): | |||||
# store default folder in user record | # store default folder in user record | ||||
if metadata[folder]['/private' + FOLDER_TYPE_ANNOTATION].endswith('.default'): | if metadata[key].endswith('.default'): | ||||
user_rec['_default_folder'] = folder | user_rec['_default_folder'] = folder | ||||
continue | |||||
# store private and confidential folders in user record | # store private and confidential folders in user record | ||||
if metadata[folder]['/private' + FOLDER_TYPE_ANNOTATION].endswith('.confidential') and not user_rec.has_key('_confidential_folder'): | if metadata[key].endswith('.confidential'): | ||||
if '_confidential_folder' not in user_rec: | |||||
user_rec['_confidential_folder'] = folder | user_rec['_confidential_folder'] = folder | ||||
if metadata[folder]['/private' + FOLDER_TYPE_ANNOTATION].endswith('.private') and not user_rec.has_key('_private_folder'): | |||||
continue | |||||
if metadata[key].endswith('.private'): | |||||
if '_private_folder' not in user_rec: | |||||
user_rec['_private_folder'] = folder | user_rec['_private_folder'] = folder | ||||
continue | |||||
# cache with user record | # cache with user record | ||||
user_rec['_imap_folders'] = result | user_rec['_imap_folders'] = result | ||||
return result | return result | ||||
def find_existing_object(uid, type, recurrence_id, user_rec, lock=False): | def find_existing_object(uid, type, recurrence_id, user_rec, lock=False): | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 604 Lines • Show Last 20 Lines |
We need only two annotations. Wouldn't be possible to extend get_metadata() to fetch only these?