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.
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 开发者_如何学Pythonother 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).
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...
精彩评论