[imp] PATCH: IMP_ACL_rfc2086 - things I learnt yesterday!
Chris Hastie
lists at oak-wood.co.uk
Wed Feb 5 22:12:30 PST 2003
On Wed, 5 Feb 2003, Jan Schneider <jan at horde.org> wrote
>Zitat von Chris Hastie <lists at oak-wood.co.uk>:
>
>> 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-)
>
>I committed the patch to acl.php.
>
>Unfortunately you cleaned up the patch to rf2086.php a bit too much now. ;-)
>The gettext strings _need_ to have double quotes, as Eric clearly stated in
>his addition to CODING_STANDARDS.
>
I plan on turning my brain on later :(
Here we go again...
--
Chris Hastie
-------------- next part --------------
--- imp/lib/ACL/rfc2086.php,v 1.4
+++ imp/lib/ACL/rfc2086.php Wed Feb 5 22:06:55 2003
@@ -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