QuickSearchDateRange is having some problems

Jun 30, 2008 at 9:39 AM
Hi All

If you try to search by date using QuickSearchDateRange e.g. searching the last 10 days you need to also search one day in the future in order to return today's email.

var sResult = subFolder.Search(IMAPSearchQuery.QuickSearchDateRange(DateTime.Now.AddDays(DaysToSearch), DateTime.Now.AddDays(1)));

Jun 30, 2008 at 10:34 AM


acosta wrote:
Hi All

If you try to search by date using QuickSearchDateRange e.g. searching the last 10 days you need to also search one day in the future in order to return today's email.

var sResult = subFolder.Search(IMAPSearchQuery.QuickSearchDateRange(DateTime.Now.AddDays(DaysToSearch), DateTime.Now.AddDays(1)));



Trying to understand that issue I was trying AfterDate instead QuickSearchDateRange but now I got that

Failure searching IMAP with the given criteria. IMAP008 BAD Protocol Error: "Invalid key supplied in the SEARCH command".

Jun 30, 2008 at 11:16 AM


acosta wrote:


acosta wrote:
Hi All

If you try to search by date using QuickSearchDateRange e.g. searching the last 10 days you need to also search one day in the future in order to return today's email.

var sResult = subFolder.Search(IMAPSearchQuery.QuickSearchDateRange(DateTime.Now.AddDays(DaysToSearch), DateTime.Now.AddDays(1)));


Trying to understand that issue I was trying AfterDate instead QuickSearchDateRange but now I got that

Failure searching IMAP with the given criteria. IMAP008 BAD Protocol Error: "Invalid key supplied in the SEARCH command".



Ok I found that IMAPFolder.Search the AfterDate  option was using "AFTER" as  command so I changed to SENTSINCE  and is not throwing "IMAP008 BAD Protocol Error: "Invalid key supplied in the SEARCH command". Jason Can you confirm that this is right ?

           if (query.AfterDate != String.Empty)
            {
                searchTerms.Add(String.Format("SENTSINCE {0}", FormatDateToServer(query.AfterDate)));
                //searchTerms.Add(String.Format("AFTER {0}", FormatDateToServer(query.AfterDate)));
            }
Jun 30, 2008 at 11:21 AM
I also found that the date range is searching using greater and equal to (SENTSINCE) but just less than (SENTBEFORE), so SENTBEFORE is not going to include today's date in my example.
Coordinator
Jun 30, 2008 at 2:07 PM
Yes, SENTSINCE is the correct command to use. The IMAP spec has several redundant/conflicting search commands, not sure if the one that works is server specific, meaning not every command needs to be implemented by the server.

I've also added SENTON terms to the date range section for both the start and end dates which should take care of the other problem you mentioned. I'll upload the new code so you can give it a try in your application.