[CalendarServer-changes] [4471] CalendarServer/branches/users/cdaboo/partition-4464/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu Jul 23 09:18:48 PDT 2009


Revision: 4471
          http://trac.macosforge.org/projects/calendarserver/changeset/4471
Author:   cdaboo at apple.com
Date:     2009-07-23 09:18:48 -0700 (Thu, 23 Jul 2009)
Log Message:
-----------
When doing iSchedule "unnormalize" the calendar user addresses so outside agents don't see our urn:uuid things.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/partition-4464/twistedcaldav/ical.py
    CalendarServer/branches/users/cdaboo/partition-4464/twistedcaldav/scheduling/ischedule.py

Modified: CalendarServer/branches/users/cdaboo/partition-4464/twistedcaldav/ical.py
===================================================================
--- CalendarServer/branches/users/cdaboo/partition-4464/twistedcaldav/ical.py	2009-07-22 16:37:15 UTC (rev 4470)
+++ CalendarServer/branches/users/cdaboo/partition-4464/twistedcaldav/ical.py	2009-07-23 16:18:48 UTC (rev 4471)
@@ -1242,8 +1242,8 @@
         timezone_refs    = set()
         timezones        = set()
         got_master       = False
-        got_override     = False
-        master_recurring = False
+#        got_override     = False
+#        master_recurring = False
         
         for subcomponent in self.subcomponents():
             # Disallowed in CalDAV-Access-08, section 4.1
@@ -1291,14 +1291,14 @@
                         raise ValueError(msg)
                     else:
                         got_master = True
-                        master_recurring = subcomponent.hasProperty("RRULE") or subcomponent.hasProperty("RDATE")
-                else:
-                    got_override = True
+#                        master_recurring = subcomponent.hasProperty("RRULE") or subcomponent.hasProperty("RDATE")
+#                else:
+#                    got_override = True
                             
                 # Check that if an override is present then the master is recurring
                 # Leopard iCal sometimes does this for overridden instances that an Attendee receives and
                 # it creates a "fake" (invalid) master. We are going to skip this test here. Instead implicit
-                # scheduling with verify the validity of the components and raise if they don't make sense.
+                # scheduling will verify the validity of the components and raise if they don't make sense.
                 # If no scheduling is happening then we allow this - that may cause other clients to choke.
                 # If it does we will have to reinstate this check but only after we have checked for implicit.
 #                if got_override and got_master and not master_recurring:
@@ -2075,7 +2075,7 @@
                     if dataValue.find(dropboxPrefix) != -1:
                         self.removeProperty(attachment)
 
-    def normalizeCalendarUserAddresses(self, lookupFunction):
+    def normalizeCalendarUserAddresses(self, lookupFunction, toUUID=True):
         """
         Do the ORGANIZER/ATTENDEE property normalization.
 
@@ -2097,9 +2097,48 @@
                 if guid is None:
                     continue
 
-                # Always re-write value to urn:uuid
-                prop.setValue("urn:uuid:%s" % (guid,))
+                # Get any EMAIL parameter
+                oldemail = prop.params().get("EMAIL", (None,))[0]
+                if oldemail:
+                    oldemail = "mailto:%s" % (oldemail,)
 
+                if toUUID:
+                    # Always re-write value to urn:uuid
+                    prop.setValue("urn:uuid:%s" % (guid,))
+                    
+                # If it is already a non-UUID address leave it be
+                elif cuaddr.startswith("urn:uuid:"):
+                    if oldemail:
+                        # Use the EMAIL parameter if it exists
+                        newaddr = oldemail
+                    else:
+                        # Pick the first mailto, or failing that the first http, or failing that the first one
+                        first_mailto = None
+                        first_http = None
+                        first = None
+                        for addr in cuaddrs:
+                            if addr.startswith("mailto:"):
+                                first_mailto = addr
+                                break
+                            elif addr.startswith("http:"):
+                                if not first_http:
+                                    first_http = addr
+                            elif not first:
+                                first = addr
+                        
+                        if first_mailto:
+                            newaddr = first_mailto
+                        elif first_http:
+                            newaddr = first_http
+                        elif first:
+                            newaddr = first
+                        else:
+                            newaddr = None
+                    
+                    # Make the change
+                    if newaddr:
+                        prop.setValue(newaddr)
+
                 # Always re-write the CN parameter
                 if name:
                     prop.params()["CN"] = [name,]
@@ -2109,12 +2148,8 @@
                     except KeyError:
                         pass
 
-                # Re-write the EMAIL if its value no longer
-                # matches
-                oldemail = prop.params().get("EMAIL", (None,))[0]
-                if oldemail:
-                    oldemail = "mailto:%s" % (oldemail,)
-                if oldemail is None or oldemail not in cuaddrs:
+                # Re-write the EMAIL if its value no longer matches
+                if oldemail and oldemail not in cuaddrs or oldemail is None and toUUID:
                     if cuaddr.startswith("mailto:") and cuaddr in cuaddrs:
                         email = cuaddr[7:]
                     else:

Modified: CalendarServer/branches/users/cdaboo/partition-4464/twistedcaldav/scheduling/ischedule.py
===================================================================
--- CalendarServer/branches/users/cdaboo/partition-4464/twistedcaldav/scheduling/ischedule.py	2009-07-22 16:37:15 UTC (rev 4470)
+++ CalendarServer/branches/users/cdaboo/partition-4464/twistedcaldav/scheduling/ischedule.py	2009-07-23 16:18:48 UTC (rev 4471)
@@ -166,8 +166,22 @@
             )
 
     def _prepareData(self):
-        self.data = str(self.scheduler.calendar)
+        if self.scheduler.method == "PUT": 
+            def lookupFunction(cuaddr):
+                principal = self.scheduler.resource.principalForCalendarUserAddress(cuaddr)
+                if principal is None:
+                    return (None, None, None)
+                else:
+                    return (principal.record.fullName.decode("utf-8"),
+                        principal.record.guid,
+                        principal.record.calendarUserAddresses)
 
+            normalizedCalendar = self.scheduler.calendar.duplicate()
+            normalizedCalendar.normalizeCalendarUserAddresses(lookupFunction, toUUID=False)
+        else:
+            normalizedCalendar = self.scheduler.calendar
+        self.data = str(normalizedCalendar)
+
     def _parseResponse(self, xml):
 
         # Check for correct root element
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090723/83b86c8b/attachment.html>


More information about the calendarserver-changes mailing list