Przeglądaj źródła

Fix the iCal support (now tested with iCal, Lightning, Evolution)

Guillaume Ayoub 14 lat temu
rodzic
commit
e9ad9b1716
3 zmienionych plików z 14 dodań i 14 usunięć
  1. 5 1
      radicale/__init__.py
  2. 4 4
      radicale/ical.py
  3. 5 9
      radicale/xmlutils.py

+ 5 - 1
radicale/__init__.py

@@ -144,7 +144,11 @@ class Application(object):
     @staticmethod
     def sanitize_uri(uri):
         """Clean URI: unquote and remove /../ to prevent access to other data."""
-        return posixpath.normpath(unquote(uri))
+        uri = unquote(uri)
+        trailing_slash = "/" if uri.endswith("/") else ""
+        uri = posixpath.normpath(uri)
+        trailing_slash = "" if uri == "/" else trailing_slash
+        return uri + trailing_slash
 
     def __call__(self, environ, start_response):
         """Manage a request."""

+ 4 - 4
radicale/ical.py

@@ -192,12 +192,12 @@ class Calendar(object):
         attributes = posixpath.normpath(path).strip("/").split("/")
         if not attributes:
             return None
-        if attributes[-1].endswith(".ics"):
+        if not (os.path.isfile(os.path.join(FOLDER, *attributes)) or path.endswith("/")):
             attributes.pop()
 
         result = []
 
-        path = "/".join(attributes[:min(len(attributes), 2)])
+        path = "/".join(attributes)
         abs_path = os.path.join(FOLDER, path.replace("/", os.sep))
         if os.path.isdir(abs_path):
             if depth == "0":
@@ -213,10 +213,10 @@ class Calendar(object):
                     # Directory does not exist yet
                     pass
         else:
-            calendar = cls(path)
             if depth == "0":
-                result.append(calendar)
+                result.append(cls(path))
             else:
+                calendar = cls(path, principal=True)
                 if include_container:
                     result.append(calendar)
                 result.extend(calendar.components)

+ 5 - 9
radicale/xmlutils.py

@@ -201,7 +201,7 @@ def _propfind_response(path, item, props, user):
     response = ET.Element(_tag("D", "response"))
 
     href = ET.Element(_tag("D", "href"))
-    href.text = item.url if is_calendar else "%s/%s" % (path, item.name)
+    href.text = (item.url if is_calendar else "%s/%s" % (path, item.name)).replace('//', '/')
     response.append(href)
 
     propstat404 = ET.Element(_tag("D", "propstat"))
@@ -221,12 +221,7 @@ def _propfind_response(path, item, props, user):
             element.text = item.etag
         elif tag == _tag("D", "principal-URL"):
             tag = ET.Element(_tag("D", "href"))
-            if item.owner_url:
-                tag.text = item.owner_url
-            elif user:
-                tag.text = '/%s/' % user
-            else:
-                tag.text = path
+            tag.text = path
             element.append(tag)
         elif tag in (
             _tag("D", "principal-collection-set"),
@@ -267,8 +262,9 @@ def _propfind_response(path, item, props, user):
                 if item.is_principal:
                     tag = ET.Element(_tag("D", "principal"))
                     element.append(tag)
-                tag = ET.Element(_tag("C", "calendar"))
-                element.append(tag)
+                else:
+                    tag = ET.Element(_tag("C", "calendar"))
+                    element.append(tag)
                 tag = ET.Element(_tag("D", "collection"))
                 element.append(tag)
             elif tag == _tag("D", "owner") and item.owner_url: