circuithub / mail-listener

Mail listener library for node.js. Get notification when new email arrived.
134 stars 32 forks source link

Callback when all message retrievals are complete #19

Open anotheri opened 11 years ago

anotheri commented 11 years ago

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.

chirag04 commented 11 years ago

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.

anotheri commented 11 years ago

@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.

chirag04 commented 11 years ago

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)

anotheri commented 11 years ago

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

chirag04 commented 11 years ago

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

anotheri commented 11 years ago

@chirag04 thank you very much

anotheri commented 11 years ago

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

chirag04 commented 11 years ago

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