[CalendarServer-changes] [5391] CalendarServer/trunk/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 24 11:27:11 PDT 2010
Revision: 5391
http://trac.macosforge.org/projects/calendarserver/changeset/5391
Author: sagen at apple.com
Date: 2010-03-24 11:27:08 -0700 (Wed, 24 Mar 2010)
Log Message:
-----------
Unit test for outbound imip processing.
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/mail.py
CalendarServer/trunk/twistedcaldav/test/test_mail.py
Modified: CalendarServer/trunk/twistedcaldav/mail.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/mail.py 2010-03-24 15:44:13 UTC (rev 5390)
+++ CalendarServer/trunk/twistedcaldav/mail.py 2010-03-24 18:27:08 UTC (rev 5391)
@@ -768,7 +768,7 @@
- def outbound(self, originator, recipient, calendar, language='en'):
+ def outbound(self, originator, recipient, calendar, language='en', send=True):
# create token, send email
component = calendar.masterComponent()
@@ -863,34 +863,38 @@
orgCN, attendees, formattedFrom, addressWithToken, recipient,
language=language)
- self.log_debug("Sending: %s" % (message,))
- def _success(result, msgId, fromAddr, toAddr):
- self.log_info("Mail gateway sent message %s from %s to %s" %
- (msgId, fromAddr, toAddr))
- return True
+ if send:
+ self.log_debug("Sending: %s" % (message,))
+ def _success(result, msgId, fromAddr, toAddr):
+ self.log_info("Mail gateway sent message %s from %s to %s" %
+ (msgId, fromAddr, toAddr))
+ return True
- def _failure(failure, msgId, fromAddr, toAddr):
- self.log_error("Mail gateway failed to send message %s from %s to %s (Reason: %s)" %
- (msgId, fromAddr, toAddr, failure.getErrorMessage()))
- return False
+ def _failure(failure, msgId, fromAddr, toAddr):
+ self.log_error("Mail gateway failed to send message %s from %s to %s (Reason: %s)" %
+ (msgId, fromAddr, toAddr, failure.getErrorMessage()))
+ return False
- deferred = defer.Deferred()
+ deferred = defer.Deferred()
- if settings["UseSSL"]:
- contextFactory = ssl.ClientContextFactory()
- else:
- contextFactory = None
+ if settings["UseSSL"]:
+ contextFactory = ssl.ClientContextFactory()
+ else:
+ contextFactory = None
- factory = ESMTPSenderFactory(settings['Username'], settings['Password'],
- fromAddr, toAddr, StringIO(str(message)), deferred,
- contextFactory=contextFactory,
- requireAuthentication=False,
- requireTransportSecurity=settings["UseSSL"])
+ factory = ESMTPSenderFactory(settings['Username'], settings['Password'],
+ fromAddr, toAddr, StringIO(str(message)), deferred,
+ contextFactory=contextFactory,
+ requireAuthentication=False,
+ requireTransportSecurity=settings["UseSSL"])
- reactor.connectTCP(settings['Server'], settings['Port'], factory)
- deferred.addCallback(_success, msgId, fromAddr, toAddr)
- deferred.addErrback(_failure, msgId, fromAddr, toAddr)
- return deferred
+ reactor.connectTCP(settings['Server'], settings['Port'], factory)
+ deferred.addCallback(_success, msgId, fromAddr, toAddr)
+ deferred.addErrback(_failure, msgId, fromAddr, toAddr)
+ return deferred
+ else:
+ return succeed((inviteState, calendar, orgEmail, orgCN, attendees,
+ formattedFrom, recipient, addressWithToken))
def getIconPath(self, details, canceled, language='en'):
Modified: CalendarServer/trunk/twistedcaldav/test/test_mail.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_mail.py 2010-03-24 15:44:13 UTC (rev 5390)
+++ CalendarServer/trunk/twistedcaldav/test/test_mail.py 2010-03-24 18:27:08 UTC (rev 5391)
@@ -16,6 +16,10 @@
from twistedcaldav.mail import *
from twistedcaldav.test.util import TestCase
+from twistedcaldav.ical import Component
+from twistedcaldav.config import config
+
+from twisted.internet.defer import inlineCallbacks
import email
import os
@@ -107,6 +111,139 @@
self.assertEquals(organizer, "mailto:user01 at example.com")
+ @inlineCallbacks
+ def test_outbound(self):
+ """
+ Make sure outbound( ) stores tokens properly so they can be looked up
+ """
+
+ config.Scheduling.iMIP.Sending.Address = "server at example.com"
+
+ data = (
+ # Initial invite
+ (
+ """BEGIN:VCALENDAR
+VERSION:2.0
+METHOD:REQUEST
+BEGIN:VEVENT
+UID:CFDD5E46-4F74-478A-9311-B3FF905449C3
+DTSTART:20100325T154500Z
+DTEND:20100325T164500Z
+ATTENDEE;CN=The Attendee;CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:mailto:attendee at example.com
+ATTENDEE;CN=The Organizer;CUTYPE=INDIVIDUAL;EMAIL=organizer at example.com;PARTSTAT=ACCEPTED:urn:uuid:C3B38B00-4166-11DD-B22C-A07C87E02F6A
+ORGANIZER;CN=The Organizer;EMAIL=organizer at example.com:urn:uuid:C3B38B00-4166-11DD-B22C-A07C87E02F6A
+SUMMARY:testing outbound( )
+END:VEVENT
+END:VCALENDAR
+""",
+ "CFDD5E46-4F74-478A-9311-B3FF905449C3",
+ "mailto:organizer at example.com",
+ "mailto:attendee at example.com",
+ "new",
+ "organizer at example.com",
+ "The Organizer",
+ [
+ (u'The Attendee', u'attendee at example.com'),
+ (u'The Organizer', None)
+ ],
+ "The Organizer <organizer at example.com>",
+ "attendee at example.com",
+ ),
+
+ # Update
+ (
+ """BEGIN:VCALENDAR
+VERSION:2.0
+METHOD:REQUEST
+BEGIN:VEVENT
+UID:CFDD5E46-4F74-478A-9311-B3FF905449C3
+DTSTART:20100325T154500Z
+DTEND:20100325T164500Z
+ATTENDEE;CN=The Attendee;CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:mailto:attendee at example.com
+ATTENDEE;CN=The Organizer;CUTYPE=INDIVIDUAL;EMAIL=organizer at example.com;PARTSTAT=ACCEPTED:urn:uuid:C3B38B00-4166-11DD-B22C-A07C87E02F6A
+ORGANIZER;CN=The Organizer;EMAIL=organizer at example.com:urn:uuid:C3B38B00-4166-11DD-B22C-A07C87E02F6A
+SUMMARY:testing outbound( ) *update*
+END:VEVENT
+END:VCALENDAR
+""",
+ "CFDD5E46-4F74-478A-9311-B3FF905449C3",
+ "mailto:organizer at example.com",
+ "mailto:attendee at example.com",
+ "update",
+ "organizer at example.com",
+ "The Organizer",
+ [
+ (u'The Attendee', u'attendee at example.com'),
+ (u'The Organizer', None)
+ ],
+ "The Organizer <organizer at example.com>",
+ "attendee at example.com",
+ ),
+
+ # Reply
+ (
+ """BEGIN:VCALENDAR
+VERSION:2.0
+METHOD:REPLY
+BEGIN:VEVENT
+UID:DFDD5E46-4F74-478A-9311-B3FF905449C4
+DTSTART:20100325T154500Z
+DTEND:20100325T164500Z
+ATTENDEE;CN=The Attendee;CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED:mailto:attendee at example.com
+ORGANIZER;CN=The Organizer;EMAIL=organizer at example.com:mailto:organizer at example.com
+SUMMARY:testing outbound( ) *reply*
+END:VEVENT
+END:VCALENDAR
+""",
+ None,
+ "mailto:attendee at example.com",
+ "mailto:organizer at example.com",
+ "reply",
+ "organizer at example.com",
+ "The Organizer",
+ [
+ (u'The Attendee', u'attendee at example.com'),
+ ],
+ "attendee at example.com",
+ "organizer at example.com",
+ ),
+
+ )
+ for (inputCalendar, UID, inputOriginator, inputRecipient, inviteState,
+ outputOrganizerEmail, outputOrganizerName, outputAttendeeList,
+ outputFrom, outputRecipient) in data:
+
+ (actualInviteState, actualCalendar, actualOrganizerEmail,
+ actualOrganizerName, actualAttendeeList, actualFrom,
+ actualRecipient, actualReplyTo) = (yield self.handler.outbound(
+ inputOriginator,
+ inputRecipient,
+ Component.fromString(inputCalendar.replace("\n", "\r\n")),
+ send=False)
+ )
+
+ self.assertEquals(actualInviteState, inviteState)
+ self.assertEquals(actualOrganizerEmail, outputOrganizerEmail)
+ self.assertEquals(actualOrganizerName, outputOrganizerName)
+ self.assertEquals(actualAttendeeList, outputAttendeeList)
+ self.assertEquals(actualFrom, outputFrom)
+ self.assertEquals(actualRecipient, outputRecipient)
+
+ if UID: # The organizer is local, and server is sending to remote
+ # attendee
+
+ token = self.handler.db.getToken(inputOriginator,
+ inputRecipient, UID)
+ self.assertNotEquals(token, None)
+ self.assertEquals(actualReplyTo,
+ "server+%s at example.com" % (token,))
+
+ else: # Reply only -- the attendee is local, and server is sending
+ # reply to remote organizer
+
+ self.assertEquals(actualReplyTo, actualFrom)
+
+
class MailGatewayTokensDatabaseTests(TestCase):
def setUp(self):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100324/358ab348/attachment.html>
More information about the calendarserver-changes
mailing list