Search code examples
office365imap

Outlook IMAP search not returning correct value with BODY search criteria


We've been using Chilkat to access emails from outlook accounts and recently we noticed that the search function started failing, I think it started about less than a week ago.

we are connecting to "office365.outlook.com" and using Subject and Body as search criteria to get the emails.

Sample search criteria:

SUBJECT "Hot Lead (New) - Test Cahestg 92J6cf6n Hot Email" BODY "QA Automation"

When it started failing, I did some more investigation and noticed that SUBJECT "Hot Lead (New) - Test Cahestg 92J6cf6n Hot Email" actually works but adding the BODY field causes it to fail.

I did print out the .body of the email object returned and it does have the string "QA Automation" in it so I was wondering why outlook did not return the same email with the search criteria with BODY.

Anyone else have this issue or know of another search field we can use instead of BODY?


Solution

  • IMAP doesn't specify what the BODY search key does, exactly. The server is free to know as little or as much as it wants about body formats.

    So, if your message uses HTML, to take a common example, and contains the HTML string QA Auto­mation, the server may or may not know that ­ can be ignored and that   is sort of equivalent to a simple space, at least for searching. Similar issues arise for other formats, it's not just HTML. PDF is horrible, even plain text isn't trivial.

    As a programming issue, this doesn't really have a solution, except maybe issuing OR BODY QA BODY Automation and then doing client-side filtering of the results.