imap_search()未知搜索条件"OR"; [英] imap_search() unknown search criterion "OR"

查看:219
本文介绍了imap_search()未知搜索条件"OR";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试构建IMAP搜索查询以通过php代码过滤掉特定的邮件...导致必须使用"OR"搜索条件的情况.

 <?php$ search_string ='或(主题"FedEx"主题"USPS")';$ search_string ='或主题"FedEx"主题"USPS"';$ search_string ='SUBJECT"FedEx"或SUBJECT"USPS"';$ search_string ='或(主题"FedEx")或(主题"USPS")';$ search_string ='OR(主题"FedEx")(主题"USPS")';//所有单独使用的搜索字符串均无效$ emails = imap_search($ inbox,$ search_string);?> 

但是在使用时,php会引发错误 PHP注意:未知:未知搜索条件:在第0行的未知"中为OR(errflg = 2)

在引用 IMAP的php文档时,它表示文档可能不准确,并且指向 RFC 2060 ,因此,当您在第6.4.4节中搜索命令时,它提到可以使用OR,NOT和少量额外的搜索条件...

因此在前缀位置,中缀位置使用了它,并按照RFC 2060的建议尝试使用括号,但都没有用

还遇到了 php错误条目,但不确定这是否是错误或需要以其他方式使用!

有人知道解决方案/解决方法吗?

我不希望遍历每封邮件并检查代码是否满足条件...我希望通过IMAP搜索来实现


编辑/更新:

imap_search函数与IMAP4不完全兼容.从现在开始使用的c客户端仅支持IMAP2,并且某些搜索条件(例如"OR")将不可用

因此php代码类似于:

  $ inbox = imap_open('{imap.example.com:993/imap/ssl}INBOX','foo@example.com','pass123',OP_READONLY);$ search_string ='SUBJECT"FedEx"或SUBJECT"USPS"';$ emails = imap_search($ inbox,$ search_string); 

将抛出一个错误消息,提示未知搜索条件"

观察和参考:
git repo: https://github.com/php/php-src

PHP源跟踪:(ref: https://github.com/php/php-src/blob/master/ext/imap/php_imap.c )
/ext/imap/php_imap.c->行号:4126
imap_search =>行号:4148

c客户端库源跟踪:
src/c-client/mail.c->行号:3973

/docs/internal.txt->行号:1919 => mail_criteria()
条件IMAP2格式的搜索条件字符串
警告:此功能不接受IMAP4搜索条件.

IMAP2 RFC1064 => [ref: https://tools.ietf.org/html/rfc1064 ] [页面:13]
IMAP4 RFC2060 => [ref: http://www.faqs.org/rfcs/rfc2060.html ] [节:6.4.4]

注意:核心模块(IMAP)中的核心搜索功能在PHP中仍然不可用.希望这会引起开发人员社区的注意...

但是我不确定哪个PHP版本使用IMAP4兼容的c客户端...

  1. 有没有一种方法可以强制php更新/使用最新的c-client图书馆?
  2. 还是最新的(截至2016年4月11日)c客户端仅支持IMAP2?
  3. 我们应该修改库源代码并编译并安装吗?
  4. 或者还有第三方开发的其他任何PHP库,我们可以用来完成相同的操作(imap协议邮件搜索,检索那些不支持OAuth2的邮件提供商?

解决方案

我通过做几个imap_search句子来模拟"OR"来解决了这个问题.

  $ criteria ='从"someaddr@gmail.com"中脱机|从"@ onedomain.com"中脱机|从"@ anotherdomain.org"中脱机$ criterias = explode('|',$ criteria);$ emails = array();foreach($ criterias as $ search){$ emails_ = imap_search($ inbox,$ search);如果($ emails_)$ emails = array_merge($ emails,$ emails_);}$ emails = array_unique($ emails); 

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', 'foo@example.com', '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...

  1. Is there a way to force php to just update/use the latest c-client library?
  2. Or the current latest(as of 11Apr 2016) c-client supports only IMAP2?
  3. Should we modify the library source code and compile and install?
  4. 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)?

解决方案

I solved this doing several imap_search sentences to simulate "OR".

$criteria = 'UNSEEN FROM "someaddr@gmail.com"|UNSEEN FROM "@onedomain.com"|UNSEEN FROM "@anotherdomain.org"'
$criterias = explode('|', $criteria);
$emails = array();
foreach ($criterias as $search) {
    $emails_ = imap_search($inbox, $search);
    if ($emails_)
        $emails = array_merge($emails, $emails_);
}
$emails = array_unique($emails);

这篇关于imap_search()未知搜索条件"OR";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