Archived Forum Post

Index of archived forum posts

Question:

IMAP Searching Office365

Jan 09 '15 at 06:43

Hi Guys,

I'm trying to put together some code that scans users Sent Mail folders looking for emails with a set of tag text (e.g. [TAG: ) that have been filed after 1st January 2015, but the Chilkat component seems to be having problems.

The search query that I'm passing to Chilkat's Search method is: AND (SINCE 01-Jan-2015) (BODY "[TAG:")

The results seem to be very unreliable with Office365 refusing to return anything (even though I know that there are matching emails) but GMail working fine. I'm assuming that this will be down to something like Microsoft's implementation of the IMAP search standards but wondered if anyone could see if it's something that I'm doing that's wrong


Answer

One thing to realize about the Imap.Search method is that the search string your app passed to it is sent unmodified to the IMAP server. Therefore, the format of the search criteria is defined by the IMAP specification (RFC 3501 at http://tools.ietf.org/html/rfc3501 ). If there are differences in IMAP server implementations then the behavior will be different. I would recommend reviewing section 6.4.4 of RFC 3501.

Given that AND is the default, you might try this: BODY "[TAG:" SINCE 01-Jan-2015

If Office365 doesn't return anything, then experiment. Does passing only "SINCE 01-Jan-2015" return anything? What about passing only BODY "[TAG:"?


Answer

After poking values into the filter, using the BODY filter is totally unreliable across IMAP servers. The SUBJECT filter though works fine...which might explain why most email tags appear in the subject line.

Hopefully this'll save anyone else banging their head against this one