+2 votes

We’re hitting the following error on large mailboxes (more than 3 million message) in Gmail.
Do you know what can be the reason (error returned by the server?)

C: d766a38332474fb7 UID SEARCH RETURN (ALL) SENTSINCE 01-Feb-2014 SENTBEFORE 01-Feb-2015
S: * BYE System Error

The code we use to search IMAP is simple:

DateTime startDate = new DateTime(2014,2,1);
DateTime endDate = new DateTime(2015, 2, 1);

List<long> lst = client.Search().Where(
    Expression.And(
        Expression.SentSince(startDate), 
        Expression.SentBefore(endDate)));

Any way to increase timeouts or may do the query differently.

by
edited by

1 Answer

0 votes
 
Best answer

It is the IMAP server that is returning an error:

* BYE System Error

This means that the server is able to send its error message before it disconnects.
Increasing the timeout won't help as the problem is not on the IMAP client side nor it is the communication/network problem.

The account is not being throttled (No [THROTTLED] is present).

I'm afraid that your only option may be break the search period into smaller intervals.

You can use the object returned by the Imap.Examine or Imap.Select method to get total message count (using MessageCount property) and act accordingly for large mailboxes.

[Edit]

I run a small check and it seems that Imap.GetAll() method works, even for such large mailboxes:

C: e17ccfdc58d2410e UID SEARCH RETURN (ALL) ALL
S: * ESEARCH (TAG "e17ccfdc58d2410e") UID ALL 1:2,5:41,43:3526 .... (150kB data here)
S: e17ccfdc58d2410e OK SEARCH completed (Success)

Please update the component, as the latest version uses ESEARCH whenever possible.

ESEARCH compacts IMAP server responses greatly, as the server may replay using ranges (1:50) instead of specific uids (1,2,3,[44 more numbers here],48,49,50). Ranges are handled internally by Mail.dll, so on the outside you see
regular list of all uids: List.

Search by date nevertheless fails. Most likely this is because internally IMAP server is not able to apply the where condition to that many messages. It timeouts out and returns the error message (*BYE) and disconnects.

by (301k points)
...