chirag04/mail-listener2

how to get buid or seqno ?

Closed this issue · 2 comments

How can I get a message buid or seqno ??

I think I found how to do that by using the imap object:

mailListener.imap.openBox('INBOX', true, function(err, box) {
if (err) {
throw err;
}

        var uid = '',
            f = mailListener.imap.seq.fetch(box.messages.total + ':*', { bodies: ['HEADER.FIELDS (FROM)','TEXT'] });

        f.on('message', function(msg, seqno) {
            msg.once('attributes', function(attrs) {
                console.log(attrs['x-gm-msgid']);

                uid = attrs['x-gm-msgid'];
            });
        });
        f.once('error', function(err) {
            console.log('Fetch error: ' + err);
        });
        f.once('end', function() {
            console.log('Done fetching all messages!');
                            mailListener.imap.end();
        });
    });

It is not very clean but I get the uid (the Gmail uid).
My problem is that when I try to use it after to set a flag in example, I've got an error...

mailListener.imap.addFlags(uid, 'Deleted', function(err){ console.log(err); });

{ [Error: Could not parse command] textCode: undefined, source: 'protocol' }

the mail event will now have seq and attributes. Refer the updated readme.

eg:

mailListener.on("mail", function(mail, seqno, attributes){
  // do something with mail object including attachments
  console.log("emailParsed", mail);
  // mail processing code goes here
});