Proper IMAP logout

Prior to this CL the IMAP client never send a LOGOUT command and just
shut down the socket, which was regarded as an "abnormal session
termination" to the server.

In this CL, we will attempt to send the LOGOUT command before closing
the socket. ImapHelper was also made closeable to ensure the connection
is not leaked.

Change-Id: I920c63edaa39116e56d17866451709306e5ab91c
Fixes: 27816588
8 files changed