Move the getOwner() method into the namespace handler.
authorGunnar Wrobel <p@rdus.de>
Thu, 11 Mar 2010 21:22:22 +0000 (22:22 +0100)
committerGunnar Wrobel <wrobel@temple.(none)>
Thu, 11 Mar 2010 21:35:06 +0000 (22:35 +0100)
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Namespace.php

index bfea567..a35ac90 100644 (file)
@@ -484,25 +484,9 @@ class Horde_Kolab_Storage_Folder
     {
         if (!isset($this->_owner)) {
             if (!isset($this->name) && isset($this->new_name)) {
-                $name = $this->new_name;
+                $this->_owner = $this->_namespace->getOwner($this->new_name);
             } else {
-                $name = $this->name;
-            }
-
-            if (!preg_match(";(shared\.|INBOX[/]?|user/([^/]+)[/]?)([^@]*)(@.*)?;", $name, $matches)) {
-                return PEAR::raiseError(sprintf(_("Owner of folder %s cannot be determined."), $name));
-            }
-
-            $this->_subpath = $matches[3];
-
-            if (substr($matches[1], 0, 6) == 'INBOX/') {
-                $this->_owner = Horde_Auth::getAuth();
-            } elseif (substr($matches[1], 0, 5) == 'user/') {
-                $domain = strstr(Horde_Auth::getAuth(), '@');
-                $user_domain = isset($matches[4]) ? $matches[4] : $domain;
-                $this->_owner = $matches[2] . $user_domain;
-            } elseif ($matches[1] == 'shared.') {
-                $this->_owner =  'anonymous';
+                $this->_owner = $this->_namespace->getOwner($this->name);
             }
         }
         return $this->_owner;
index 0401a23..c0cf2a9 100644 (file)
@@ -34,6 +34,8 @@ class Horde_Kolab_Storage_Namespace
      * Return the title of a folder.
      *
      * @param string $name The name of the folder.
+     *
+     * @return sring The title of the folder.
      */
     public function getTitle($name)
     {
@@ -43,4 +45,30 @@ class Horde_Kolab_Storage_Namespace
         $name = str_replace('/', ':', $name);
         return Horde_String::convertCharset($name, 'UTF7-IMAP');
     }
+
+    /**
+     * Return the owner of a folder.
+     *
+     * @param string $name The name of the folder.
+     *
+     * @return string The owner of the folder.
+     */
+    public function getOwner($name)
+    {
+        if (!preg_match(";(shared\.|INBOX[/]?|user/([^/]+)[/]?)([^@]*)(@.*)?;", $name, $matches)) {
+            throw new Horde_Kolab_Storage_Exception(
+                'Owner of folder %s cannot be determined.', $name
+            );
+        }
+
+        if (substr($matches[1], 0, 6) == 'INBOX/') {
+            return Horde_Auth::getAuth();
+        } elseif (substr($matches[1], 0, 5) == 'user/') {
+            $domain = strstr(Horde_Auth::getAuth(), '@');
+            $user_domain = isset($matches[4]) ? $matches[4] : $domain;
+            return $matches[2] . $user_domain;
+        } elseif ($matches[1] == 'shared.') {
+            return  'anonymous';
+        }
+    }
 }
\ No newline at end of file