MateMalice / mail-listener2

Mail listener library for node.js. Get notification when new email arrived.
Other
9 stars 7 forks source link

Attributes null on mailListener.on("mail") #41

Open stratbasher opened 1 year ago

stratbasher commented 1 year ago

Hello,

My code worked a few days ago when I was running an older version of mailListener. I decided to run npm update yesterday. I'm not sure what version it was but it was probably about 6 months old. I tried to downgrade but I didn't see any older releases.

Using Node v19.7.0

mailListener.on("mail", async function (mail, seqno, attributes) {

    mailListener.imap.move(attributes.uid, "INBOX/Folder/here");

}

The "attributes" variable is null when trying to access the uid variable so I can move the email to another folder.

image

Any ideas on what I can troubleshoot?

stratbasher commented 1 year ago

I'm an idiot - making it async didn't give time for imap to resolve the attributes. Removing "async" fixed the issue.

stratbasher commented 1 year ago

I spoke too soon. I put two log lines into parseUnread().

One in:

f.on('message', (msg, seqno) => {
    attrs=0;
    **console.log(attrs);**
}

And one in:

msg.on('body', async (stream, info) => {
    let parsed = await simpleParser(stream);
    **console.log('emitting mail');**
}

When running my code against an mailbox with existing mail, I'm getting the "emitting mail" message without any attrs. I think this has to be some sort of synchronicity issue where the 'attributes' event gets fired after 'body' does.

image

This is further reinforced by the fact that if I put some breakpoints in the mail-listener5 index.js file to manually slow things down, I will get the attributes variable.

image

@MorphedAU did you ever figure this out?