[CalendarServer-changes] [11590] CalendarServer/trunk/txdav/caldav/datastore/scheduling

source_changes at macosforge.org source_changes at macosforge.org
Wed Aug 7 13:31:03 PDT 2013


Revision: 11590
          http://trac.calendarserver.org//changeset/11590
Author:   cdaboo at apple.com
Date:     2013-08-07 13:31:03 -0700 (Wed, 07 Aug 2013)
Log Message:
-----------
Handle broken mailto URIs without failing.

Modified Paths:
--------------
    CalendarServer/trunk/txdav/caldav/datastore/scheduling/caldav/delivery.py
    CalendarServer/trunk/txdav/caldav/datastore/scheduling/caldav/test/test_delivery.py
    CalendarServer/trunk/txdav/caldav/datastore/scheduling/cuaddress.py
    CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/delivery.py
    CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/test/test_delivery.py
    CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_utils.py
    CalendarServer/trunk/txdav/caldav/datastore/scheduling/utils.py

Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/caldav/delivery.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/caldav/delivery.py	2013-08-07 15:42:31 UTC (rev 11589)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/caldav/delivery.py	2013-08-07 20:31:03 UTC (rev 11590)
@@ -25,18 +25,19 @@
 from twistedcaldav.caldavxml import caldav_namespace
 from twistedcaldav.config import config
 
+from txdav.base.propertystore.base import PropertyName
 from txdav.caldav.datastore.scheduling.cuaddress import LocalCalendarUser, RemoteCalendarUser, \
     PartitionedCalendarUser, OtherServerCalendarUser
 from txdav.caldav.datastore.scheduling.delivery import DeliveryService
+from txdav.caldav.datastore.scheduling.freebusy import processAvailabilityFreeBusy, \
+    generateFreeBusyInfo, buildFreeBusyResult
 from txdav.caldav.datastore.scheduling.itip import iTIPRequestStatus
 from txdav.caldav.datastore.scheduling.processing import ImplicitProcessor, ImplicitProcessorException
+from txdav.caldav.datastore.scheduling.utils import extractEmailDomain
+from txdav.caldav.icalendarstore import ComponentUpdateState
 
 import hashlib
 import uuid
