Doc #53361 [Fbk->Csd]: imap_search function (almost) always returns false
| From: | hm2k@php.net | Date: | Mon, 13 Dec 2010 14:11:01 +0000 |
| Subject: | Doc #53361 [Fbk->Csd]: imap_search function (almost) always returns false | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-5674@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53361&edit=1
ID: 53361
Updated by: hm2k@php.net
Reported by: hm2k@php.net
Summary: imap_search function (almost) always returns false
-Status: Feedback
+Status: Closed
Type: Documentation Problem
Package: IMAP related
Operating System: CentOS
PHP Version: 5.2.14
-Assigned To:
+Assigned To: hm2k
Block user comment: N
Private report: N
New Comment:
This bug has been superseded by bug #53375.
Previous Comments:
------------------------------------------------------------------------
[2010-11-19 23:05:44] hm2k@php.net
@frozenfire you have clearly understood. They are meant to by separate
calls, as a point of demonstration. Each of them fail individually.
Equally, they will fail together too.
ceo at l-i-e dot com: imap_last_error is called after each imap_search
call, so being overwritten isn't an issue.
I'm really seeking advise from experienced developers, but thanks for
your interest anyway.
------------------------------------------------------------------------
[2010-11-19 20:52:44] ceo at l-i-e dot com
Hard won experience:
You don't want just imap_last_error(). Internal imap calls will
overwrite that, as I recall...
Oh, and some things most of us would consider as "error" are classified
by IMAP as "alert"...
So you want more like:
var_dump(imap_errors($stream));
var_dump(imap_alerts($stream));
------------------------------------------------------------------------
[2010-11-19 20:00:59] frozenfire@php.net
Looking at your test script, it appears that you are sending each
segment of the imap_search command as a separate call.
The documentation clearly states that the "criteria" parameter is a
space-delimited set of filtering commands which are sent as a single
call.
I'm setting this bug to Feedback while you try modifying your script to,
instead of looping through $searches, implode it with space "glue".
An example would be: var_dump(imap_search($stream,implode(' ',
$searches)));
If you continue to have issues with it, respond with the result. I'd
rather not have to set up the extension on my system to test what seems
like a simple EBCAK ;).
------------------------------------------------------------------------
[2010-11-19 19:30:53] hm2k@php.net
Description:
------------
---
From manual page: http://www.php.net/function.imap-search
---
The imap_search() function almost always returns false with no hint or
indication as to why.
Test script:
---------------
<pre>
<?php
ini_set('display_errors','On');
error_reporting(E_ALL);
include 'settings.php';
//connect to mailbox
$stream=imap_open('{'.$host.'/imap/notls/norsh/novalidate-cert/readonly}INBOX',$user,$pass,OP_SILENT);
echo "imap_mailboxmsginfo\n";
var_dump(imap_mailboxmsginfo($stream));
echo "\n";
//searches
$searches=array();
$searches[]='ALL';
$searches[]='ANSWERED';
$searches[]='BCC "@"';
$searches[]='BEFORE 19-11-2010';
$searches[]='SINCE 1-1-1970';
$searches[]='SINCE 01-01-1970';
$searches[]='SINCE 01-Jan-1970';
$searches[]='SINCE "1-1-1970"';
$searches[]='SINCE "1-Jan-1970"';
$searches[]='SINCE "17-Jul-1996 02:44:25 -0700"';
$searches[]='SINCE "17 Nov 2008"';
foreach ($searches as $search) {
echo "imap_search $search\n";
var_dump(imap_search($stream,$search)); //bool(false)
if (imap_last_error()) { echo 'Error: '.imap_last_error()."\n"; }
echo "\n";
}
Expected result:
----------------
Returns an array of message numbers or UIDs.
Actual result:
--------------
imap_mailboxmsginfo
object(stdClass)#1 (8) {
["Unread"]=>
int(70)
["Deleted"]=>
int(0)
["Nmsgs"]=>
int(974)
["Size"]=>
int(19740065)
["Date"]=>
string(37) "Sat, 20 Nov 2010 02:50:34 +0000 (GMT)"
["Driver"]=>
string(4) "imap"
["Mailbox"]=>
string(96)
"{mail.example.com:143/imap/notls/novalidate-cert/readonly/user="email@example.com"}INBOX"
["Recent"]=>
int(0)
}
imap_search ALL
bool(false)
imap_search ANSWERED
bool(false)
imap_search BCC "@"
bool(false)
imap_search BEFORE 19-11-2010
bool(false)
Error: Unknown search criterion: BEFORE
imap_search SINCE 1-1-1970
bool(false)
Error: Unknown search criterion: SINCE
imap_search SINCE 01-01-1970
bool(false)
Error: Unknown search criterion: SINCE
imap_search SINCE 01-Jan-1970
bool(false)
Error: Unknown search criterion: SINCE
imap_search SINCE "1-1-1970"
bool(false)
Error: Unknown search criterion: SINCE
imap_search SINCE "1-Jan-1970"
bool(false)
Error: Unknown search criterion: SINCE
imap_search SINCE "17-Jul-1996 02:44:25 -0700"
bool(false)
Error: Unknown search criterion: SINCE
imap_search SINCE "17 Nov 2008"
bool(false)
Error: Unknown search criterion: SINCE
Notice: Unknown: Unknown search criterion: BEFORE (errflg=2) in Unknown
on line 0
Notice: Unknown: Unknown search criterion: SINCE (errflg=2) in Unknown
on line 0
Notice: Unknown: Unknown search criterion: SINCE (errflg=2) in Unknown
on line 0
Notice: Unknown: Unknown search criterion: SINCE (errflg=2) in Unknown
on line 0
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53361&edit=1