andyedinborough / aenetmail

C# POP/IMAP Mail Client
369 stars 153 forks source link

Error searching for Gmail emails started "xm003 BAD Could not parse command" #197

Open shay-rm opened 7 years ago

shay-rm commented 7 years ago

Two days ago we started getting the following error when searching for emails after a particular date from a Gmail account:

xm003 BAD Could not parse command

   at AE.Net.Mail.ImapClient.Search(String criteria, Boolean uid) in c:\Repos\aenetmail\ImapClient.cs:line 703
   at AE.Net.Mail.ImapClient.Search(SearchCondition criteria, Boolean uid) in c:\Repos\aenetmail\ImapClient.cs:line 691
   at ....

We didn't make any changes to the code. Anyone else start experiencing this when querying Gmail?

mattiasmoser commented 7 years ago

I am experiencing something very similar here, getting the exception below when searching for emails after a specific date using SearchCondition SentSince(datetime).

Stack Trace:

System.Exception: xm004 BAD Could not parse command at AE.Net.Mail.ImapClient.Search(String criteria, Boolean uid) at AE.Net.Mail.ImapClient.Search(SearchCondition criteria, Boolean uid) at ...

537mfb commented 7 years ago

Also running into this - gmail only - other mail servers don't throw this Couldn't figure out what causes this but other mail libraries seem to be getting this aswell example: https://github.com/nikoblag/Gmail.ps/issues/14

ReneNP commented 7 years ago

We are experiencing the exact samme issue using the "Since" field on SearchCondition.

First I was able to prevent the error by setting the Value property of SearchCondition to a string with no time (instead of a DateTime):

SearchCondition condition = new SearchCondition(); condition.Field = SearchCondition.Fields.Since; condition.Value = new DateTime(2016, 10, 1).ToString("dd-MMM-yyyy");

Then 2-3 days later that solution stopped working. And now I am using one of Gmail's IMAP extensions:

SearchCondition condition = new SearchCondition(); condition.Value = string.Format(@"X-GM-RAW ""AFTER:{0:yyyy-MM-dd}""", new DateTime(2016, 10, 1));

Currently I am only using the library with Gmail - I don't think the above "fix" would work with other providers.

537mfb commented 7 years ago

Thanks @ReneNP - That solution in a ternary will work for me If it's gmail use Gmail extension otherwise use regular search command

Would be nice to now why the regular search command no longer works with Gmail though

TroyWalshProf commented 7 years ago

It looks like the issue is that GMail is no longer able to handle the SearchCondition.GetRFC2060Date format. See related Gmail help forum

Note* Per IMAP RFC 3501 & 2060 it looks like SentSince should be Date and not Date-Time So search is sending something like this:

SEARCH SENTSINCE "28-Oct-2016 13:55:27 -05"

but should be sending

SEARCH SENTSINCE "28-Oct-2016"

saurabhabh commented 7 years ago

Any update on this issue. Facing the same problem with Gmail.