user1829200
user1829200

Reputation:

Do I need to do something else after sending IMAP idle command in order to keep the connection alive?

I am dealing with the implementation of an IMAP client (more precisely, with JavaMail), which uses the IMAP idle() command to get new email notifications directly from the Server, without having to poll it.

Here is my question: Should I do something else after sending this idle command (i.e. sending IMAP idle() again, just asking for the number of messages) in order to keep the connection alive?

Said another way: Could this Server close the current IMAP connection, even though I have previously sent the idle() command?

I found a lot of questions/some code in Stackoverflow and other sites, but I am still not satisfied. Hope there is an expert in the IMAP protocol out there.

Thanks!

Upvotes: 1

Views: 1140

Answers (2)

Max
Max

Reputation: 10985

The protocol indicates that the server may disconnect you, even in IDLE, after 30 minutes.

You must end the IDLE and reissue it at least every 30 minutes. Also, as Lt.Worf indicates, the socket could be closed for a multitude of other reasons.

Upvotes: 1

LtWorf
LtWorf

Reputation: 7600

The server will probably not disconnect you, but NEVER EVER rely on the stability of a socket, the connection could go away for several different reasons and you will need to gracefully intercept the exception and try to connect again, possibly after increasing timeouts.

KMail for example thinks that connections are the most permanent thing in the world after the pyramids so after suspending my laptop and moving somewhere else, i must restart it to have it connect again to the IMAP server.

Upvotes: 1

Related Questions