Refactor SELECT code into a helper function: g_imap_select().

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