Split out the code to login into imap in a separate function.

Signed-off-by: Thiago Farina <tfarina@chromium.org>