summaryrefslogtreecommitdiffstats
path: root/wallace/module_invitationpolicy.py
diff options
context:
space:
mode:
Diffstat (limited to 'wallace/module_invitationpolicy.py')
-rw-r--r--wallace/module_invitationpolicy.py72
1 files changed, 38 insertions, 34 deletions
diff --git a/wallace/module_invitationpolicy.py b/wallace/module_invitationpolicy.py
index 46e506d..da6eec9 100644
--- a/wallace/module_invitationpolicy.py
+++ b/wallace/module_invitationpolicy.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from six import string_types
import datetime
import os
@@ -23,7 +24,10 @@ import random
import signal
import tempfile
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import urllib
import hashlib
import traceback
@@ -34,7 +38,7 @@ from email.parser import Parser
from email.utils import formataddr
from email.utils import getaddresses
-import modules
+from . import modules
import pykolab
import kolabformat
@@ -138,7 +142,7 @@ policy_name_map = {
'ACT_SAVE_AND_FORWARD': ACT_SAVE_AND_FORWARD + COND_TYPE_EVENT,
}
-policy_value_map = dict([(v &~ COND_TYPE_ALL, k) for (k, v) in policy_name_map.iteritems()])
+policy_value_map = dict([(v &~ COND_TYPE_ALL, k) for (k, v) in policy_name_map.items()])
object_type_conditons = {
'event': COND_TYPE_EVENT,
@@ -227,12 +231,12 @@ def execute(*args, **kw):
imap = IMAP()
# ignore calls on lock files
- if '/locks/' in filepath or kw.has_key('stage') and kw['stage'] == 'locks':
+ if '/locks/' in filepath or 'stage' in kw and kw['stage'] == 'locks':
return False
log.debug("Invitation policy executing for %r, %r" % (filepath, '/locks/' in filepath), level=8)
- if kw.has_key('stage'):
+ if 'stage' in kw:
log.debug(_("Issuing callback after processing to stage %s") % (kw['stage']), level=8)
log.debug(_("Testing cb_action_%s()") % (kw['stage']), level=8)
@@ -280,7 +284,7 @@ def execute(*args, **kw):
# is an iTip message by checking the length of this list.
try:
itip_events = objects_from_message(message, ['VEVENT','VTODO'], ['REQUEST', 'REPLY', 'CANCEL'])
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("Failed to parse iTip objects from message: %r" % (errmsg)))
itip_events = []
@@ -292,7 +296,7 @@ def execute(*args, **kw):
log.debug(_("iTip objects attached to this message contain the following information: %r") % (itip_events), level=8)
# See if any iTip actually allocates a user.
- if any_itips and len([x['uid'] for x in itip_events if x.has_key('attendees') or x.has_key('organizer')]) > 0:
+ if any_itips and len([x['uid'] for x in itip_events if 'attendees' in x or 'organizer' in x]) > 0:
auth.connect()
# we're looking at the first itip object
@@ -329,7 +333,7 @@ def execute(*args, **kw):
# for replies, the organizer is the recipient
if itip_event['method'] == 'REPLY':
# Outlook can send iTip replies without an organizer property
- if itip_event.has_key('organizer'):
+ if 'organizer' in itip_event:
organizer_mailto = str(itip_event['organizer']).split(':')[-1]
user_attendees = [organizer_mailto] if organizer_mailto in recipient_emails else []
else:
@@ -337,10 +341,10 @@ def execute(*args, **kw):
else:
# Limit the attendees to the one that is actually invited with the current message.
- attendees = [str(a).split(':')[-1] for a in (itip_event['attendees'] if itip_event.has_key('attendees') else [])]
+ attendees = [str(a).split(':')[-1] for a in (itip_event['attendees'] if 'attendees' in itip_event else [])]
user_attendees = [a for a in attendees if a in recipient_emails]
- if itip_event.has_key('organizer'):
+ if 'organizer' in itip_event:
sender_email = itip_event['xml'].get_organizer().email()
# abort if no attendee matches the envelope recipient
@@ -354,7 +358,7 @@ def execute(*args, **kw):
recipient_email = user_attendees[0]
# change gettext language to the preferredlanguage setting of the receiving user
- if receiving_user.has_key('preferredlanguage'):
+ if 'preferredlanguage' in receiving_user:
pykolab.translate.setUserLanguage(receiving_user['preferredlanguage'])
# find user's kolabInvitationPolicy settings and the matching policy values
@@ -369,7 +373,7 @@ def execute(*args, **kw):
}
done = None
- if method_processing_map.has_key(itip_event['method']):
+ if itip_event['method'] in method_processing_map:
processor_func = method_processing_map[itip_event['method']]
# connect as cyrus-admin
@@ -413,7 +417,7 @@ def process_itip_request(itip_event, policy, recipient_email, sender_email, rece
try:
receiving_attendee = itip_event['xml'].get_attendee_by_email(recipient_email)
log.debug(_("Receiving attendee: %r") % (receiving_attendee.to_dict()), level=8)
- except Exception, errmsg:
+ except Exception as errmsg:
log.error("Could not find envelope attendee: %r" % (errmsg))
return MESSAGE_FORWARD
@@ -486,7 +490,7 @@ def process_itip_request(itip_event, policy, recipient_email, sender_email, rece
# if RSVP, send an iTip REPLY
if rsvp or scheduling_required:
# set attendee's CN from LDAP record if yet missing
- if not receiving_attendee.get_name() and receiving_user.has_key('cn'):
+ if not receiving_attendee.get_name() and 'cn' in receiving_user:
receiving_attendee.set_name(receiving_user['cn'])
# send iTip reply
@@ -542,7 +546,7 @@ def process_itip_reply(itip_event, policy, recipient_email, sender_email, receiv
try:
sender_attendee = itip_event['xml'].get_attendee_by_email(sender_email)
log.debug(_("Sender Attendee: %r") % (sender_attendee), level=8)
- except Exception, errmsg:
+ except Exception as errmsg:
log.error("Could not find envelope sender attendee: %r" % (errmsg))
return MESSAGE_FORWARD
@@ -565,7 +569,7 @@ def process_itip_reply(itip_event, policy, recipient_email, sender_email, receiv
existing.set_attendee_participant_status(sender_email, sender_attendee.get_participant_status(), rsvp=False)
existing_attendee = existing.get_attendee(sender_email)
updated_attendees.append(existing_attendee)
- except Exception, errmsg:
+ except Exception as errmsg:
log.error("Could not find corresponding attende in organizer's copy: %r" % (errmsg))
# append delegated-from attendee ?
@@ -598,7 +602,7 @@ def process_itip_reply(itip_event, policy, recipient_email, sender_email, receiv
existing.update_attendees([existing_attendee])
log.debug(_("Update delegator: %r") % (existing_attendee.to_dict()), level=8)
- except Exception, errmsg:
+ except Exception as errmsg:
log.error("Could not find delegated-to attendee: %r" % (errmsg))
# update the organizer's copy of the object
@@ -693,7 +697,7 @@ def user_dn_from_email_address(email_address):
auth.connect()
# return cached value
- if user_dn_from_email_address.cache.has_key(email_address):
+ if email_address in user_dn_from_email_address.cache:
return user_dn_from_email_address.cache[email_address]
local_domains = auth.list_domains()
@@ -709,7 +713,7 @@ def user_dn_from_email_address(email_address):
user_dn = auth.find_user_dn(email_address, True)
- if isinstance(user_dn, basestring):
+ if isinstance(user_dn, string_types):
log.debug(_("User DN: %r") % (user_dn), level=8)
else:
log.debug(_("No user record(s) found for %r") % (email_address), level=8)
@@ -724,7 +728,7 @@ user_dn_from_email_address.cache = {}
def get_matching_invitation_policies(receiving_user, sender_email, type_condition=COND_TYPE_ALL):
# get user's kolabInvitationPolicy settings
- policies = receiving_user['kolabinvitationpolicy'] if receiving_user.has_key('kolabinvitationpolicy') else []
+ policies = receiving_user['kolabinvitationpolicy'] if 'kolabinvitationpolicy' in receiving_user else []
if policies and not isinstance(policies, list):
policies = [policies]
@@ -742,7 +746,7 @@ def get_matching_invitation_policies(receiving_user, sender_email, type_conditio
if domain == '' or domain == '*' or str(sender_email).endswith(domain):
value = value.upper()
- if policy_name_map.has_key(value):
+ if value in policy_name_map:
val = policy_name_map[value]
# append if type condition matches
if val & type_condition:
@@ -767,7 +771,7 @@ def imap_proxy_auth(user_rec):
mail_attribute = mail_attribute.lower()
- if not user_rec.has_key(mail_attribute):
+ if mail_attribute not in user_rec:
log.error(_("User record doesn't have the mailbox attribute %r set" % (mail_attribute)))
return False
@@ -780,7 +784,7 @@ def imap_proxy_auth(user_rec):
imap.disconnect()
imap.connect(login=False)
imap.login_plain(admin_login, admin_password, user_rec[mail_attribute])
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("IMAP proxy authentication failed: %r") % (errmsg))
return False
@@ -910,7 +914,7 @@ def find_existing_object(uid, type, recurrence_id, user_rec, lock=False):
try:
msguid = re.search(r"\WUID (\d+)", data[0][0]).group(1)
- except Exception, errmsg:
+ except Exception:
log.error(_("No UID found in IMAP response: %r") % (data[0][0]))
continue
@@ -936,7 +940,7 @@ def find_existing_object(uid, type, recurrence_id, user_rec, lock=False):
setattr(event, '_lock_key', lock_key)
setattr(event, '_msguid', msguid)
- except Exception, errmsg:
+ except Exception:
log.error(_("Failed to parse %s from message %s/%s: %s") % (type, folder, num, traceback.format_exc()))
event = None
master = None
@@ -961,7 +965,7 @@ def check_availability(itip_event, receiving_user):
conflict = False
# return previously detected conflict
- if itip_event.has_key('_conflicts'):
+ if '_conflicts' in itip_event:
return not itip_event['_conflicts']
for folder in list_user_folders(receiving_user, 'event'):
@@ -977,7 +981,7 @@ def check_availability(itip_event, receiving_user):
try:
event = event_from_message(message_from_string(data[0][1]))
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("Failed to parse event from message %s/%s: %r") % (folder, num, errmsg))
continue
@@ -1087,12 +1091,12 @@ def store_object(object, user_rec, targetfolder=None, master=None):
oc = object.get_classification()
# use *.confidential/private folder for confidential/private invitations
- if oc == kolabformat.ClassConfidential and user_rec.has_key('_confidential_folder'):
+ if oc == kolabformat.ClassConfidential and '_confidential_folder' in user_rec:
targetfolder = user_rec['_confidential_folder']
- elif oc == kolabformat.ClassPrivate and user_rec.has_key('_private_folder'):
+ elif oc == kolabformat.ClassPrivate and '_private_folder' in user_rec:
targetfolder = user_rec['_private_folder']
# use *.default folder if exists
- elif user_rec.has_key('_default_folder'):
+ elif '_default_folder' in user_rec:
targetfolder = user_rec['_default_folder']
# fallback to any existing folder of specified type
elif targetfolders is not None and len(targetfolders) > 0:
@@ -1122,7 +1126,7 @@ def store_object(object, user_rec, targetfolder=None, master=None):
)
return result
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("Failed to save %s to user folder at %r: %r") % (
saveobj.type, targetfolder, errmsg
))
@@ -1160,7 +1164,7 @@ def delete_object(existing):
imap.imap.m.expunge()
return True
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("Failed to delete %s from folder %r: %r") % (
existing.type, targetfolder, errmsg
))
@@ -1205,7 +1209,7 @@ def send_update_notification(object, receiving_user, old=None, reply=True, sende
for attendee in object.get_attendees():
parstat = attendee.get_participant_status(True)
- if partstats.has_key(parstat):
+ if parstat in partstats:
partstats[parstat].append(attendee.get_displayname())
else:
partstats['PENDING'].append(attendee.get_displayname())
@@ -1243,7 +1247,7 @@ def send_update_notification(object, receiving_user, old=None, reply=True, sende
if itip_comment is not None:
roundup += "\n" + itip_comment
- for status,attendees in partstats.iteritems():
+ for status,attendees in partstats.items():
if len(attendees) > 0:
roundup += "\n" + participant_status_label(status) + ":\n\t" + "\n\t".join(attendees) + "\n"
else: