text
stringlengths
0
357
}
}
// TODO: also optimize for already processed report/mdn Message-IDs.
// this happens regulary as eg. mdns are typically read from the INBOX,
// moved to MVBOX and popping up from there.
// when modifying tables for this purpose, maybe also target #112 (mdn cleanup)
free(old_server_folder);
return rfc724_mid_exists;
}
static void cb_receive_imf(dc_imap_t* imap, const char* imf_raw_not_terminated, size_t imf_raw_bytes, const char* server_folder, uint32_t server_uid, uint32_t flags)
{
dc_context_t* context = (dc_context_t*)imap->userData;
dc_receive_imf(context, imf_raw_not_terminated, imf_raw_bytes, server_folder, server_uid, flags);
}
/**
* Create a new context object. After creation it is usually
* opened, connected and mails are fetched.
*
* @memberof dc_context_t
* @param cb a callback function that is called for events (update,
* state changes etc.) and to get some information from the client (eg. translation
* for a given string).
* See @ref DC_EVENT for a list of possible events that may be passed to the callback.
* - The callback MAY be called from _any_ thread, not only the main/GUI thread!
* - The callback MUST NOT call any dc_* and related functions unless stated
* otherwise!
* - The callback SHOULD return _fast_, for GUI updates etc. you should
* post yourself an asynchronous message to your GUI thread, if needed.
* - If not mentioned otherweise, the callback should return 0.
* @param userdata can be used by the client for any purpuse. He finds it
* later in dc_get_userdata().
* @param os_name is only for decorative use
* and is shown eg. in the `X-Mailer:` header
* in the form "Delta Chat Core <version>/<os_name>".
* You can give the name of the app, the operating system,
* the used environment and/or the version here.
* It is okay to give NULL, in this case `X-Mailer:` header
* is set to "Delta Chat Core <version>".
* @return A context object with some public members.
* The object must be passed to the other context functions
* and must be freed using dc_context_unref() after usage.
*/
dc_context_t* dc_context_new(dc_callback_t cb, void* userdata, const char* os_name)
{
dc_context_t* context = NULL;
if ((context=calloc(1, sizeof(dc_context_t)))==NULL) {
exit(23); /* cannot allocate little memory, unrecoverable error */
}
pthread_mutex_init(&context->smear_critical, NULL);
pthread_mutex_init(&context->bobs_qr_critical, NULL);
pthread_mutex_init(&context->inboxidle_condmutex, NULL);
dc_jobthread_init(&context->sentbox_thread, context, "SENTBOX", "configured_sentbox_folder");
dc_jobthread_init(&context->mvbox_thread, context, "MVBOX", "configured_mvbox_folder");
pthread_mutex_init(&context->smtpidle_condmutex, NULL);
pthread_cond_init(&context->smtpidle_cond, NULL);
pthread_mutex_init(&context->oauth2_critical, NULL);
context->magic = DC_CONTEXT_MAGIC;
context->userdata = userdata;
context->cb = cb? cb : cb_dummy;
context->os_name = dc_strdup_keep_null(os_name);
context->shall_stop_ongoing = 1; /* the value 1 avoids dc_stop_ongoing_process() from stopping already stopped threads */
dc_openssl_init(); // OpenSSL is used by libEtPan and by netpgp, init before using these parts.
dc_pgp_init();
context->sql = dc_sqlite3_new(context);
dc_job_kill_action(context, DC_JOB_EMPTY_SERVER);
context->inbox = dc_imap_new(cb_get_config, cb_set_config, cb_precheck_imf, cb_receive_imf, (void*)context, context);
context->sentbox_thread.imap = dc_imap_new(cb_get_config, cb_set_config, cb_precheck_imf, cb_receive_imf, (void*)context, context);
context->mvbox_thread.imap = dc_imap_new(cb_get_config, cb_set_config, cb_precheck_imf, cb_receive_imf, (void*)context, context);
context->smtp = dc_smtp_new(context);
/* Random-seed. An additional seed with more random data is done just before key generation
(the timespan between this call and the key generation time is typically random.
Moreover, later, we add a hash of the first message data to the random-seed
(it would be okay to seed with even more sensible data, the seed values cannot be recovered from the PRNG output, see OpenSSL's RAND_seed()) */
uintptr_t seed[5];
seed[0] = (uintptr_t)time(NULL); /* time */
seed[1] = (uintptr_t)seed; /* stack */
seed[2] = (uintptr_t)context; /* heap */
seed[3] = (uintptr_t)pthread_self(); /* thread ID */
seed[4] = (uintptr_t)getpid(); /* process ID */
dc_pgp_rand_seed(context, seed, sizeof(seed));
return context;
}
/**