Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search getting stuck when new mail recieved #910

Open
Code-R-xplorer opened this issue Sep 24, 2023 · 0 comments
Open

Search getting stuck when new mail recieved #910

Code-R-xplorer opened this issue Sep 24, 2023 · 0 comments

Comments

@Code-R-xplorer
Copy link

So I'm trying to use this library to read emails that come into the inbox and then read the contents to pass on to another part of the program. The issue I'm facing at the moment is that when a new email comes in and a search is performed it seems to get stuck and then the program just crashes.

I'm using more or less the example code given.

const Imap = require('imap'), inspect = require('util').inspect;

const imap = new Imap({
    user: '*****@**************.com',
    password: '***************',
    host: ***********.com',
    port: 993,
    tls: true,
    debug: console.log
});

function openInbox() {
    imap.openBox('INBOX', false, function (err, cb) {
        if (err) throw err;
    });
}

imap.once('ready', function() {
    openInbox()
});

imap.on('mail', function() {
    console.log("Mail Received");
    imap.search(['UNSEEN', ['SINCE', new Date("2023-09-19")]], (err, results) => {
        if (err) throw err;
        console.log("Searched");
    });
});

imap.once('error', function(err) {
    console.log(err);
});

imap.once('end', function() {
    console.log('Connection ended');
});

imap.connect();

I've taken out all the mail-parsing code as I don't believe that to be the issue.

Here is the output:

[connection] Connected to host
<= '* OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ AUTH=PLAIN AUTH=LOGIN AUTH=DIGEST-MD5 AUTH=CRAM-MD5] Dovecot ready.'
=> 'A0 CAPABILITY'                                                                                                                                 
<= '* CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ AUTH=PLAIN AUTH=LOGIN AUTH=DIGEST-MD5 AUTH=CRAM-MD5'
<= 'A0 OK Pre-login capabilities listed, post-login capabilities have more.'                                                   
=> 'A1 LOGIN "*****@**********.com" "************"'                                                                 
<= '* CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=
1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY PREVIEW=FUZZY PREVIEW STATUS=SIZE SAVEDATE LITERAL+ NOTIFY SPECIAL-USE QUOTA'
<= 'A1 OK Logged in'
=> 'A2 NAMESPACE'
<= '* NAMESPACE (("INBOX." ".")) NIL NIL'           
<= 'A2 OK Namespace completed (0.001 + 0.000 secs).'
=> 'A3 LIST "" ""'                                  
<= '* LIST (\\Noselect) "." ""'
<= 'A3 OK List completed (0.001 + 0.000 secs).'
=> 'A4 SELECT "INBOX" (CONDSTORE)'
<= '* FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)'
<= '* OK [PERMANENTFLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft \\*)] Flags permitted.'
<= '* 13 EXISTS'
Mail Received
<= '* 0 RECENT'
<= '* OK [UIDVALIDITY 1695200970] UIDs valid'
<= '* OK [UIDNEXT 14] Predicted next UID'
<= '* OK [HIGHESTMODSEQ 26] Highest'
<= 'A4 OK [READ-WRITE] Select completed (0.004 + 0.000 + 0.003 secs).'
=> 'A5 UID SEARCH UNSEEN SINCE 19-Sep-2023'
<= '* SEARCH'
<= 'A5 OK Search completed (0.001 + 0.000 secs).'
Searched
=> 'IDLE IDLE'
<= '+ idling'
<= '* 14 EXISTS'
Mail Received
=> DONE
<= '* 1 RECENT'
<= 'IDLE OK Idle completed (11.833 + 11.832 + 11.832 secs).'

I'm using a Plesk Ubuntu server for my mail server which uses Dovecot if that is useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant