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

Bug #4264 foreach() called without argument check
Submitted: 2005-05-02 21:46 UTC
From: miker at life-captured dot com Assigned: richy
Status: Closed Package: Mail_IMAPv2
PHP Version: 5.0.3 OS: GNU/Linux
Roadmaps: (Not assigned)    
Subscription  


 [2005-05-02 21:46 UTC] miker at life-captured dot com
Description: ------------ PHP warnings WRT invalid arguments to foreach() are thrown when I access my mailbox using MailIMAPv2. Reproduce code: --------------- Line 1182 (in function _getDefaultPid) is as follows: foreach ($this->structure[$mid]['pid'] as $p => $id) { Expected result: ---------------- I've added if (is_array($this->structure[$mid]['pid'] { .. } around the aforementioned loop, and the warnings went away. Suggest inclusion in future releases of package. Actual result: -------------- I get numerous occurrences of the following (using my own error-logging method): Warning: Invalid argument supplied for foreach() in /usr/local/lib/php/Mail/IMAPv2.php on line 1182

Comments

 [2005-05-03 17:53 UTC] richy
Thanks for the bug report. I see the point of adding is_array(), but if $this->structure[$mid]['pid'] is not an array it's a sign of a larger problem. Can you tell me if there are anomolies in the message(s) being parsed that trigger this error? Do you get the expected output from that/those message(s)? Essentially, if $this->structure[$mid]['pid'] is not an array, there are no message parts, and message parsing has failed. I wouldn't expect a message with no parts. (no body, no attachments). That's why there is no check, it is essential to everything Mail_IMAP does that $this->structure[$mid]['pid'] be set an be an array. If you can reproduce the bug in a specific message, then send that message (in exactly the form you see it, not as an attachment to another message), to demo@smilingsouls.net. That is my live demo mailbox that houses unique messages that expose problems in Mail_IMAP's parsing algorithms, and also serves as quality assurance to test new releases of Mail_IMAP.
 [2005-05-03 17:55 UTC] richy
I will add some error reporting for this, BTW.
 [2005-05-03 18:16 UTC] miker at life-captured dot com
Message (w/ audio content) has generated by our system and sent to myself and demo@smilingsouls.net. Hope it contains helpful information. :)
 [2005-05-03 18:25 UTC] miker at life-captured dot com
Here's a dump of a partial context, as generated by my error handler. MailConnection is my own structure, encapsulating the Mail_IMAPv2 object (among other things). [MailConnection] => Mail_IMAPv2 Object ( [error] => PEAR_ErrorStack Object ( [_errors] => Array ( ) [_errorsByLevel] => Array ( ) [_package] => Mail_IMAPv2 [_compat] => [_msgCallback] => Array ( [0] => PEAR_ErrorStack Object *RECURSION* [1] => getErrorMessage ) [_contextCallback] => Array ( [0] => PEAR_ErrorStack Object *RECURSION* [1] => getFileLine ) [_errorCallback] => Array ( ) [_logger] => [_errorMsgs] => Array ( ) ) [mailbox] => Resource id #35 [mailboxInfo] => Array ( [Mail_IMAPv2] => Array ( [version] => Mail_IMAPv2 0.1.0 Beta ) [host] => {myhost.foobar.com:143/imap} [folder] => INBOX [user] => someuser@myhost.com ) [option] => Array ( [fetchbody] => 2 [body] => 2 ) [structure] => Array ( [1] => Array ( [pid] => 0 ) ) [msg] => Array ( ) [header] => Array ( ) [_dataTypes] => Array ( [0] => text [1] => multipart [2] => message [3] => application [4] => audio [5] => image [6] => video [7] => other ) [_encodingTypes] => Array ( [0] => 7bit [1] => 8bit [2] => binary [3] => base64 [4] => quoted-printable [5] => other ) [fields] => Array ( [0] => fname [1] => pid [2] => ftype [3] => fsize [4] => has_at [5] => charset [6] => cid ) )
 [2005-05-03 18:32 UTC] richy
Thanks, I don't see the message in the demo mailbox. http://www.smilingsouls.net/index.html?content=Mail_IMAP/live
 [2005-05-15 16:15 UTC] richy
I still do not have the test message. If you could try sending it again, that'd be grand. I'm adding an error for this for version 0.2.0.
 [2007-07-30 10:17 UTC] rotzbengel (Rotz Bengel)
Any news about this case? I still have this problem. Installed Versions: PHP 5.2.0 with Suhosin-Patch 0.9.6.1 (cli) Mail_IMAPv2, version 0.2.0