Gmail 上的标点字符按主题进行 IMAP 搜索失败
我正在使用 PHP IMAP 库的 imap_search()
函数通过主题字符串搜索 Gmail 收件箱中的邮件。
imap_seach($mbox, 'ALL SUBJECT "<search string>"');
此搜索对于字母数字字符串返回完美,但当它包含特殊字符(如斜杠、逗号、冒号、单引号、连字符和许多我什至不知道的其他字符)时会失败。逃避他们并没有帮助。用空格替换其中一些有时会有所帮助,但并非在所有情况下都如此。
是否有一种标准方法来过滤搜索字符串,以便它永远不会出错并返回一些结果?我尝试过标记主题刺痛并从搜索字符串中删除所有单词,甚至包括一个字母数字字符。这通常有效,但当所有单词都具有非字母数字字符时(这对于单个或两个单词主题来说很常见),则会失败。
I am using the PHP IMAP libraray's imap_search()
function to search mails in a Gmail inbox via the subject string.
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. This mostly works but fails when all the words have non-alphanumeric character (which is common for single or two word subject).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜测 GMail 搜索的想法是,只有整个字母数字单词可以用作搜索字符串。
因此,您必须从搜索字符串中删除所有非字母数字,并且它将起作用...
I'm guessing that GMail search goes by the idea that only whole alphanumeric words can be used as search strings..
Therefore you'd have to remove all non-alphanumerics from your search string, and it will work...