简体   繁体   English

按主题进行的IMAP搜索在Gmail上的标点符号上失败

[英]IMAP search by subject fails on punctuation characters on Gmail

I am using the PHP IMAP libraray's imap_search() function to search mails in a Gmail inbox via the subject string. 我正在使用PHP IMAP libraray的imap_search()函数通过主题字符串搜索Gmail收件箱中的邮件。

imap_seach($mbox, 'ALL SUBJECT "<search string>"');

This search returns perfectly fine for alphanumeric strings but fails when it has special characters like slash, comma, colon, single quote, hyphen, and many other characters that I do not even know of. 对于字母数字字符串,此搜索返回完全正常,但是当它具有特殊字符(如斜杠,逗号,冒号,单引号,连字符和许多其他我不知道的字符)时会失败。 Escaping them doesn't help. 逃避他们并没有帮助。 Replacing a few of them with space helps sometime but not in all cases. 用空间替换它们中的一些有时会有所帮助,但并非在所有情况下。

Is there a standard way to filter the search string so that it never errors out and returns some result? 是否有一种标准的方法来过滤搜索字符串,以便它永远不会出错并返回一些结果? I have tried tokenizing the subject sting and removing all words from the search string which even one alphanumeric characters. 我尝试过标记主题sting并从搜索字符串中删除所有单词,甚至是一个字母数字字符。 This mostly works but fails when all the words have non-alphanumeric character (which is common for single or two word subject). 这主要起作用,但是当所有单词都具有非字母数字字符时(这对于单个或两个单词主题是常见的)则失败。

I'm guessing that GMail search goes by the idea that only whole alphanumeric words can be used as search strings.. 我猜测GMail搜索认为只有整个字母数字字才能用作搜索字符串。

Therefore you'd have to remove all non-alphanumerics from your search string, and it will work... 因此,您必须从搜索字符串中删除所有非字母数字,它才能正常工作......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM