Add g_imap_connect() helper function.

This functions does the initial setup of socket and the connection
through SSL with gmail imap server.

It extracts the code from the main function, so it can be reused as an
API by clients.

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