text
stringlengths
0
357
void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job)
{
int success = 0;
int imap_connected_here = 0;
int smtp_connected_here = 0;
int ongoing_allocated_here = 0;
char* mvbox_folder = NULL;
dc_loginparam_t* param = NULL;
char* param_domain = NULL; /* just a pointer inside param, must not be freed! */
char* param_addr_urlencoded = NULL;
dc_loginparam_t* param_autoconfig = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
goto cleanup;
}
if (!dc_alloc_ongoing(context)) {
goto cleanup;
}
ongoing_allocated_here = 1;
#define PROGRESS(p) \
if (context->shall_stop_ongoing) { goto cleanup; } \
context->cb(context, DC_EVENT_CONFIGURE_PROGRESS, (p)<1? 1 : ((p)>999? 999 : (p)), 0);
if (!dc_sqlite3_is_open(context->sql)) {
dc_log_error(context, 0, "Cannot configure, database not opened.");
goto cleanup;
}
dc_imap_disconnect(context->inbox);
dc_imap_disconnect(context->sentbox_thread.imap);
dc_imap_disconnect(context->mvbox_thread.imap);
dc_smtp_disconnect(context->smtp);
//dc_sqlite3_set_config_int(context->sql, "configured", 0); -- NO: we do _not_ reset this flag if it was set once; otherwise the user won't get back to his chats (as an alternative, we could change the UI). Moreover, and not changeable in the UI, we use this flag to check if we shall search for backups.
context->smtp->log_connect_errors = 1;
context->inbox->log_connect_errors = 1;
context->sentbox_thread.imap->log_connect_errors = 1;
context->mvbox_thread.imap->log_connect_errors = 1;
dc_log_info(context, 0, "Configure ...");
PROGRESS(0)
/* 1. Load the parameters and check email-address and password
**************************************************************************/
param = dc_loginparam_new();
dc_loginparam_read(param, context->sql, "");
if (param->addr==NULL) {
dc_log_error(context, 0, "Please enter the email address.");
goto cleanup;
}
dc_trim(param->addr);
if (param->server_flags & DC_LP_AUTH_OAUTH2)
{
// the used oauth2 addr may differ, check this.
// if dc_get_oauth2_addr() is not available in the oauth2 implementation,
// just use the given one.
PROGRESS(10)
char* oauth2_addr = dc_get_oauth2_addr(context, param->addr, param->mail_pw);
if (oauth2_addr) {
free(param->addr);
param->addr = oauth2_addr;
dc_sqlite3_set_config(context->sql, "addr", param->addr);
}
PROGRESS(20)
}
param_domain = strchr(param->addr, '@');
if (param_domain==NULL || param_domain[0]==0) {
dc_log_error(context, 0, "Bad email-address.");
goto cleanup;
}
param_domain++;
param_addr_urlencoded = dc_urlencode(param->addr);
/* if no password is given, assume an empty password.
(in general, unset values are NULL, not the empty string, this allows to use eg. empty user names or empty passwords) */
if (param->mail_pw==NULL) {
param->mail_pw = dc_strdup(NULL);
}
PROGRESS(200)
/* 2. Autoconfig
**************************************************************************/
if (param->mail_server ==NULL
&& param->mail_port ==0
/*&&param->mail_user ==NULL -- the user can enter a loginname which is used by autoconfig then */