IMAP search by subject fails on punctuation characters on Gmail

jorgeathens

New Member
I am using the PHP IMAP libraray's \[code\]imap_search()\[/code\] function to search mails in a Gmail inbox via the subject string.\[code\]imap_seach($mbox, 'ALL SUBJECT "<search string>"');\[/code\]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).
 
Back
Top