text
stringlengths
0
357
}
cleanup:
dc_param_unref(job.param);
free(job.pending_error);
sqlite3_finalize(select_stmt);
}
/*******************************************************************************
* User-functions handle IMAP-jobs from the IMAP-thread
******************************************************************************/
/**
* Execute pending imap-jobs.
* This function and dc_perform_imap_fetch() and dc_perform_imap_idle()
* must be called from the same thread, typically in a loop.
*
* Example:
*
* void* imap_thread_func(void* context)
* {
* while (true) {
* dc_perform_imap_jobs(context);
* dc_perform_imap_fetch(context);
* dc_perform_imap_idle(context);
* }
* }
*
* // start imap-thread that runs forever
* pthread_t imap_thread;
* pthread_create(&imap_thread, NULL, imap_thread_func, context);
*
* ... program runs ...
*
* // network becomes available again -
* // the interrupt causes dc_perform_imap_idle() in the thread above
* // to return so that jobs are executed and messages are fetched.
* dc_maybe_network(context);
*
* @memberof dc_context_t
* @param context The context as created by dc_context_new().
* @return None.
*/
void dc_perform_imap_jobs(dc_context_t* context)
{
dc_log_info(context, 0, "INBOX-jobs started...");
pthread_mutex_lock(&context->inboxidle_condmutex);
int probe_imap_network = context->probe_imap_network;
context->probe_imap_network = 0;
context->perform_inbox_jobs_needed = 0;
pthread_mutex_unlock(&context->inboxidle_condmutex);
dc_job_perform(context, DC_IMAP_THREAD, probe_imap_network);
dc_log_info(context, 0, "INBOX-jobs ended.");
}
/**
* Fetch new messages, if any.
* This function and dc_perform_imap_jobs() and dc_perform_imap_idle() must be called from the same thread,
* typically in a loop.
*
* See dc_perform_imap_jobs() for an example.
*
* @memberof dc_context_t
* @param context The context as created by dc_context_new().
* @return None.
*/
void dc_perform_imap_fetch(dc_context_t* context)
{
clock_t start = clock();
if (!connect_to_inbox(context)) {
return;
}
if (dc_sqlite3_get_config_int(context->sql, "inbox_watch", DC_INBOX_WATCH_DEFAULT)==0) {
dc_log_info(context, 0, "INBOX-watch disabled.");
return;
}
dc_log_info(context, 0, "INBOX-fetch started...");
dc_imap_fetch(context->inbox);
if (context->inbox->should_reconnect)
{
dc_log_info(context, 0, "INBOX-fetch aborted, starting over...");
dc_imap_fetch(context->inbox);
}
dc_log_info(context, 0, "INBOX-fetch done in %.0f ms.", (double)(clock()-start)*1000.0/CLOCKS_PER_SEC);
}