diff options
author | Thomas Bruederli <bruederli@kolabsys.com> | 2014-03-04 16:14:50 -0500 |
---|---|---|
committer | Thomas Bruederli <bruederli@kolabsys.com> | 2014-03-04 16:14:50 -0500 |
commit | 65df5988b84608386dd0b56c6e60e3eb9a67e83e (patch) | |
tree | 3e448eb37dc013679b3a2497d388e98d686d7394 | |
parent | a4c05082d6b365da9bc4ad138278d682bc1bce80 (diff) | |
download | pykolab-65df5988b84608386dd0b56c6e60e3eb9a67e83e.tar.gz |
Ignore invalid iTip messages but not fail on them
-rw-r--r-- | tests/unit/test-011-wallace_resources.py | 9 | ||||
-rw-r--r-- | wallace/module_resources.py | 15 |
2 files changed, 17 insertions, 7 deletions
diff --git a/tests/unit/test-011-wallace_resources.py b/tests/unit/test-011-wallace_resources.py index 204df06..50fdc6b 100644 --- a/tests/unit/test-011-wallace_resources.py +++ b/tests/unit/test-011-wallace_resources.py @@ -305,6 +305,15 @@ class TestWallaceResources(unittest.TestCase): itips5 = module_resources.itip_events_from_message(message_from_string(itip_empty)) self.assertEqual(len(itips5), 0, "Simple plain text message") + # invalid itip blocks + self.assertRaises(Exception, module_resources.itip_events_from_message, message_from_string(itip_multipart.replace("BEGIN:VEVENT", ""))) + + itips6 = module_resources.itip_events_from_message(message_from_string(itip_multipart.replace("DTSTART;", "X-DTSTART;"))) + self.assertEqual(len(itips6), 0, "Event with not DTSTART") + + itips7 = module_resources.itip_events_from_message(message_from_string(itip_non_multipart.replace("METHOD:REQUEST", "METHOD:PUBLISH").replace("method=REQUEST", "method=PUBLISH"))) + self.assertEqual(len(itips7), 0, "Invalid METHOD") + def test_002_resource_record_from_email_address(self): res = module_resources.resource_record_from_email_address("doe@example.org") diff --git a/wallace/module_resources.py b/wallace/module_resources.py index cf03520..3db2209 100644 --- a/wallace/module_resources.py +++ b/wallace/module_resources.py @@ -152,7 +152,11 @@ def execute(*args, **kw): # An iTip message may contain multiple events. Later on, test if the message # is an iTip message by checking the length of this list. - itip_events = itip_events_from_message(message) + try: + itip_events = itip_events_from_message(message) + except Exception, e: + log.error(_("Failed to parse iTip events from message: %r" % (e))) + itip_events = [] if not len(itip_events) > 0: log.info( @@ -586,7 +590,7 @@ def itip_events_from_message(message): seen_uids = [] # iTip methods we are actually interested in. Other methods will be ignored. - itip_methods = [ "REQUEST", "REPLY", "ADD", "CANCEL" ] + itip_methods = [ "REQUEST", "CANCEL" ] # Are all iTip messages multipart? No! RFC 6047, section 2.4 states "A # MIME body part containing content information that conforms to this @@ -600,11 +604,8 @@ def itip_events_from_message(message): # But in real word, other mime-types are used as well if part.get_content_type() in [ "text/calendar", "text/x-vcalendar", "application/ics" ]: if not str(part.get_param('method')).upper() in itip_methods: - log.error( - _("Method %r not really interesting for us.") % ( - part.get_param('method') - ) - ) + log.error(_("Method %r not really interesting for us.") % (part.get_param('method'))) + continue # Get the itip_payload itip_payload = part.get_payload(decode=True) |