text
stringlengths
0
357
if (!dc_chatlist_load_from_db(obj, listflags, query_str, query_id)) {
goto cleanup;
}
success = 1;
cleanup:
if (success) {
return obj;
}
else {
dc_chatlist_unref(obj);
return NULL;
}
}
```
Filename: dc_configure.c
```c
#include <dirent.h>
#include <unistd.h>
#include "dc_context.h"
#include "dc_loginparam.h"
#include "dc_imap.h"
#include "dc_smtp.h"
#include "dc_saxparser.h"
#include "dc_job.h"
#include "dc_oauth2.h"
/*******************************************************************************
* Connect to configured account
******************************************************************************/
int dc_connect_to_configured_imap(dc_context_t* context, dc_imap_t* imap)
{
int ret_connected = DC_NOT_CONNECTED;
dc_loginparam_t* param = dc_loginparam_new();
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || imap==NULL) {
dc_log_warning(imap->context, 0, "Cannot connect to IMAP: Bad parameters.");
goto cleanup;
}
if (dc_imap_is_connected(imap)) {
ret_connected = DC_ALREADY_CONNECTED;
goto cleanup;
}
if (dc_sqlite3_get_config_int(imap->context->sql, "configured", 0)==0) {
dc_log_warning(imap->context, 0, "Not configured, cannot connect.");
goto cleanup;
}
dc_loginparam_read(param, imap->context->sql,
"configured_" /*the trailing underscore is correct*/);
if (!dc_imap_connect(imap, param)) {
goto cleanup;
}
ret_connected = DC_JUST_CONNECTED;
cleanup:
dc_loginparam_unref(param);
return ret_connected;
}
/*******************************************************************************
* Thunderbird's Autoconfigure
******************************************************************************/
/* documentation: https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Autoconfiguration */
typedef struct moz_autoconfigure_t
{
const dc_loginparam_t* in;
char* in_emaildomain;
char* in_emaillocalpart;
dc_loginparam_t* out;
int out_imap_set;
int out_smtp_set;
/* currently, we assume there is only one emailProvider tag in the
file, see example at https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
moreover, we assume, the returned domains match the one queried. I've not seen another example (bp).
However, _if_ the assumptions are wrong, we can add a first saxparser-pass that searches for the correct domain
and the second pass will look for the index found. */
#define MOZ_SERVER_IMAP 1
#define MOZ_SERVER_SMTP 2
int tag_server;