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

Add IMAP listeners on "close" and "error" #22

Open
anotheri opened this issue Jun 13, 2013 · 10 comments
Open

Add IMAP listeners on "close" and "error" #22

anotheri opened this issue Jun 13, 2013 · 10 comments

Comments

@anotheri
Copy link

Add please two imap listeners and emits. Something like this:

After @emit "server:connected":

@imap.on "close", (err) =>
    # console.log "IMAP close"
    @emit "imap:close", err

@imap.on "error", (err) =>
    # console.log "IMAP error", err
    @emit "imap:err", err;

I think it may have another predefine handlers by default (stop mailListener, for example, or restart it, or something other). But i need opportunity to set handlers on this events from listeners for mail-listener class like this:

mailListener.on("imap:err", function(){
    console.log("imapError");
});

mailListener.on("imap:close", function(){
    mailListener.restart();
        // or something other code
});
@chirag04
Copy link
Contributor

Mail listener already emit these events. See if below example makes sense to you.

mailListener.on("server:error", function(error){
                console.log('imap error')
});
mailListener.on("server:disconnected", function(){
      //  restart here
});

@anotheri
Copy link
Author

@chirag04
server:error and server:disconnected are not imap events, check the code. you can try to add this events and check it.
imap is down after 1 hour of inactivity and only @imap.on "close", (err) => can catch it.

@anotheri
Copy link
Author

@chirag04
this is actual for imap v. 0.7.8. I didn't test this with other versions of imap.
but I'm testing now imap v.0.7.12.

@chirag04
Copy link
Contributor

Ok. got it. I will leave this to @podviaznikov

@anotheri
Copy link
Author

@chirag04
It seems that fallings down after 1 hour of inactivity were fixed in imap. And that's great! It works already 1.5 hour. )
I'll leave my listener in active status for 24 hours and will describe how it works tomorrow.

@podviaznikov
Could you update mail-listener in the npm please? Version based on imap 0.7.12 seems more stable.

@anotheri
Copy link
Author

But... After ~2 hour I send a second mail, it was parsed correctly and listener working else few minute and than shutted down with unhandled error:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: read ECONNRESET
    at errnoException (net.js:883:11)
    at TCP.onread (net.js:539:19)

And I think this error should be handled next way:

@imap.on "error", (err) =>
    # console.log "IMAP error", err
    @emit "imap:err", err;

And I started listener again...

@chirag04
Copy link
Contributor

@anotheri till then you might want to start your script with forever. Shall give you some good sleep. Haha :)

@anotheri
Copy link
Author

@chirag04 thanks for realy good advice. ) but now i want test it without forever. this (forever) is my ace in the hole. =))

@anotheri
Copy link
Author

@chirag04 And, as i sad yesterday, listener was shutted down with only output:

 --- IMAP CLOSE: false

that I define into this block:

@imap.on "close", (err) =>
    console.log " --- IMAP CLOSE:", err
    @emit "imap:close", err

In this case imap v. 0.7.12 works like previous.
So add emit functions on imap close and error events please.
And I'll use my ace — forever. =)

@chirag04
Copy link
Contributor

Not sure if this is relevant but i tried to start mail-listener and kept it on server. Its still connected and running from last 5hours.

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

2 participants