summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2014-07-30 14:24:57 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2014-07-30 14:24:57 +0200
commit46fd1e032160f010525bddedf18a9ccd14a5c62a (patch)
tree8c8910ce85eeec7f2ca983ca2c7ddb318e57e577
parente949ef9342ca4c8b67d6207eb2ac211e0b1c2122 (diff)
parentbc7fba1f1f1e0afab921b069be6e7d9c562addda (diff)
downloadpykolab-46fd1e032160f010525bddedf18a9ccd14a5c62a.tar.gz
Merge branch 'master' of ssh://git.kolabsys.com/git/pykolab
-rw-r--r--pykolab/imap/__init__.py3
-rw-r--r--pykolab/xml/event.py47
-rw-r--r--pykolab/xml/recurrence_rule.py5
-rw-r--r--tests/unit/test-003-event.py51
4 files changed, 99 insertions, 7 deletions
diff --git a/pykolab/imap/__init__.py b/pykolab/imap/__init__.py
index 33984bf..6cec86f 100644
--- a/pykolab/imap/__init__.py
+++ b/pykolab/imap/__init__.py
@@ -211,8 +211,7 @@ class IMAP(object):
folder_path = self.folder_utf7(folder_path)
if not server == None:
- if not self._imap.has_key(server):
- self.connect(server=server)
+ self.connect(server=server)
try:
self._imap[server].cm(folder_path, partition=partition)
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index 8e41a92..98436d9 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -7,6 +7,7 @@ import pytz
import time
import uuid
import base64
+import re
import pykolab
from pykolab import constants
@@ -56,6 +57,17 @@ class Event(object):
"CONFIDENTIAL": kolabformat.ClassConfidential,
}
+ alarm_type_map = {
+ 'EMAIL': kolabformat.Alarm.EMailAlarm,
+ 'DISPLAY': kolabformat.Alarm.DisplayAlarm,
+ 'AUDIO': kolabformat.Alarm.AudioAlarm
+ }
+
+ related_map = {
+ 'START': kolabformat.Start,
+ 'END': kolabformat.End
+ }
+
properties_map = {
# property: getter
"uid": "get_uid",
@@ -494,8 +506,7 @@ class Event(object):
if status in self.status_map.keys():
return status
- if status in self.status_map.values():
- return [k for k, v in self.status_map.iteritems() if v == status][0]
+ return self._translate_value(status, self.status_map)
def get_ical_sequence(self):
return str(self.event.sequence()) if self.event.sequence() else None
@@ -839,7 +850,7 @@ class Event(object):
elif isinstance(val, kolabformat.vectorattachment):
val = [dict(fmttype=x.mimetype(), label=x.label(), uri=x.uri()) for x in val]
elif isinstance(val, kolabformat.vectoralarm):
- val = [dict(type=x.type()) for x in val]
+ val = [self._alarm_to_dict(x) for x in val]
elif isinstance(val, list):
val = [x.to_dict() for x in val if hasattr(x, 'to_dict')]
@@ -848,6 +859,36 @@ class Event(object):
return data
+ def _alarm_to_dict(self, alarm):
+ ret = dict(
+ action=self._translate_value(alarm.type(), self.alarm_type_map),
+ summary=alarm.summary(),
+ description=alarm.description(),
+ trigger=None
+ )
+
+ start = alarm.start()
+ if start and start.isValid():
+ ret['trigger'] = xmlutils.from_cdatetime(start, True)
+ else:
+ ret['trigger'] = dict(related=self._translate_value(alarm.relativeTo(), self.related_map))
+ duration = alarm.relativeStart()
+ if duration and duration.isValid():
+ prefix = '-' if duration.isNegative() else '+'
+ value = prefix + "P%dW%dDT%dH%dM%dS" % (
+ duration.weeks(), duration.days(), duration.hours(), duration.minutes(), duration.seconds()
+ )
+ ret['trigger']['value'] = re.sub(r"T$", '', re.sub(r"0[WDHMS]", '', value))
+
+ if alarm.type() == kolabformat.Alarm.EMailAlarm:
+ ret['attendee'] = [ContactReference(a).to_dict() for a in alarm.attendees()]
+
+ return ret
+
+ def _translate_value(self, val, map):
+ name_map = dict([(v, k) for (k, v) in map.iteritems()])
+ return name_map[val] if name_map.has_key(val) else 'UNKNOWN'
+
def to_message(self):
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
diff --git a/pykolab/xml/recurrence_rule.py b/pykolab/xml/recurrence_rule.py
index eb17fd5..4a0b6c5 100644
--- a/pykolab/xml/recurrence_rule.py
+++ b/pykolab/xml/recurrence_rule.py
@@ -60,6 +60,7 @@ class RecurrenceRule(kolabformat.RecurrenceRule):
'until': 'end',
'bymonth': 'bymonth',
'byday': 'byday',
+ 'bymonthday':'bymonthday',
'byyearday': 'byyearday',
'byweekno': 'byweekno',
'byhour': 'byhour',
@@ -106,9 +107,9 @@ class RecurrenceRule(kolabformat.RecurrenceRule):
if isinstance(val, kolabformat.cDateTime):
val = xmlutils.from_cdatetime(val, True)
elif isinstance(val, kolabformat.vectori):
- val = [int(v) for x in val]
+ val = ",".join([int(v) for x in val])
elif isinstance(val, kolabformat.vectordaypos):
- val = ["%d%s" % (x.occurence, self._translate_value(x.weekday)) for x in val]
+ val = ",".join(["%s%s" % (str(x.occurence()) if x.occurence() != 0 else '', self._translate_value(x.weekday(), self.weekday_map)) for x in val])
if val is not None:
data[p] = val
diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py
index 5017091..f069be3 100644
--- a/tests/unit/test-003-event.py
+++ b/tests/unit/test-003-event.py
@@ -190,6 +190,50 @@ xml_event = """
<value>BUSY</value>
</x-custom>
</properties>
+ <components>
+ <valarm>
+ <properties>
+ <action>
+ <text>DISPLAY</text>
+ </action>
+ <description>
+ <text>alarm 1</text>
+ </description>
+ <trigger>
+ <parameters>
+ <related>
+ <text>START</text>
+ </related>
+ </parameters>
+ <duration>-PT2H</duration>
+ </trigger>
+ </properties>
+ </valarm>
+ <valarm>
+ <properties>
+ <action>
+ <text>EMAIL</text>
+ </action>
+ <summary>
+ <text>test</text>
+ </summary>
+ <description>
+ <text>alarm 2</text>
+ </description>
+ <attendee>
+ <cal-address>mailto:%3Cjohn.die%40example.org%3E</cal-address>
+ </attendee>
+ <trigger>
+ <parameters>
+ <related>
+ <text>START</text>
+ </related>
+ </parameters>
+ <duration>-P1D</duration>
+ </trigger>
+ </properties>
+ </valarm>
+ </components>
</vevent>
</components>
</vcalendar>
@@ -520,6 +564,13 @@ END:VEVENT
self.assertEqual(data['rrule']['wkst'], 'MO')
self.assertIsInstance(data['rrule']['until'], datetime.date)
+ self.assertIsInstance(data['alarm'], list)
+ self.assertEqual(len(data['alarm']), 2)
+ self.assertEqual(data['alarm'][0]['action'], 'DISPLAY')
+ self.assertEqual(data['alarm'][1]['action'], 'EMAIL')
+ self.assertEqual(data['alarm'][1]['trigger']['value'], '-P1D')
+ self.assertEqual(len(data['alarm'][1]['attendee']), 1)
+
if __name__ == '__main__':
unittest.main()