Changeset View
Changeset View
Standalone View
Standalone View
pykolab/xml/todo.py
Show All 23 Lines | def todo_from_message(message): | ||||
todo = None | todo = 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) | ||||
todo = todo_from_string(payload) | todo = todo_from_string(payload) | ||||
# append attachment parts to Todo object | # append attachment parts to Todo object | ||||
elif todo and part.has_key('Content-ID'): | elif todo and 'Content-ID' in part: | ||||
todo._attachment_parts.append(part) | todo._attachment_parts.append(part) | ||||
return todo | return todo | ||||
# FIXME: extend a generic pykolab.xml.Xcal class instead of Event | # FIXME: extend a generic pykolab.xml.Xcal class instead of Event | ||||
class Todo(Event): | class Todo(Event): | ||||
type = 'task' | type = 'task' | ||||
Show All 36 Lines | def from_ical(self, ical, raw): | ||||
# VCALENDAR block was given, find the first VTODO item | # VCALENDAR block was given, find the first VTODO item | ||||
if isinstance(ical_todo, icalendar.Calendar): | if isinstance(ical_todo, icalendar.Calendar): | ||||
for c in ical_todo.walk(): | for c in ical_todo.walk(): | ||||
if c.name == 'VTODO': | if c.name == 'VTODO': | ||||
ical_todo = c | ical_todo = c | ||||
break | break | ||||
log.debug("Todo.from_ical(); %r, %r, %r" % (type(ical_todo), ical_todo.has_key('ATTACH'), ical_todo.has_key('ATTENDEE')), level=8) | log.debug("Todo.from_ical(); %r, %r, %r" % (type(ical_todo), 'ATTACH' in ical_todo, 'ATTENDEE' in ical_todo), level=8) | ||||
# DISABLED: use the libkolab calendaring bindings to load the full iCal data | # DISABLED: use the libkolab calendaring bindings to load the full iCal data | ||||
# TODO: this requires support for iCal parsing in the kolab.calendaring bindings | # TODO: this requires support for iCal parsing in the kolab.calendaring bindings | ||||
if False and ical_todo.has_key('ATTACH') or [part for part in ical_todo.walk() if part.name == 'VALARM']: | if False and 'ATTACH' in ical_todo or [part for part in ical_todo.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.Todo() | self.event = kolabformat.Todo() | ||||
for attr in list(set(ical_todo.required)): | for attr in list(set(ical_todo.required)): | ||||
if ical_todo.has_key(attr): | if attr in ical_todo: | ||||
self.set_from_ical(attr.lower(), ical_todo[attr]) | self.set_from_ical(attr.lower(), ical_todo[attr]) | ||||
for attr in list(set(ical_todo.singletons)): | for attr in list(set(ical_todo.singletons)): | ||||
if ical_todo.has_key(attr): | if attr in ical_todo: | ||||
if isinstance(ical_todo[attr], list): | if isinstance(ical_todo[attr], list): | ||||
ical_todo[attr] = ical_todo[attr][0]; | ical_todo[attr] = ical_todo[attr][0]; | ||||
self.set_from_ical(attr.lower(), ical_todo[attr]) | self.set_from_ical(attr.lower(), ical_todo[attr]) | ||||
for attr in list(set(ical_todo.multiple)): | for attr in list(set(ical_todo.multiple)): | ||||
if ical_todo.has_key(attr): | if attr in ical_todo: | ||||
self.set_from_ical(attr.lower(), ical_todo[attr]) | self.set_from_ical(attr.lower(), ical_todo[attr]) | ||||
# although specified by RFC 2445/5545, icalendar doesn't have this property listed | # although specified by RFC 2445/5545, icalendar doesn't have this property listed | ||||
if ical_todo.has_key('PERCENT-COMPLETE'): | if 'PERCENT-COMPLETE' in ical_todo: | ||||
self.set_from_ical('percentcomplete', ical_todo['PERCENT-COMPLETE']) | self.set_from_ical('percentcomplete', ical_todo['PERCENT-COMPLETE']) | ||||
def _xml_from_ical(self, ical): | def _xml_from_ical(self, ical): | ||||
# FIXME: kolabformat or kolab.calendaring modules do not provide bindings to import Todo from iCal | # FIXME: kolabformat or kolab.calendaring modules do not provide bindings to import Todo from iCal | ||||
self.event = Todo() | self.event = Todo() | ||||
def set_ical_attach(self, attachment): | def set_ical_attach(self, attachment): | ||||
if hasattr(attachment, 'params'): | if hasattr(attachment, 'params'): | ||||
params = attachment.params | params = attachment.params | ||||
else: | else: | ||||
params = {} | params = {} | ||||
_attachment = kolabformat.Attachment() | _attachment = kolabformat.Attachment() | ||||
if params.has_key('FMTTYPE'): | if 'FMTTYPE' in params: | ||||
mimetype = str(params['FMTTYPE']) | mimetype = str(params['FMTTYPE']) | ||||
else: | else: | ||||
mimetype = 'application/octet-stream' | mimetype = 'application/octet-stream' | ||||
if params.has_key('X-LABEL'): | if 'X-LABEL' in params: | ||||
_attachment.setLabel(str(params['X-LABEL'])) | _attachment.setLabel(str(params['X-LABEL'])) | ||||
decode = False | decode = False | ||||
if params.has_key('ENCODING'): | if 'ENCODING' in params: | ||||
if params['ENCODING'] == "BASE64" or params['ENCODING'] == "B": | if params['ENCODING'] == "BASE64" or params['ENCODING'] == "B": | ||||
decode = True | decode = True | ||||
_attachment.setData(base64.b64decode(str(attachment)) if decode else str(attachment), mimetype) | _attachment.setData(base64.b64decode(str(attachment)) if decode else str(attachment), mimetype) | ||||
vattach = self.event.attachments() | vattach = self.event.attachments() | ||||
vattach.append(_attachment) | vattach.append(_attachment) | ||||
self.event.setAttachments(vattach) | self.event.setAttachments(vattach) | ||||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |