

Imap_search () unknown search criteria & ldquo; OR & rdquo;
source link: https://www.codesd.com/item/imap-search-unknown-search-criteria-or.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Imap_search () unknown search criteria & ldquo; OR & rdquo;
Trying to build a IMAP Search query to filter out specific mails via php code... Pushed into a situation where I must use the "OR" search criteria.
<?php
$search_string = 'OR (SUBJECT "FedEx" SUBJECT "USPS")';
$search_string = 'OR SUBJECT "FedEx" SUBJECT "USPS"';
$search_string = 'SUBJECT "FedEx" OR SUBJECT "USPS"';
$search_string = 'OR (SUBJECT "FedEx") OR (SUBJECT "USPS")';
$search_string = 'OR (SUBJECT "FedEx") (SUBJECT "USPS")';
//all of the search strings when used separately didn't work
$emails = imap_search($inbox, $search_string);
?>
But when used, php throws the error PHP Notice: Unknown: Unknown search criterion: OR (errflg=2) in Unknown on line 0
When referred php docs for IMAP it says the documentation might be inaccurate and directed to RFC 2060 so When referring section 6.4.4 for search command, it mentions that we can use OR, NOT and few extra search criteria...
so used it in prefix position, infix position and tried using parenthesis as suggested in RFC 2060 but all in vain
Also Came across the php bug entry but not sure if this is a bug or it needs to be used in some other way!
Anybody with solutions / workarounds?
I would hate to iterate over every mail and check in code if it satisfies the condition... I'd like that to be accomplished via IMAP search
Edit/Updates:
imap_search function is not fully compatible with IMAP4. the c-client used as of now supports only IMAP2 and some search criterion will not be available for use such as "OR"
So a php code similar to:
$inbox = imap_open('{imap.example.com:993/imap/ssl}INBOX', '[email protected]', 'pass123', OP_READONLY);
$search_string = 'SUBJECT "FedEx" OR SUBJECT "USPS"';
$emails = imap_search($inbox, $search_string);
will throw an error saying "Unknown search criterion"
observations and reference:
git repo : https://github.com/php/php-src
PHP source trace:( ref: https://github.com/php/php-src/blob/master/ext/imap/php_imap.c )
/ext/imap/php_imap.c -> line no : 4126
imap_search => line no : 4148
c-client library source trace:
src/c-client/mail.c -> line no : 3973
/docs/internal.txt -> line no : 1919 => mail_criteria()
criteria IMAP2-format search criteria string
WARNING: This function does not accept IMAP4 search criteria.
IMAP2 RFC1064 => [ ref: https://tools.ietf.org/html/rfc1064 ] [page: 13]
IMAP4 RFC2060 => [ ref: http://www.faqs.org/rfcs/rfc2060.html ] [section: 6.4.4]
Note: The core search functionality in a core module(IMAP) is still not available in PHP. Hope this will be brought to the developer community's attention...
But I'm not sure about which PHP version uses the IMAP4 compatible c-client...
- Is there a way to force php to just update/use the latest c-client library?
- Or the current latest(as of 11Apr 2016) c-client supports only IMAP2?
- Should we modify the library source code and compile and install?
- Or Is there any other PHP libraries developed by 3rd parties that we can use to accomplish the same(imap protocol mail search, retrieve for those mail providers who doesn't support OAuth2)?
Did you try this.?
$inbox = imap_open('{imap.example.com:993/imap/ssl}INBOX', '[email protected]', 'pass123', OP_READONLY);
$search_string = 'SINCE "08-Mar-2011" OR SUBJECT "FedEx" OR SUBJECT "USPS"';
$emails = imap_search($inbox, $search_string);
Recommend
-
17
Magento: & ldquo; Image does not exist & rdquo; advertisements I'm importing a CSV file in Magento (version 1.9). I receive...
-
12
& ldquo; azure & rdquo; not recognized in Azece powershell advertisements For the first time I'm trying out Azure Powershell. I'm sele...
-
10
How to use & ldquo; Consistency & rdquo; Java api parameter when setting elastic search data advertisements I have used "consistency"...
-
5
Javascript & ldquo; Private & rdquo; Vs properties of the instance advertisements I'm doing some Javascript R&D and,...
-
10
C # & ldquo; Undefined method & rdquo; When adding a new method to a simulated interface advertisements I am curren...
-
4
Labeling & ldquo; to-do & rdquo; s and colorful text in Markdown advertisements I'm using the GitHub flavoured Mark...
-
5
Is & ldquo; Dollar-sign & rdquo; Optional in powershell & ldquo; $ () & Rdquo; advertisements I've seen an...
-
13
Is a & ldquo; for & rdquo; Is the loop necessary if the elements of the vector numpy depend on the previous element? advertisements
-
6
Unexpected result of & ldquo; F \ t \ b \ bg \ n & rdquo; In Visual C ++ advertisements I wrote a one line program in Vi...
-
4
Disable & ldquo; Save image & rdquo; In the iOS Web application advertisements I want to disable the "s...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK