Bug #64271 [Opn->Nab]: imap_search has a bug

From: Date: Sat, 29 Aug 2015 13:38:21 +0000
Subject: Bug #64271 [Opn->Nab]: imap_search has a bug
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195627@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64271&edit=1 ID: 64271 Updated by: cmb@php.net Reported by: rixsta at hotmail dot com Summary: imap_search has a bug -Status: Open +Status: Not a bug Type: Bug Package: IMAP related Operating System: Cent OS PHP Version: Irrelevant -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: > This function returns false if no messages were found. Indeed. And count(false) === 1. Previous Comments: ------------------------------------------------------------------------ [2013-02-24 15:50:54] inefedor at gmail dot com This function returns false if no messages were found. Yeah, it's a bit tricky, but you just need to do: $items = imap_search($imap_stream, 'UNSEEN'); $newCount = $items === false ? 0 : count($items); ------------------------------------------------------------------------ [2013-02-21 21:11:24] rixsta at hotmail dot com Description: ------------ --- From manual page: http://www.php.net/function.imap-search#refsect1- function.imap-search-description --- The following example should highlight this bug clearly: $newCount = count(imap_search($imap_stream, 'UNSEEN')); We use the function above to count the number of 'UNSEEN' messages in the mailbox folders. It works fine until we have read all messages and in this case we would expect the $newCount to be 0. However it remains at 1! We have been able to work around this bug with the following fix/function (see test script) This returns the count as we would expect. If you do address this bug we would appreciate a quick email and advise on the version of PHP it will be included in. Many thanks. Test script: --------------- $newCount = $this->count_unread_email($imap_stream); function count_unread_email($imap_stream) { $count = 0; if (!$imap_stream) { echo "Error"; } else { $headers = imap_headers($imap_stream); foreach ($headers as $mail) { $flags = substr($mail, 0, 4); $isunr = (strpos($flags, "U") !== false); if ($isunr) $count++; } } return $count; } Expected result: ---------------- We expect the function to return 0 when there are no remaining 'UNSEEN' messages, not 1. Actual result: -------------- We receive a 1 even though there are 0 'UNSEEN' messages remaining in our mailbox folder. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64271&edit=1

« previous php.bugs (#195627) next »