Changeset View
Changeset View
Standalone View
Standalone View
wallace/module_invitationpolicy.py
Show All 13 Lines | |||||
# GNU General Public License for more details. | # GNU General Public License for more details. | ||||
# You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | ||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
# | # | ||||
import datetime | import datetime | ||||
import os | import os | ||||
import signal | |||||
import tempfile | import tempfile | ||||
import time | import time | ||||
from urlparse import urlparse | from urlparse import urlparse | ||||
import urllib | import urllib | ||||
import hashlib | import hashlib | ||||
import traceback | import traceback | ||||
import re | import re | ||||
Show All 17 Lines | |||||
from pykolab.xml import event_from_message | from pykolab.xml import event_from_message | ||||
from pykolab.xml import participant_status_label | from pykolab.xml import participant_status_label | ||||
from pykolab.itip import objects_from_message | from pykolab.itip import objects_from_message | ||||
from pykolab.itip import check_event_conflict | from pykolab.itip import check_event_conflict | ||||
from pykolab.itip import send_reply | from pykolab.itip import send_reply | ||||
from pykolab.translate import _ | from pykolab.translate import _ | ||||
# define some contstants used in the code below | # define some contstants used in the code below | ||||
ACT_MANUAL = 1 | ACT_MANUAL = 1 | ||||
Lint: PEP8 E221: multiple spaces before operator | |||||
ACT_ACCEPT = 2 | ACT_ACCEPT = 2 | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ACT_DELEGATE = 4 | ACT_DELEGATE = 4 | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ACT_REJECT = 8 | ACT_REJECT = 8 | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ACT_UPDATE = 16 | ACT_UPDATE = 16 | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ACT_CANCEL_DELETE = 32 | ACT_CANCEL_DELETE = 32 | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ACT_SAVE_TO_FOLDER = 64 | ACT_SAVE_TO_FOLDER = 64 | ||||
COND_IF_AVAILABLE = 128 | COND_IF_AVAILABLE = 128 | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
COND_IF_CONFLICT = 256 | COND_IF_CONFLICT = 256 | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
COND_TENTATIVE = 512 | COND_TENTATIVE = 512 | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
COND_NOTIFY = 1024 | COND_NOTIFY = 1024 | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
COND_FORWARD = 2048 | COND_FORWARD = 2048 | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
COND_TYPE_EVENT = 4096 | COND_TYPE_EVENT = 4096 | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
COND_TYPE_TASK = 8192 | COND_TYPE_TASK = 8192 | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
COND_TYPE_ALL = COND_TYPE_EVENT + COND_TYPE_TASK | COND_TYPE_ALL = COND_TYPE_EVENT + COND_TYPE_TASK | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ACT_TENTATIVE = ACT_ACCEPT + COND_TENTATIVE | ACT_TENTATIVE = ACT_ACCEPT + COND_TENTATIVE | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ACT_UPDATE_AND_NOTIFY = ACT_UPDATE + COND_NOTIFY | ACT_UPDATE_AND_NOTIFY = ACT_UPDATE + COND_NOTIFY | ||||
ACT_SAVE_AND_FORWARD = ACT_SAVE_TO_FOLDER + COND_FORWARD | ACT_SAVE_AND_FORWARD = ACT_SAVE_TO_FOLDER + COND_FORWARD | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ACT_CANCEL_DELETE_AND_NOTIFY = ACT_CANCEL_DELETE + COND_NOTIFY | ACT_CANCEL_DELETE_AND_NOTIFY = ACT_CANCEL_DELETE + COND_NOTIFY | ||||
FOLDER_TYPE_ANNOTATION = '/vendor/kolab/folder-type' | FOLDER_TYPE_ANNOTATION = '/vendor/kolab/folder-type' | ||||
MESSAGE_PROCESSED = 1 | MESSAGE_PROCESSED = 1 | ||||
MESSAGE_FORWARD = 2 | MESSAGE_FORWARD = 2 | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
policy_name_map = { | policy_name_map = { | ||||
# policy values applying to all object types | # policy values applying to all object types | ||||
'ALL_MANUAL': ACT_MANUAL + COND_TYPE_ALL, | 'ALL_MANUAL': ACT_MANUAL + COND_TYPE_ALL, | ||||
'ALL_ACCEPT': ACT_ACCEPT + COND_TYPE_ALL, | 'ALL_ACCEPT': ACT_ACCEPT + COND_TYPE_ALL, | ||||
'ALL_REJECT': ACT_REJECT + COND_TYPE_ALL, | 'ALL_REJECT': ACT_REJECT + COND_TYPE_ALL, | ||||
'ALL_DELEGATE': ACT_DELEGATE + COND_TYPE_ALL, # not implemented | 'ALL_DELEGATE': ACT_DELEGATE + COND_TYPE_ALL, # not implemented | ||||
'ALL_UPDATE': ACT_UPDATE + COND_TYPE_ALL, | 'ALL_UPDATE': ACT_UPDATE + COND_TYPE_ALL, | ||||
▲ Show 20 Lines • Show All 1,196 Lines • ▼ Show 20 Lines | def send_update_notification(object, receiving_user, old=None, reply=True, sender=None, comment=None): | ||||
msg = MIMEText(utils.stripped_message(message_text), _charset='utf-8') | msg = MIMEText(utils.stripped_message(message_text), _charset='utf-8') | ||||
msg['To'] = receiving_user['mail'] | msg['To'] = receiving_user['mail'] | ||||
msg['Date'] = formatdate(localtime=True) | msg['Date'] = formatdate(localtime=True) | ||||
msg['Subject'] = utils.str2unicode(_('"%s" has been updated') % (object.get_summary())) | msg['Subject'] = utils.str2unicode(_('"%s" has been updated') % (object.get_summary())) | ||||
msg['From'] = Header(utils.str2unicode('%s' % orgname) if orgname else '') | msg['From'] = Header(utils.str2unicode('%s' % orgname) if orgname else '') | ||||
msg['From'].append("<%s>" % orgemail) | msg['From'].append("<%s>" % orgemail) | ||||
seed = random.randint(0, 6) | |||||
alarm_after = (seed * 10) + 60 | |||||
log.debug(_("Set alarm to %s seconds") % (alarm_after), level=8) | |||||
signal.alarm(alarm_after) | |||||
result = modules._sendmail(orgemail, receiving_user['mail'], msg.as_string()) | result = modules._sendmail(orgemail, receiving_user['mail'], msg.as_string()) | ||||
log.debug(_("Sent update notification to %r: %r") % (receiving_user['mail'], result), level=8) | log.debug(_("Sent update notification to %r: %r") % (receiving_user['mail'], result), level=8) | ||||
signal.alarm(0) | |||||
def send_cancel_notification(object, receiving_user, deleted=False, sender=None, comment=None): | def send_cancel_notification(object, receiving_user, deleted=False, sender=None, comment=None): | ||||
""" | """ | ||||
Send a notification about event/task cancellation | Send a notification about event/task cancellation | ||||
""" | """ | ||||
from email.MIMEText import MIMEText | from email.MIMEText import MIMEText | ||||
from email.Utils import formatdate | from email.Utils import formatdate | ||||
from email.header import Header | from email.header import Header | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | def send_cancel_notification(object, receiving_user, deleted=False, sender=None, comment=None): | ||||
msg = MIMEText(utils.stripped_message(message_text), _charset='utf-8') | msg = MIMEText(utils.stripped_message(message_text), _charset='utf-8') | ||||
msg['To'] = receiving_user['mail'] | msg['To'] = receiving_user['mail'] | ||||
msg['Date'] = formatdate(localtime=True) | msg['Date'] = formatdate(localtime=True) | ||||
msg['Subject'] = utils.str2unicode(_('"%s" has been cancelled') % (object.get_summary())) | msg['Subject'] = utils.str2unicode(_('"%s" has been cancelled') % (object.get_summary())) | ||||
msg['From'] = Header(utils.str2unicode('%s' % orgname) if orgname else '') | msg['From'] = Header(utils.str2unicode('%s' % orgname) if orgname else '') | ||||
msg['From'].append("<%s>" % orgemail) | msg['From'].append("<%s>" % orgemail) | ||||
seed = random.randint(0, 6) | |||||
alarm_after = (seed * 10) + 60 | |||||
log.debug(_("Set alarm to %s seconds") % (alarm_after), level=8) | |||||
signal.alarm(alarm_after) | |||||
result = modules._sendmail(orgemail, receiving_user['mail'], msg.as_string()) | result = modules._sendmail(orgemail, receiving_user['mail'], msg.as_string()) | ||||
log.debug(_("Sent cancel notification to %r: %r") % (receiving_user['mail'], result), level=8) | log.debug(_("Sent cancel notification to %r: %r") % (receiving_user['mail'], result), level=8) | ||||
signal.alarm(0) | |||||
def is_auto_reply(user, sender_email, type): | def is_auto_reply(user, sender_email, type): | ||||
accept_available = False | accept_available = False | ||||
accept_conflicts = False | accept_conflicts = False | ||||
for policy in get_matching_invitation_policies(user, sender_email, object_type_conditons.get(type, COND_TYPE_EVENT)): | for policy in get_matching_invitation_policies(user, sender_email, object_type_conditons.get(type, COND_TYPE_EVENT)): | ||||
if policy & (ACT_ACCEPT | ACT_REJECT | ACT_DELEGATE): | if policy & (ACT_ACCEPT | ACT_REJECT | ACT_DELEGATE): | ||||
if check_policy_condition(policy, True): | if check_policy_condition(policy, True): | ||||
accept_available = True | accept_available = True | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |
multiple spaces before operator