Add support for limit when searching
#221

Comments

Related to #218 would it be possible to add a LIMIT option when searching for emails? I'm currently using [ 'ALL', ['SINCE', 'yesterday'] ], and processing those emails. The issue is - what if the script has missed processing emails before yesterday?

To alleviate the errors produced in #218 I need to not read so many emails per batch, which would be really easy to do with LIMIT - and wouldn't be constrained to time.

There is no built-in mechanism in the imap protocol (or even any extra server capabilities that I know of) to limit search results.

I think the best way is to just fetch a portion of the results array at a time (you might have to use some trial and error to find out what the optimal size is). One solution might be something like (untested):

@engram-design The limit being used there is just a simple range based on messages' sequence numbers, which you can do in this module as well with search(). The problem is you may not know what the sequence numbers are before searching. If you did know them before searching, then you probably wouldn't have to search in the first place... :-)