text stringlengths 0 357 |
|---|
dc_log_info(imap->context, 0, "IMAP-OAuth2 connect..."); |
char* access_token = dc_get_oauth2_access_token(imap->context, imap->addr, imap->imap_pw, 0); |
r = mailimap_oauth2_authenticate(imap->etpan, imap->imap_user, access_token); |
if (dc_imap_is_error(imap, r)) { |
free(access_token); |
access_token = dc_get_oauth2_access_token(imap->context, imap->addr, imap->imap_pw, DC_REGENERATE); |
r = mailimap_oauth2_authenticate(imap->etpan, imap->imap_user, access_token); |
} |
free(access_token); |
} |
else |
{ |
/* DC_LP_AUTH_NORMAL or no auth flag set */ |
r = mailimap_login(imap->etpan, imap->imap_user, imap->imap_pw); |
} |
if (dc_imap_is_error(imap, r)) { |
char* msg = get_error_msg(imap, "Cannot login", r); |
dc_log_event_seq(imap->context, DC_EVENT_ERROR_NETWORK, &imap->log_connect_errors, |
"%s", msg); |
free(msg); |
goto cleanup; |
} |
dc_log_event(imap->context, DC_EVENT_IMAP_CONNECTED, 0, |
"IMAP-login as %s ok.", imap->imap_user); |
success = 1; |
cleanup: |
if (success==0) { |
unsetup_handle(imap); |
} |
imap->should_reconnect = 0; |
return success; |
} |
static void unsetup_handle(dc_imap_t* imap) |
{ |
if (imap==NULL) { |
return; |
} |
if (imap->etpan) |
{ |
if (imap->idle_set_up) { |
mailstream_unsetup_idle(imap->etpan->imap_stream); |
imap->idle_set_up = 0; |
} |
if (imap->etpan->imap_stream!=NULL) { |
mailstream_close(imap->etpan->imap_stream); /* not sure, if this is really needed, however, mailcore2 does the same */ |
imap->etpan->imap_stream = NULL; |
} |
mailimap_free(imap->etpan); |
imap->etpan = NULL; |
dc_log_info(imap->context, 0, "IMAP disconnected."); |
} |
imap->selected_folder[0] = 0; |
/* we leave sent_folder set; normally this does not change in a normal reconnect; we'll update this folder if we get errors */ |
} |
/******************************************************************************* |
* Connect/Disconnect |
******************************************************************************/ |
static void free_connect_param(dc_imap_t* imap) |
{ |
free(imap->addr); |
imap->addr = NULL; |
free(imap->imap_server); |
imap->imap_server = NULL; |
free(imap->imap_user); |
imap->imap_user = NULL; |
free(imap->imap_pw); |
imap->imap_pw = NULL; |
imap->watch_folder[0] = 0; |
imap->selected_folder[0] = 0; |
imap->imap_port = 0; |
imap->can_idle = 0; |
imap->has_xlist = 0; |
} |
int dc_imap_connect(dc_imap_t* imap, const dc_loginparam_t* lp) |
{ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.