Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.1.4

Bug #2954 Incorrect parsing of MYRIGHTS response
Submitted: 2004-12-12 19:25 UTC
From: pear at mattoddie dot com Assigned: hudeldudel
Status: Closed Package: Net_IMAP
PHP Version: 4.3.9 OS: Debian Linux
Roadmaps: (Not assigned)    
Subscription  


 [2004-12-12 19:25 UTC] pear at mattoddie dot com
Description: ------------ I get the following error when accessing my IMAP account (running Courier IMAP 3.0.8 on Debian Linux) and selecting a mailbox: "2730,/usr/share/php/Net/IMAPProtocol.php,PROTOCOL ERROR!:must be a ' ' but is a ')' !!!!". I have tracked this down to the parsing of the MYRIGHTS response. The response my mail server gives is '* OK [MYRIGHTS "acdilrsw"] ACL', however the Net_IMAP seems to add a ')' to it, turning this into '* OK [MYRIGHTS "acdilrsw")] ACL'. I discovered this by putting some debugging information into the script, which said the $token for parsing this was '"acdilrsw")', and as a result gave the above error. Reproduce code: --------------- My mail server gives the following response to a "SELECT INBOX" command: * FLAGS (\Draft \Answered \Flagged \Deleted \Seen \Recent) * OK [PERMANENTFLAGS (\* \Draft \Answered \Flagged \Deleted \Seen)] Limited * 18 EXISTS * 0 RECENT * OK [UIDVALIDITY 1076619064] Ok * OK [MYRIGHTS "acdilrsw"] ACL a02 OK [READ-WRITE] Ok Expected result: ---------------- I guess it should just accept the response, and not return an error. Actual result: -------------- It returns the following error: 2730,/usr/share/php/Net/IMAPProtocol.php,PROTOCOL ERROR!:must be a ' ' but is a ')' !!!!

Comments

 [2005-02-06 03:24 UTC] mortonda at dgrmm dot net
I get the same error when issuing a login() request.
 [2005-02-13 17:48 UTC] pearIMAP at xaarr dot net
I has the same problem after courier-imap update. I has not found the real problem, but i have patched the file 'IMAPProtocol.php' for fix this one Problem for me. replace the lines 2452-2457 <code> if( ( $ret = $this->_retrParsedResponse( $str , $token ) ) != false ){ //$struct_arr[$token] = $ret; $struct_arr=array_merge($struct_arr, $ret); } $parenthesis=$token; </code> with this code: <code> #begin.bug-2954.quick&dirty.byDast.mailto:pearIMAP@xaarr.net if (defined("BUG_2954_courier_imap") && BUG_2954_courier_imap == true ) { if ( (strlen($str)>3) && (substr($str,1,1) == '"') && (substr($str,strlen($str)-((strlen($str)>0)?(1):(0)),1) == ')') ) { $str = str_replace('")','" ',$str); $parenthesis=")"; } else { $parenthesis=$token; } if( ( $ret = $this->_retrParsedResponse( $str , $token ) ) != false ){ //$struct_arr[$token] = $ret; $struct_arr=array_merge($struct_arr, $ret); } } else { #BUG_2954_courier_imap == false) => try orginal-code if( ( $ret = $this->_retrParsedResponse( $str , $token ) ) != false ){ //$struct_arr[$token] = $ret; $struct_arr=array_merge($struct_arr, $ret); } $parenthesis=$token; } #end.bug-2954.quick&dirty.byDast.mailto:pearIMAP@xaarr.net </code> ...then add this 2 lines after "require_once 'Net/Socket.php';" on line 20: <code> #Quick&Dirty-BUG-removing-after-courier-imap-update#Bug define("BUG_2954_courier_imap","true"); </code> thats it. you have a better patch ? write me! daniel.
 [2006-03-22 05:02 UTC] amistry at php dot net (Anish Mistry)
damian is no longer active. I'm going take a look at this once I get time. If you happen to have any patch updates please post them. Thank you.
 [2006-09-18 14:20 UTC] camilo at dyres dot com (Camilo Rodríguez T.)
There are 2 possible MYRIGHTS response syntaxes: MYRIGHTS <mailbox> "<permissions>" MYRIGHTS "permissions" The second syntax is not a standard MYRIGHTS response, but it is a response pipelined within the SELECT response in order to increase the protocol's efficiency. The class just fails to properly parse this second possibility and assumes it is a protocol error. I patched the IMAPProtocol.php so that it is able to recognize both of the response syntaxes like this: Original code (starting at line 2727 of IMAPProtocol.php file): <code> case "MYRIGHTS" : $this->_parseSpace( $str , __LINE__ , __FILE__ ); $this->_getNextToken( $str ,$mailbox ); $this->_parseSpace( $str , __LINE__ , __FILE__ ); $this->_getNextToken( $str , $granted ); $result_array = array( "MAILBOX"=>$this->utf_7_decode($mailbox) , "GRANTED"=>$granted ); return $result_array; break; </code> Modified code (starting at line 2727 of IMAPProtocol.php file):: <code> case "MYRIGHTS" : $this->_parseSpace( $str , __LINE__ , __FILE__ ); $this->_getNextToken( $str ,$mailbox ); // GFE Colombia // Camilo A. Rodríguez T. - 2006-09-18 08:53 // Change made to accept alternate MYRIGHTS response syntax. if ($str == ')') { $granted = $mailbox; $mailbox = $this->currentMailbox; } else { $this->_parseSpace( $str , __LINE__ , __FILE__ ); $this->_getNextToken( $str , $granted ); } // FINAL Camilo A. Rodríguez T. - 2006-09-18 08:53 $result_array = array( "MAILBOX"=>$this->utf_7_decode($mailbox) , "GRANTED"=>$granted ); return $result_array; break; </code> As you can see, what i've done is to assume that if after I parse the first argument in the MYRIGHTS response the rest of the string is a ')', then the whole MYRIGHTS response was using the short syntax and that the first and only argument in the response were actually the current mailbox rights. Hope this works for you!
 [2006-12-07 01:39 UTC] amistry at php dot net (Anish Mistry)
Fixed in CVS. Please verify.
 [2007-01-06 13:46 UTC] hudeldudel at php dot net (Sebastian Ebling)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. I've tested with a courier-imap box last night which had the same MYRIGHTS response and the fix in CVS works. There have been some simmilar errors when parsing QUOTA response which should now be fixed with latest CVS, too.