mail-listener icon indicating copy to clipboard operation
mail-listener copied to clipboard

Callback when all message retrievals are complete

Open anotheri opened this issue 11 years ago • 8 comments

fetch(< mixed >source, [< object >options, ] < mixed >request, < function >callback) - (void) - Fetches message(s) in the currently open mailbox. source can be a message UID, a message UID range (e.g. '2504:2507' or '' or '2504:'), or an array of message UIDs and/or message UID rang ... callback has 1 parameter: < Error >err. This is executed when all message retrievals are complete.

There is usage examples here.

Please implement this feature in the options of mail-listener or emit some event from callback function.

anotheri avatar May 23 '13 13:05 anotheri

Do you want a callback when all the mails are parsed or when all the mails are fetched?

I might be able to send a PR for this as well.

chirag04 avatar May 23 '13 15:05 chirag04

@chirag04 when all the mails are fetched like here:

imap.fetch(results,
      { headers: ['from', 'to', 'subject', 'date'],
        cb: function(fetch) {
          fetch.on('message', function(msg) {
            console.log('Saw message no. ' + msg.seqno);
            msg.on('headers', function(hdrs) {
              console.log('Headers for no. ' + msg.seqno + ': ' + show(hdrs));
            });
            msg.on('end', function() {
              console.log('Finished message no. ' + msg.seqno);
            });
          });
        }
      }, 
      function(err) { 
        if (err) throw err;
        console.log('Done fetching all messages!');
        imap.logout();
      } // <—— THIS CALLBACK
    );

Thank you.

anotheri avatar May 23 '13 15:05 anotheri

Yes, I know about the callback that you asking about. But the thing is, mail-listener will call mailparser in the cb function which emits mail:parsed event. This mail:parsed event will be fired after the callback you asking for.

So, it comes down to, do you need callback for (done fetching all) or something like (done parsing all and emitting parsing event)

chirag04 avatar May 23 '13 17:05 chirag04

@chirag04 hm... seems I need second case (done parsing all and emitting parsing event).

anotheri avatar May 24 '13 05:05 anotheri

@anotheri I think i will be able to do that for you by eod.

chirag04 avatar May 24 '13 07:05 chirag04

@chirag04 thank you very much

anotheri avatar May 24 '13 08:05 anotheri

@chirag04 so... what's about it?

anotheri avatar May 28 '13 13:05 anotheri

@anotheri sorry man! busy with other stuff. Will try to take some time out for this.

chirag04 avatar May 28 '13 13:05 chirag04