Search code examples
javascriptnode.jsimap

Searching email in imap Node.js


I am using imap package in my project I have read the documentation and I found this for searching in email with date.

imap.search([ 'UNSEEN', ['SINCE', 'May 20, 2010'] ], function(err, results) {
});

I want to search email between two dates for example May 20, 2010 to May 28,2010.

So it possible to find between dates in imap protocol ?


Solution

  • Can you give reference to the module you refer to?

    If you are using mscdex/node-imap, you can refer to

    'BEFORE' - Messages whose internal date (disregarding time and timezone) is earlier than the specified date.

    'SINCE' - Messages whose internal date (disregarding time and timezone) is within or later than the specified date.

    in its API documentation https://github.com/mscdex/node-imap/blob/master/README.md#API

    search(< array >criteria, < function >callback) - (void)

    so to sum up

    imap.search([ 'UNSEEN', ['SINCE', 'May 20, 2010'], ['BEFORE', 'May 28, 2010'] ],
        function(err, results) {
    });
    

    is what you want ...