mscdex / node-imap

An IMAP client module for node.js.
MIT License
2.14k stars 379 forks source link

Mail events are not triggered most of the time #889

Open LanXiaoChr opened 1 year ago

LanXiaoChr commented 1 year ago

When I receive a new email in my work email, the ‘mail’ event doesn't fire. It's the same when I use my private email. Sometimes, when I rerun the program it may work but most of the time it doesn't.

const Imap = require('imap')

let imap = new Imap({
    user: 'xxxxxx@xxx.com',
    password: 'xxxxxxxx',
    host: 'imap.xxxx.com',
    port: 993,
    tls: true
})

imap.once('ready', () => {
    imap.openBox('INBOX', true, (err, box) => {
        if (err) throw err
    })
})

imap.on('mail', (mail) => {
    console.log('new email: ' + mail)
})

imap.connect()

Log:

$ node test.js 
[connection] Connected to host
<= '* OK [CAPABILITY IMAP4 IMAP4rev1 ID AUTH=PLAIN AUTH=LOGIN AUTH=XOAUTH2 NAMESPACE] QQMail XMIMAP4Server ready'
=> 'A0 CAPABILITY'
<= '* CAPABILITY IMAP4 IMAP4rev1 XLIST MOVE IDLE XAPPLEPUSHSERVICE AUTH=PLAIN AUTH=LOGIN AUTH=XOAUTH2 NAMESPACE CHILDREN ID UIDPLUS'
<= 'A0 OK CAPABILITY Completed'
=> 'A1 LOGIN "xxxxxx@xxx.com" "xxxxxxxx"'
<= 'A1 OK Success login ok'
=> 'A2 CAPABILITY'
<= '* CAPABILITY IMAP4 IMAP4rev1 XLIST MOVE IDLE XAPPLEPUSHSERVICE NAMESPACE CHILDREN ID UIDPLUS'
<= 'A2 OK CAPABILITY Completed'
=> 'A3 NAMESPACE'
<= '* NAMESPACE (("" "/")) NIL NIL'
<= 'A3 OK NAMESPACE Success'
=> 'A4 LIST "" ""'
<= '* LIST (\\NoSelect) "/" "/"'
<= 'A4 OK LIST completed'
=> 'A5 EXAMINE "INBOX"'
<= '* 69 EXISTS'
new email: 69
<= '* 0 RECENT'
<= '* OK [UNSEEN 8]'
<= '* OK [UIDVALIDITY 1663402387] UID validity status'
<= '* OK [UIDNEXT 2664] Predicted next UID'
<= '* FLAGS (\\Answered \\Flagged \\Deleted \\Draft \\Seen)'
<= '* OK [PERMANENTFLAGS ()] No permanent flags permitted'
<= 'A5 OK [READ-ONLY] EXAMINE complete'
=> 'IDLE IDLE'
<= '+ idling'
vininjr commented 1 year ago

` let imap = new Imap({

user: 'xxxxxx@xxx.com',
password: 'xxxxxxxx',
host: 'imap.xxxx.com',
port: 993,
tls: true,
keepalive: {
  interval: 10000,
  idleInterval: 0,
  forceNoop: true,
},

}) ` / This is the interval (in milliseconds) at which NOOPs are sent and the interval at which idleInterval is checked. Default: 10000 */ interval?: number | undefined; /* This is the interval (in milliseconds) at which an IDLE command (for servers that support IDLE) is re-sent. Default: 300000 (5 mins) / idleInterval?: number | undefined; / Set to true to force use of NOOP keepalive on servers also support IDLE. Default: false */ forceNoop?: boolean | undefined;