text
stringlengths
0
357
*/
```
Filename: dc_job.c
```c
#include <stdarg.h>
#include <unistd.h>
#include <math.h>
#include "dc_context.h"
#include "dc_loginparam.h"
#include "dc_job.h"
#include "dc_imap.h"
#include "dc_smtp.h"
#include "dc_mimefactory.h"
static void dc_send_mdn(dc_context_t* context, uint32_t msg_id);
/*******************************************************************************
* IMAP-jobs
******************************************************************************/
static int connect_to_inbox(dc_context_t* context)
{
int ret_connected = DC_NOT_CONNECTED;
ret_connected = dc_connect_to_configured_imap(context, context->inbox);
if (!ret_connected) {
goto cleanup;
}
dc_imap_set_watch_folder(context->inbox, "INBOX");
cleanup:
return ret_connected;
}
static void dc_job_do_DC_JOB_DELETE_MSG_ON_IMAP(dc_context_t* context, dc_job_t* job)
{
int delete_from_server = 1;
dc_msg_t* msg = dc_msg_new_untyped(context);
if (!dc_msg_load_from_db(msg, context, job->foreign_id)
|| msg->rfc724_mid==NULL || msg->rfc724_mid[0]==0 /* eg. device messages have no Message-ID */) {
goto cleanup;
}
if (dc_rfc724_mid_cnt(context, msg->rfc724_mid)!=1) {
dc_log_info(context, 0, "The message is deleted from the server when all parts are deleted.");
delete_from_server = 0;
}
/* if this is the last existing part of the message, we delete the message from the server */
if (delete_from_server)
{
if (!dc_imap_is_connected(context->inbox)) {
connect_to_inbox(context);
if (!dc_imap_is_connected(context->inbox)) {
dc_job_try_again_later(job, DC_STANDARD_DELAY, NULL);
goto cleanup;
}
}
if (!dc_imap_delete_msg(context->inbox, msg->rfc724_mid, msg->server_folder, msg->server_uid))
{
dc_job_try_again_later(job, DC_AT_ONCE, NULL);
goto cleanup;
}
}
/* we delete the database entry ...
- if the message is successfully removed from the server
- or if there are other parts of the message in the database (in this case we have not deleted if from the server)
(As long as the message is not removed from the IMAP-server, we need at least one database entry to avoid a re-download) */
dc_delete_msg_from_db(context, msg->id);
cleanup:
dc_msg_unref(msg);
}
static void dc_job_do_DC_JOB_EMPTY_SERVER(dc_context_t* context, dc_job_t* job)
{
char* mvbox_name = NULL;
if (!dc_imap_is_connected(context->inbox)) {
connect_to_inbox(context);
if (!dc_imap_is_connected(context->inbox)) {
goto cleanup;
}
}
if (job->foreign_id&DC_EMPTY_MVBOX) {
char* mvbox_name = dc_sqlite3_get_config(context->sql, "configured_mvbox_folder", NULL);
if (mvbox_name && mvbox_name[0]) {