[imp] PATCH: IMP_ACL_rfc2086 - things I learnt yesterday!

Chris Hastie lists at oak-wood.co.uk
Wed Feb 5 19:59:00 PST 2003


On Wed, 5 Feb 2003, Jan Schneider <jan at horde.org> wrote
>Zitat von Chris Hastie <lists at oak-wood.co.uk>:
>
>> *   Warnings include more detailed information about what the problem
>>     was. Hopefully this will make further debugging easier.
>
>Great, but please replace double with single quotes where possible (see
>Eric's addition to CODING_STANDARDS).
>

OK, here's my revised patch, cleaned up a bit and at the moment against 
what's in HEAD currently 8-)
-- 
Chris Hastie
-------------- next part --------------
--- imp/acl.php,v 1.4
+++ imp/acl.php	Wed Feb  5 09:45:04 2003
@@ -64,7 +64,7 @@
 
     if ($ok_form) {
         $result = $ACLDriver->createACL($folder, $share_user, $acl);
-        if ($result == 'no_support') {
+        if ($result === 'no_support') {
             header('Location: ' . Horde::applicationUrl('prefs.php', true));
             exit;
         }
@@ -87,7 +87,7 @@
 
     if ($ok_form) {
         $result = $ACLDriver->editACL($folder, $share_user, $acl);
-        if ($result == 'no_support') {
+        if ($result === 'no_support') {
             header('Location: ' . Horde::applicationUrl('prefs.php', true));
             exit;
         }
-------------- next part --------------
--- imp/lib/ACL/rfc2086.php,v 1.4
+++ imp/lib/ACL/rfc2086.php	Wed Feb  5 19:50:29 2003
@@ -52,15 +52,15 @@
         $this->_protected = array($_SESSION['imp']['user']);
 
         $this->_rightsList = array(
-             'l' => _("List - user can see the folder"),
-             'r' => _("Read messages"),
-             's' => _("Mark with Seen/Unseen flags"),
-             'w' => _("Mark with other flags (e.g. Important/Answered)"),
-             'i' => _("Insert messages"),
-             'p' => _("Post to this folder (not enforced by IMAP)"),
-             'c' => _("Create sub folders"),
-             'd' => _("Delete and purge messages"),
-             'a' => _("Administer - set permissions for other users")
+             'l' => _('List - user can see the folder'),
+             'r' => _('Read messages'),
+             's' => _('Mark with Seen/Unseen flags'),
+             'w' => _('Mark with other flags (e.g. Important/Answered)'),
+             'i' => _('Insert messages'),
+             'p' => _('Post to this folder (not enforced by IMAP)'),
+             'c' => _('Create sub folders'),
+             'd' => _('Delete and purge messages'),
+             'a' => _('Administer - set permissions for other users')
         );
     }
 
@@ -96,15 +96,15 @@
             $errors = @imap_errors();
             foreach ($errors as $err) {
                 if ($err == 'ACL not available on this IMAP server') {
-                    $err = _("This IMAP server does not support sharing folders.");
+                    $err = _('This IMAP server does not support sharing folders.');
                     $result = 'no_support';
                 }
                 $notification->push($err, 'horde.error');
             }
         } elseif (strlen($acl_str) < 1) {
-            $notification->push(_("All rights on folder ") . "'" . $folder . "'" . _(" successfully removed for user ") . "'" . $share_user . "'", 'horde.success');
+            $notification->push(_('All rights on folder ') . "'" . $folder . "'" . _(' successfully removed for user ') . "'" . $share_user . "'", 'horde.success');
         } else {
-            $notification->push(_("User") . " '" . $share_user . "' " . _("successfully given the following rights for the folder ") . "'" . $folder . "': " . $acl_str, 'horde.success');
+            $notification->push(_('User') . " '" . $share_user . "' " . _('successfully given the following rights for the folder ') . "'" . $folder . "': " . $acl_str, 'horde.success');
         }
 
         return $result;
@@ -151,11 +151,12 @@
 
         $server = $_SESSION['imp']['server'];
 
-        if ($sub_proto == "ssl") {
+        if ($sub_proto == 'ssl') {
             if (version_compare(phpversion(), '4.3.0') >= 0) {
                 $server = $sub_proto . '://' . $server;
             } else {
-                $notification->push(_("Could not retrieve server's capabilities"), 'horde.warning');
+                 $notification->push(_('Could not retrieve server\'s capabilities')
+                    . ' - ' . _('SSL connections require PHP 4.3 or better'), 'horde.warning');
                 return null;
             }
         }
@@ -163,15 +164,16 @@
         $imap = fsockopen($server, $_SESSION['imp']['port'], $errno, $errstr, 30);
 
         if (!$imap) {
-            $notification->push(_("Could not retrieve server's capabilities"), 'horde.warning');
+            $notification->push(_('Could not retrieve server\'s capabilities') 
+                . ' - ' . _('Connection failed: ') . $errno . ' : ' . $errstr, 'horde.warning');
             return null;
         } else {
             $response = fgets($imap, 4096);
-            if (preg_match("/^\*\sOK/", $response)) {
+            if (preg_match('/^\*\sOK/', $response)) {
                 fputs($imap, "x CAPABILITY\r\n");
-                $response = trim(fgets ($imap, 1024));
-                if (preg_match("/^\*\sCAPABILITY/", $response)) {
-                    $response_array = explode(" ", $response);
+                $response = trim(fgets($imap, 1024));
+                if (preg_match('/^\*\sCAPABILITY/', $response)) {
+                    $response_array = explode(' ', $response);
                     foreach ($response_array as $var) {
                         if (strstr($var, '=')) {
                             $var2 = explode('=', $var, 2);
@@ -182,10 +184,12 @@
                     }
 
                 } else {
-                    $notification->push(_("Could not retrieve server's capabilities"), 'horde.warning');
+                    $notification->push(_('Could not retrieve server\'s capabilities')
+                        . ' - ' . _('Unexpected response from server to: ') . '\'x CAPABILITY\' : ' . $response, 'horde.warning');
                 }
             } else {
-                $notification->push(_("Could not retrieve server's capabilities"), 'horde.warning');
+                $notification->push(_('Could not retrieve server\'s capabilities')
+                    . ' - ' . _('Unexpected response from server on connection: ') . $response, 'horde.warning');
             }
             fclose ($imap);
         }
@@ -270,32 +274,34 @@
             if (version_compare(phpversion(), '4.3.0') >= 0) {
                 $server = $sub_proto . '://' . $server;
             } else {
-                $notification->push(_("Could not retrieve ACL"), 'horde.warning');
+                $notification->push(_('Could not retrieve ACL') 
+                    . ' - ' . _('SSL connections require PHP 4.3 or better'), 'horde.warning');
                 return null;
             }
         }
 
         // Quote the folder string if it contains non alpha-numeric
         // characters
-        if (preg_match("/\W/",$folder)) {
+        if (preg_match('/\W/',$folder)) {
             $folder = '"' . $folder . '"';
         }
 
         $imap = fsockopen($server, $_SESSION['imp']['port'], $errno, $errstr, 30);
 
         if (!$imap) {
-            $notification->push(_("Could not retrieve ACL"), 'horde.warning');
+            $notification->push(_('Could not retrieve ACL')
+                . ' - ' . _('Connection failed: ') . $errno.' : ' . $errstr, 'horde.warning');
             return null;
         } else {
             $response = fgets($imap, 4096);
-            if (preg_match("/^\*\sOK/", $response)) {
+            if (preg_match('/^\*\sOK/', $response)) {
 
                 // login using the preferred mechanism
                 // default to login if Auth_SASL is not installed
                 if (($authMech == 'cram-md5') && $have_sasl) {
                     $login = Auth_SASL::factory('crammd5');
 
-                    fputs ($imap, "$txid AUTHENTICATE CRAM-MD5\r\n");
+                    fputs($imap, "$txid AUTHENTICATE CRAM-MD5\r\n");
                     $challenge = explode(' ', trim(fgets ($imap, 1024)));
 
                     $response = $login->getResponse($_SESSION['imp']['user'], $pass, base64_decode($challenge[1]));
@@ -304,31 +310,37 @@
                 } elseif(($authMech == 'digest-md5') && $have_sasl) {
                     $login = Auth_SASL::factory('digestmd5');
 
-                    fputs ($imap, "$txid AUTHENTICATE DIGEST-MD5\r\n");
+                    fputs($imap, "$txid AUTHENTICATE DIGEST-MD5\r\n");
                     $challenge = explode(' ', trim(fgets($imap, 1024)));
 
                     $response = $login->getResponse($_SESSION['imp']['user'], $pass, base64_decode($challenge[1]),
                         $_SESSION['imp']['server'], $_SESSION['imp']['base_protocol']);
 
                     fputs($imap, base64_encode($response) . "\r\n");
-                    $response = explode (" ", trim(fgets ($imap,1024)));
+                    $response = explode(' ', trim(fgets ($imap,1024)));
                     $response = base64_decode($response[1]);
-                    if (!preg_match("/rspauth=/", $response)) {
-                        $notification->push(_("Could not retrieve ACL"), 'horde.warning');
+                    if (!preg_match('/rspauth=/', $response)) {
+                        $notification->push(_('Could not retrieve ACL')
+                            . ' - ' . _('Unexpected response from server to: ') . 'Digest-MD5 response', 'horde.warning');
+
                         return null;
                     }
                     fputs($imap, "\r\n");
 
                 } else {
-                    fputs ($imap, "$txid LOGIN " . $_SESSION['imp']['user'] . " " . $pass . "\r\n");
+                    if (preg_match('/\W/', $pass)) {
+                        $pass = addslashes($pass);
+                        $pass = '"' . $pass . '"';
+                    }
+                    fputs($imap, "$txid LOGIN " . $_SESSION['imp']['user'] . ' ' . $pass . "\r\n");
 
                 }
-                $response = trim(fgets ($imap,1024));
+                $response = trim(fgets($imap, 1024));
                 if (preg_match("/^$txid\sOK/", $response)) {
                     $txid++;
-                    fputs ($imap, "$txid GETACL " . $folder . "\r\n");
+                    fputs($imap, "$txid GETACL " . $folder . "\r\n");
                     $response = trim(fgets($imap, 4096));
-                    if (preg_match("/^\*\s+ACL\s+(.*)/i", $response, $matches)) {
+                    if (preg_match('/^\*\s+ACL\s+(.*)/i', $response, $matches)) {
                         $res_arr = $this->_atomise($matches[1]);
                         $res_folder = array_shift($res_arr);
                         $is_key = 1;
@@ -346,13 +358,19 @@
                             }
                         }
                     } else {
-                        $notification->push(_("Could not retrieve ACL"), 'horde.warning');
+                        $notification->push(_('Could not retrieve ACL') 
+                            . ' - ' . _('Unexpected response from server to: ') . "'$txid GETACL' : " .$response, 'horde.warning');
+
                     }
                 } else {
-                    $notification->push(_("Could not retrieve ACL"), 'horde.warning');
+                    $notification->push(_('Could not retrieve ACL') 
+                        . ' - ' . _('Unexpected response from server to: ') . 'login : ' . $response, 'horde.warning');
+
                 }
             } else {
-                $notification->push(_("Could not retrieve ACL"), 'horde.warning');
+                $notification->push(_('Could not retrieve ACL') 
+                    . ' - ' . _('Unexpected response from server on connection: ') . $response, 'horde.warning');
+
             }
             fclose($imap);
         }
@@ -369,17 +387,11 @@
      *
      * @returns boolean  True if $user has 'a' right or $acl is empty
      */
-    function canEdit($acl, $user)
-    {
-        /* Possible for getACL to fail but createACL still to work
-           (eg ssl, PHP <4.3), so return true if $acl is empty */
-        if (empty($acl)) {
-            return true;
-        } elseif (array_key_exists('a', $acl[$user]) && $acl[$user]['a'] > 0) {
-            return true;
-        } else {
-            return false;
-        }
+    function canEdit($acl, $user) {
+        /* We can't establish if the user is in a group with the
+           'a' privilege, so just return true and leave the decision
+           to the server */
+        return true;
     }
 
     /**
@@ -402,7 +414,7 @@
                 $qt = true;
                 $idx ++;
                 continue;
-            } elseif ($char == " " && !$qt) {
+            } elseif ($char == ' ' && !$qt) {
                 $idx ++;
             } elseif ($char == '"' && $qt) {
                 $qt = false;


More information about the imp mailing list