Changeset View
Changeset View
Standalone View
Standalone View
pykolab/xml/event.py
Show All 33 Lines | def event_from_message(message): | ||||
event = None | event = None | ||||
if message.is_multipart(): | if message.is_multipart(): | ||||
for part in message.walk(): | for part in message.walk(): | ||||
if part.get_content_type() == "application/calendar+xml": | if part.get_content_type() == "application/calendar+xml": | ||||
payload = part.get_payload(decode=True) | payload = part.get_payload(decode=True) | ||||
event = event_from_string(payload) | event = event_from_string(payload) | ||||
# append attachment parts to Event object | # append attachment parts to Event object | ||||
elif event and part.has_key('Content-ID'): | elif event and 'Content-ID' in part: | ||||
event._attachment_parts.append(part) | event._attachment_parts.append(part) | ||||
return event | return event | ||||
class Event(object): | class Event(object): | ||||
type = 'event' | type = 'event' | ||||
thisandfuture = False | thisandfuture = False | ||||
▲ Show 20 Lines • Show All 297 Lines • ▼ Show 20 Lines | def from_ical(self, ical, raw=None): | ||||
# VCALENDAR block was given, find the first VEVENT item | # VCALENDAR block was given, find the first VEVENT item | ||||
if isinstance(ical_event, icalendar.Calendar): | if isinstance(ical_event, icalendar.Calendar): | ||||
for c in ical_event.walk(): | for c in ical_event.walk(): | ||||
if c.name == 'VEVENT': | if c.name == 'VEVENT': | ||||
ical_event = c | ical_event = c | ||||
break | break | ||||
# use the libkolab calendaring bindings to load the full iCal data | # use the libkolab calendaring bindings to load the full iCal data | ||||
if ical_event.has_key('RRULE') or ical_event.has_key('ATTACH') \ | if 'RRULE' in ical_event or 'ATTACH' in ical_event \ | ||||
or [part for part in ical_event.walk() if part.name == 'VALARM']: | or [part for part in ical_event.walk() if part.name == 'VALARM']: | ||||
if raw is None or raw == "": | if raw is None or raw == "": | ||||
raw = ical if isinstance(ical, str) else ical.to_ical() | raw = ical if isinstance(ical, str) else ical.to_ical() | ||||
self._xml_from_ical(raw) | self._xml_from_ical(raw) | ||||
else: | else: | ||||
self.event = kolabformat.Event() | self.event = kolabformat.Event() | ||||
# TODO: Clause the timestamps for zulu suffix causing datetime.datetime | # TODO: Clause the timestamps for zulu suffix causing datetime.datetime | ||||
# to fail substitution. | # to fail substitution. | ||||
for attr in list(set(ical_event.required)): | for attr in list(set(ical_event.required)): | ||||
if ical_event.has_key(attr): | if attr in ical_event: | ||||
self.set_from_ical(attr.lower(), ical_event[attr]) | self.set_from_ical(attr.lower(), ical_event[attr]) | ||||
# NOTE: Make sure to list(set()) or duplicates may arise | # NOTE: Make sure to list(set()) or duplicates may arise | ||||
# NOTE: Keep the original order e.g. to read DTSTART before RECURRENCE-ID | # NOTE: Keep the original order e.g. to read DTSTART before RECURRENCE-ID | ||||
for attr in list(OrderedDict.fromkeys(ical_event.singletons)): | for attr in list(OrderedDict.fromkeys(ical_event.singletons)): | ||||
if ical_event.has_key(attr): | if attr in ical_event: | ||||
if isinstance(ical_event[attr], list): | if isinstance(ical_event[attr], list): | ||||
ical_event[attr] = ical_event[attr][0]; | ical_event[attr] = ical_event[attr][0]; | ||||
self.set_from_ical(attr.lower(), ical_event[attr]) | self.set_from_ical(attr.lower(), ical_event[attr]) | ||||
# NOTE: Make sure to list(set()) or duplicates may arise | # NOTE: Make sure to list(set()) or duplicates may arise | ||||
for attr in list(set(ical_event.multiple)): | for attr in list(set(ical_event.multiple)): | ||||
if ical_event.has_key(attr): | if attr in ical_event: | ||||
self.set_from_ical(attr.lower(), ical_event[attr]) | self.set_from_ical(attr.lower(), ical_event[attr]) | ||||
def _xml_from_ical(self, ical): | def _xml_from_ical(self, ical): | ||||
if not "BEGIN:VCALENDAR" in ical: | if not "BEGIN:VCALENDAR" in ical: | ||||
ical = "BEGIN:VCALENDAR\nVERSION:2.0\n" + ical + "\nEND:VCALENDAR" | ical = "BEGIN:VCALENDAR\nVERSION:2.0\n" + ical + "\nEND:VCALENDAR" | ||||
from kolab.calendaring import EventCal | from kolab.calendaring import EventCal | ||||
self.event = EventCal() | self.event = EventCal() | ||||
success = self.event.fromICal(ical) | success = self.event.fromICal(ical) | ||||
▲ Show 20 Lines • Show All 510 Lines • ▼ Show 20 Lines | def set_ical_attendee(self, _attendee): | ||||
for attendee in _attendee: | for attendee in _attendee: | ||||
address = str(attendee).split(':')[-1] | address = str(attendee).split(':')[-1] | ||||
if hasattr(attendee, 'params'): | if hasattr(attendee, 'params'): | ||||
params = attendee.params | params = attendee.params | ||||
else: | else: | ||||
params = {} | params = {} | ||||
if params.has_key('CN'): | if 'CN' in params: | ||||
name = ustr(params['CN']) | name = ustr(params['CN']) | ||||
else: | else: | ||||
name = None | name = None | ||||
if params.has_key('ROLE'): | if 'ROLE' in params: | ||||
role = params['ROLE'] | role = params['ROLE'] | ||||
else: | else: | ||||
role = None | role = None | ||||
if params.has_key('PARTSTAT'): | if 'PARTSTAT' in params: | ||||
partstat = params['PARTSTAT'] | partstat = params['PARTSTAT'] | ||||
else: | else: | ||||
partstat = None | partstat = None | ||||
if params.has_key('RSVP'): | if 'RSVP' in params: | ||||
rsvp = params['RSVP'] | rsvp = params['RSVP'] | ||||
else: | else: | ||||
rsvp = None | rsvp = None | ||||
if params.has_key('CUTYPE'): | if 'CUTYPE' in params: | ||||
cutype = params['CUTYPE'] | cutype = params['CUTYPE'] | ||||
else: | else: | ||||
cutype = kolabformat.CutypeIndividual | cutype = kolabformat.CutypeIndividual | ||||
att = self.add_attendee(address, name=name, rsvp=rsvp, role=role, participant_status=partstat, cutype=cutype, params=params) | att = self.add_attendee(address, name=name, rsvp=rsvp, role=role, participant_status=partstat, cutype=cutype, params=params) | ||||
def set_ical_dtend(self, dtend): | def set_ical_dtend(self, dtend): | ||||
# shift end by one day on all-day events | # shift end by one day on all-day events | ||||
Show All 22 Lines | def set_ical_organizer(self, organizer): | ||||
cn = None | cn = None | ||||
if hasattr(organizer, 'params'): | if hasattr(organizer, 'params'): | ||||
params = organizer.params | params = organizer.params | ||||
else: | else: | ||||
params = {} | params = {} | ||||
if params.has_key('CN'): | if 'CN' in params: | ||||
cn = ustr(params['CN']) | cn = ustr(params['CN']) | ||||
self.set_organizer(str(address), name=cn) | self.set_organizer(str(address), name=cn) | ||||
def set_ical_priority(self, priority): | def set_ical_priority(self, priority): | ||||
self.set_priority(priority) | self.set_priority(priority) | ||||
def set_ical_sequence(self, sequence): | def set_ical_sequence(self, sequence): | ||||
▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | def _alarm_to_dict(self, alarm): | ||||
if alarm.type() == kolabformat.Alarm.EMailAlarm: | if alarm.type() == kolabformat.Alarm.EMailAlarm: | ||||
ret['attendee'] = [ContactReference(a).to_dict() for a in alarm.attendees()] | ret['attendee'] = [ContactReference(a).to_dict() for a in alarm.attendees()] | ||||
return ret | return ret | ||||
def _translate_value(self, val, map): | def _translate_value(self, val, map): | ||||
name_map = dict([(v, k) for (k, v) in map.iteritems()]) | name_map = dict([(v, k) for (k, v) in map.iteritems()]) | ||||
return name_map[val] if name_map.has_key(val) else 'UNKNOWN' | return name_map[val] if val in name_map else 'UNKNOWN' | ||||
def to_message(self, creator=None): | def to_message(self, creator=None): | ||||
from email.MIMEMultipart import MIMEMultipart | from email.MIMEMultipart import MIMEMultipart | ||||
from email.MIMEBase import MIMEBase | from email.MIMEBase import MIMEBase | ||||
from email.MIMEText import MIMEText | from email.MIMEText import MIMEText | ||||
from email.Utils import COMMASPACE, formatdate | from email.Utils import COMMASPACE, formatdate | ||||
msg = MIMEMultipart() | msg = MIMEMultipart() | ||||
▲ Show 20 Lines • Show All 323 Lines • Show Last 20 Lines |