summaryrefslogtreecommitdiffstats
path: root/wallace
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-07-07 18:43:25 -0400
committerThomas Bruederli <bruederli@kolabsys.com>2014-07-07 18:43:25 -0400
commita674289628249f45ec46c3096b1c476692943ff3 (patch)
tree56a6085d94514a2098eaca41e847e39cb50e693a /wallace
parent6e137a89f6f29975133633e2e70557b3954d4220 (diff)
downloadpykolab-a674289628249f45ec46c3096b1c476692943ff3.tar.gz
Use new pykolab.xml.event_from_message() function in wallace modules and verify that attachments survive event updates
Diffstat (limited to 'wallace')
-rw-r--r--wallace/module_invitationpolicy.py43
-rw-r--r--wallace/module_resources.py39
2 files changed, 39 insertions, 43 deletions
diff --git a/wallace/module_invitationpolicy.py b/wallace/module_invitationpolicy.py
index a141251..7375d2d 100644
--- a/wallace/module_invitationpolicy.py
+++ b/wallace/module_invitationpolicy.py
@@ -39,7 +39,7 @@ from pykolab.auth import Auth
from pykolab.conf import Conf
from pykolab.imap import IMAP
from pykolab.xml import to_dt
-from pykolab.xml import event_from_string
+from pykolab.xml import event_from_message
from pykolab.itip import events_from_message
from pykolab.itip import check_event_conflict
from pykolab.itip import send_reply
@@ -619,15 +619,12 @@ def find_existing_event(itip_event, user_rec):
for num in reversed(data[0].split()):
typ, data = imap.imap.m.fetch(num, '(RFC822)')
- event_message = message_from_string(data[0][1])
-
- if event_message.is_multipart():
- for part in event_message.walk():
- if part.get_content_type() == "application/calendar+xml":
- payload = part.get_payload(decode=True)
- event = event_from_string(payload)
- setattr(event, '_imap_folder', folder)
- break
+ try:
+ event = event_from_message(message_from_string(data[0][1]))
+ setattr(event, '_imap_folder', folder)
+ except Exception, e:
+ log.error(_("Failed to parse event from message %s/%s: %r") % (folder, num, e))
+ continue
if event and event.uid == itip_event['uid']:
return event
@@ -659,20 +656,18 @@ def check_availability(itip_event, receiving_user):
event = None
typ, data = imap.imap.m.fetch(num, '(RFC822)')
- event_message = message_from_string(data[0][1])
-
- if event_message.is_multipart():
- for part in event_message.walk():
- if part.get_content_type() == "application/calendar+xml":
- payload = part.get_payload(decode=True)
- event = event_from_string(payload)
- break
-
- if event and event.uid:
- conflict = check_event_conflict(event, itip_event)
- if conflict:
- log.info(_("Existing event %r conflicts with invitation %r") % (event.uid, itip_event['uid']))
- break
+ try:
+ event = event_from_message(message_from_string(data[0][1]))
+ setattr(event, '_imap_folder', folder)
+ except Exception, e:
+ log.error(_("Failed to parse event from message %s/%s: %r") % (folder, num, e))
+ continue
+
+ if event and event.uid:
+ conflict = check_event_conflict(event, itip_event)
+ if conflict:
+ log.info(_("Existing event %r conflicts with invitation %r") % (event.uid, itip_event['uid']))
+ break
if conflict:
break
diff --git a/wallace/module_resources.py b/wallace/module_resources.py
index f398120..3864f7c 100644
--- a/wallace/module_resources.py
+++ b/wallace/module_resources.py
@@ -40,8 +40,8 @@ import kolabformat
from pykolab.auth import Auth
from pykolab.conf import Conf
from pykolab.imap import IMAP
-from pykolab.xml import event_from_string
from pykolab.xml import to_dt
+from pykolab.xml import event_from_message
from pykolab.itip import events_from_message
from pykolab.itip import check_event_conflict
from pykolab.translate import _
@@ -467,28 +467,29 @@ def read_resource_calendar(resource_rec, itip_events):
event_message = message_from_string(data[0][1])
- if event_message.is_multipart():
- for part in event_message.walk():
- if part.get_content_type() == "application/calendar+xml":
- payload = part.get_payload(decode=True)
- event = pykolab.xml.event_from_string(payload)
+ try:
+ event = event_from_message(message_from_string(data[0][1]))
+ except Exception, e:
+ log.error(_("Failed to parse event from message %s/%s: %r") % (mailbox, num, e))
+ continue
- for itip in itip_events:
- conflict = check_event_conflict(event, itip)
+ if event:
+ for itip in itip_events:
+ conflict = check_event_conflict(event, itip)
- if event.get_uid() == itip['uid']:
- resource_rec['existing_events'].append(itip['uid'])
+ if event.get_uid() == itip['uid']:
+ resource_rec['existing_events'].append(itip['uid'])
- if conflict:
- log.info(
- _("Event %r conflicts with event %r") % (
- itip['xml'].get_uid(),
- event.get_uid()
- )
- )
+ if conflict:
+ log.info(
+ _("Event %r conflicts with event %r") % (
+ itip['xml'].get_uid(),
+ event.get_uid()
+ )
+ )
- resource_rec['conflicting_events'].append(event.get_uid())
- resource_rec['conflict'] = True
+ resource_rec['conflicting_events'].append(event.get_uid())
+ resource_rec['conflict'] = True
return num_messages