summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pykolab/xml/event.py16
-rw-r--r--tests/unit/test-003-event.py1
2 files changed, 17 insertions, 0 deletions
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index 39034f6..f9b6487 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -303,6 +303,22 @@ class Event(object):
def get_attachments(self):
return self.event.attachments()
+ def get_attachment_data(self, i):
+ vattach = self.event.attachments()
+ if i < len(vattach):
+ attachment = vattach[i]
+ uri = attachment.uri()
+ if uri and uri[0:4] == 'cid:':
+ # get data from MIME part with matching content-id
+ cid = '<' + uri[4:] + '>'
+ for p in self._attachment_parts:
+ if p['Content-ID'] == cid:
+ return p.get_payload(decode=True)
+ else:
+ return attachment.data()
+
+ return None
+
def get_alarms(self):
return self.event.alarms()
diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py
index 363c75e..81337d9 100644
--- a/tests/unit/test-003-event.py
+++ b/tests/unit/test-003-event.py
@@ -389,6 +389,7 @@ METHOD:REQUEST
self.assertEqual(parts[3]['Content-ID'].strip('<>'), attachments[0].uri()[4:])
self.assertEqual(parts[4].get_content_type(), 'text/plain')
self.assertEqual(parts[4]['Content-ID'].strip('<>'), attachments[1].uri()[4:])
+ self.assertEqual(event.get_attachment_data(1), 'This is a text file')
def test_024_bogus_itip_data(self):
# DTSTAMP contains an invalid date/time value