summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-08-04 16:32:24 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2014-08-04 16:32:24 (GMT)
commit0813c350ed72c595bdee53e9c78490d8eccf7e98 (patch)
tree0c8aac6e742af18b8477c7e984bb3464814c6461
parent70139312f2b09837c5e9c95e81888d2796a4d7e2 (diff)
downloadpykolab-0813c350ed72c595bdee53e9c78490d8eccf7e98.tar.gz
Add function to send iTip REQUESTs
-rw-r--r--pykolab/itip/__init__.py50
1 files changed, 47 insertions, 3 deletions
diff --git a/pykolab/itip/__init__.py b/pykolab/itip/__init__.py
index 816ee1d..40cf007 100644
--- a/pykolab/itip/__init__.py
+++ b/pykolab/itip/__init__.py
@@ -113,7 +113,7 @@ def objects_from_message(message, objname, methods=None):
# TODO: distinguish event and todo here
itip['xml'] = event_from_ical(c.to_ical())
except Exception, e:
- log.error("event_from_ical() exception: %r" % (e))
+ log.error("event_from_ical() exception: %r; iCal: %s" % (e, itip_payload))
continue
itip_objects.append(itip)
@@ -198,10 +198,10 @@ def send_reply(from_address, itip_events, response_text, subject=None):
"""
Send the given iCal events as a valid iTip REPLY to the organizer.
"""
-
import smtplib
conf = pykolab.getConf()
+ smtp = None
if isinstance(itip_events, dict):
itip_events = [ itip_events ]
@@ -237,4 +237,48 @@ def send_reply(from_address, itip_events, response_text, subject=None):
except Exception, e:
log.error(_("SMTP sendmail error: %r") % (e))
- smtp.quit()
+ if smtp:
+ smtp.quit()
+
+
+def send_request(to_address, itip_events, request_text, subject=None):
+ """
+ Send an iTip REQUEST message from the given iCal events
+ """
+ import smtplib
+
+ conf = pykolab.getConf()
+ smtp = None
+
+ if isinstance(itip_events, dict):
+ itip_events = [ itip_events ]
+
+ for itip_event in itip_events:
+ event_summary = itip_event['xml'].get_summary()
+ message_text = request_text % { 'summary':event_summary }
+
+ if subject is not None:
+ subject = subject % { 'summary':event_summary }
+
+ try:
+ message = itip_event['xml'].to_message_itip(None,
+ method="REQUEST",
+ message_text=message_text,
+ subject=subject
+ )
+ except Exception, e:
+ log.error(_("Failed to compose iTip request message: %r") % (e))
+ return
+
+ smtp = smtplib.SMTP("localhost", 10026) # requests go through wallace
+
+ if conf.debuglevel > 8:
+ smtp.set_debuglevel(True)
+
+ try:
+ smtp.sendmail(message['From'], to_address, message.as_string())
+ except Exception, e:
+ log.error(_("SMTP sendmail error: %r") % (e))
+
+ if smtp:
+ smtp.quit()