php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #73640 imap_search can't search HEADER
Submitted: 2016-12-02 08:51 UTC Modified: 2020-10-08 14:49 UTC
Votes:11
Avg. Score:4.7 ± 0.6
Reproduced:10 of 10 (100.0%)
Same Version:5 (50.0%)
Same OS:3 (30.0%)
From: sistemisti-posta at csi dot it Assigned: cmb (profile)
Status: Closed Package: IMAP related
PHP Version: 7.0.13 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sistemisti-posta at csi dot it
New email:
PHP Version: OS:

 

 [2016-12-02 08:51 UTC] sistemisti-posta at csi dot it
Description:
------------
imap_search can't search all headers released by IMAP protocol (RFC 3501).
See at https://tools.ietf.org/html/rfc3501#section-6.4.4
You can perform the following command:

  HEADER <field-name> <string>

But this option is not allowed from PHP imap_search.

Expected result:
----------------
Something like:

$string = sprintf('HEADER "%s" "%s"','Message-ID', 'dskljflsdjfskl@example.org');
imap_search($imapconn, $string, SE_UID);

This should return the uid of message with the Message-ID found.

Actual result:
--------------
At the moment, to search an header I can use this workaround:

$string = sprintf('%s "Message-ID: <%s>"','TEXT', 'dskljflsdjfskl@example.org');
imap_search($imapconn, $string, SE_UID);

But it's not safe, because with TEXT I find all occurrences of string

  "Message-ID: <dskljflsdjfskl@example.org>"

in headers or body too.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-02 09:12 UTC] sistemisti-posta at csi dot it
Ps: the current error returned with

$string = sprintf('%s %s "%s"','HEADER', 'Message-ID', 'kldjskljf@example.org');
imap_search($imapconn, $string, SE_UID);

is

 PHP Notice:  Unknown: Unknown search criterion: HEADER (errflg=2) in Unknown
 [2020-10-08 14:49 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2020-10-08 14:49 UTC] cmb@php.net
> imap_search can't search all headers released by IMAP protocol
> (RFC 3501).

That is correct, because imap is built on top of libc-client,
which still only supports IMAP2-format search criteria.  Thus,
changing to doc problem.
 [2020-10-08 14:54 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=bab0d03aac3a3e6e0d18b8132ddc97d276ce3941
Log: Fix #73640: imap_search can't search HEADER
 [2020-10-08 14:54 UTC] phpdocbot@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 10:01:33 2025 UTC