-from txdav.base.propertystore.base import PropertyName
-from txdav.caldav.icalendarstore import ComponentUpdateState
-from txdav.caldav.datastore.scheduling.freebusy import processAvailabilityFreeBusy, \
-    generateFreeBusyInfo, buildFreeBusyResult
 
 
 """
@@ -71,9 +72,8 @@
 
         # Check for local address matches first
         if cuaddr.startswith("mailto:") and config.Scheduling[cls.serviceType()]["EmailDomain"]:
-            addr = cuaddr[7:].split("?")[0]
+            addrDomain = extractEmailDomain(cuaddr)
             domain = config.Scheduling[cls.serviceType()]["EmailDomain"]
-            _ignore_account, addrDomain = addr.split("@")
             if addrDomain == domain:
                 return succeed(True)
 

Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/caldav/test/test_delivery.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/caldav/test/test_delivery.py	2013-08-07 15:42:31 UTC (rev 11589)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/caldav/test/test_delivery.py	2013-08-07 20:31:03 UTC (rev 11590)
@@ -39,3 +39,7 @@
         self.assertFalse(result)
         result = yield ScheduleViaCalDAV.matchCalendarUserAddress("mailto:user at xyzexample.com")
         self.assertFalse(result)
+        result = yield ScheduleViaCalDAV.matchCalendarUserAddress("mailto:user at xyzexample.com?subject=foobar")
+        self.assertFalse(result)
+        result = yield ScheduleViaCalDAV.matchCalendarUserAddress("mailto:user")
+        self.assertFalse(result)

Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/cuaddress.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/cuaddress.py	2013-08-07 15:42:31 UTC (rev 11589)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/cuaddress.py	2013-08-07 20:31:03 UTC (rev 11590)
@@ -17,6 +17,7 @@
 from twext.python.log import Logger
 
 from txdav.caldav.datastore.scheduling.delivery import DeliveryService
+from txdav.caldav.datastore.scheduling.utils import extractEmailDomain
 
 __all__ = [
     "LocalCalendarUser",
@@ -92,8 +93,7 @@
 
     def extractDomain(self):
         if self.cuaddr.startswith("mailto:"):
-            splits = self.cuaddr[7:].split("?")
-            self.domain = splits[0].split("@")[1]
+            self.domain = extractEmailDomain(self.cuaddr)
         elif self.cuaddr.startswith("http://") or self.cuaddr.startswith("https://"):
             splits = self.cuaddr.split(":")[1][2:].split("/")
             self.domain = splits[0]

Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/delivery.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/delivery.py	2013-08-07 15:42:31 UTC (rev 11589)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/delivery.py	2013-08-07 20:31:03 UTC (rev 11590)
@@ -51,6 +51,7 @@
     RequestStatus, Recipient, ischedule_namespace, CalendarData, \
     ResponseDescription, Error
 from txdav.caldav.datastore.scheduling.itip import iTIPRequestStatus
+from txdav.caldav.datastore.scheduling.utils import extractEmailDomain
 from txdav.caldav.datastore.util import normalizationLookup
 
 from urlparse import urlsplit
@@ -85,7 +86,7 @@
 
         # Only handle mailtos:
         if cuaddr.lower().startswith("mailto:"):
-            _ignore_local, domain = cuaddr[7:].split("@", 1)
+            domain = extractEmailDomain(cuaddr)
             server = (yield cls.serverForDomain(domain))
             returnValue(server is not None)
 

Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/test/test_delivery.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/test/test_delivery.py	2013-08-07 15:42:31 UTC (rev 11589)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/test/test_delivery.py	2013-08-07 20:31:03 UTC (rev 11590)
@@ -60,3 +60,7 @@
         self.assertTrue(result)
         result = yield ScheduleViaISchedule.matchCalendarUserAddress("mailto:user at example.org")
         self.assertFalse(result)
+        result = yield ScheduleViaISchedule.matchCalendarUserAddress("mailto:user at example.org?subject=foobar")
+        self.assertFalse(result)
+        result = yield ScheduleViaISchedule.matchCalendarUserAddress("mailto:user")
+        self.assertFalse(result)

Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_utils.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_utils.py	2013-08-07 15:42:31 UTC (rev 11589)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_utils.py	2013-08-07 20:31:03 UTC (rev 11590)
@@ -23,7 +23,8 @@
 from twisted.internet.defer import inlineCallbacks
 from twisted.trial import unittest
 
-from txdav.caldav.datastore.scheduling.utils import getCalendarObjectForRecord
+from txdav.caldav.datastore.scheduling.utils import getCalendarObjectForRecord, \
+    extractEmailDomain
 from txdav.caldav.datastore.test.util import buildCalendarStore, \
     buildDirectoryRecord
 from txdav.common.datastore.test.util import populateCalendarsFrom, CommonCommonTests
@@ -180,3 +181,20 @@
         resource3 = (yield self.calendarObjectUnderTest(txn, name="3.ics", calendar_name="calendar3", home="user02"))
         self.assertTrue((resource2 is not None) ^ (resource3 is not None))
         yield self.commit()
+
+
+    def test_extractEmailDomain(self):
+        """
+        Test that L{extractEmailDomain} returns the expected results.
+        """
+
+        data = (
+            ("mailto:foo at example.com", "example.com"),
+            ("mailto:foo at example.com?subject=bar", "example.com"),
+            ("mailto:foo", ""),
+            ("mailto:foo@", ""),
+            ("http://foobar.com", ""),
+        )
+
+        for mailto, domain in data:
+            self.assertEqual(extractEmailDomain(mailto), domain)

Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/utils.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/utils.py	2013-08-07 15:42:31 UTC (rev 11589)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/utils.py	2013-08-07 20:31:03 UTC (rev 11590)
@@ -46,3 +46,13 @@
         returnValue(objectResources[0] if len(objectResources) == 1 else None)
     else:
         returnValue(None)
+
+
+
+def extractEmailDomain(mailtoURI):
+    try:
+        addr = mailtoURI[7:].split("?")[0]
+        _ignore_account, addrDomain = addr.split("@")
+    except ValueError:
+        addrDomain = ""
+    return addrDomain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130807/82448679/attachment-0001.html>


More information about the calendarserver-changes mailing list