text
stringlengths
0
357
char* pathNfilename = dc_param_get(mimefactory.msg->param, DC_PARAM_FILE, NULL);
if (pathNfilename) {
if ((mimefactory.msg->type==DC_MSG_IMAGE || mimefactory.msg->type==DC_MSG_GIF)
&& !dc_param_exists(mimefactory.msg->param, DC_PARAM_WIDTH)) {
unsigned char* buf = NULL; size_t buf_bytes; uint32_t w, h;
dc_param_set_int(mimefactory.msg->param, DC_PARAM_WIDTH, 0);
dc_param_set_int(mimefactory.msg->param, DC_PARAM_HEIGHT, 0);
if (dc_read_file(context, pathNfilename, (void**)&buf, &buf_bytes)) {
if (dc_get_filemeta(buf, buf_bytes, &w, &h)) {
dc_param_set_int(mimefactory.msg->param, DC_PARAM_WIDTH, w);
dc_param_set_int(mimefactory.msg->param, DC_PARAM_HEIGHT, h);
}
}
free(buf);
dc_msg_save_param_to_disk(mimefactory.msg);
}
}
free(pathNfilename);
}
/* create message */
{
if (!dc_mimefactory_render(&mimefactory)) {
dc_set_msg_failed(context, msg_id, mimefactory.error);
goto cleanup; // no redo, no IMAP - this will also fail next time
}
/* have we guaranteed encryption but cannot fulfill it for any reason? Do not send the message then.*/
if (dc_param_get_int(mimefactory.msg->param, DC_PARAM_GUARANTEE_E2EE, 0) && !mimefactory.out_encrypted) {
dc_set_msg_failed(context, msg_id, "End-to-end-encryption unavailable unexpectedly.");
goto cleanup; /* unrecoverable */
}
/* add SELF to the recipient list (it's no longer used elsewhere, so a copy of the whole list is needless) */
if (clist_search_string_nocase(mimefactory.recipients_addr, mimefactory.from_addr)==0) {
clist_append(mimefactory.recipients_names, NULL);
clist_append(mimefactory.recipients_addr, (void*)dc_strdup(mimefactory.from_addr));
}
}
dc_sqlite3_begin_transaction(context->sql);
if (mimefactory.out_gossiped) {
dc_set_gossiped_timestamp(context, mimefactory.msg->chat_id, time(NULL));
}
if (mimefactory.out_last_added_location_id) {
dc_set_kml_sent_timestamp(context, mimefactory.msg->chat_id, time(NULL));
if (!mimefactory.msg->hidden) {
dc_set_msg_location_id(context, mimefactory.msg->id, mimefactory.out_last_added_location_id);
}
}
if (mimefactory.out_encrypted && dc_param_get_int(mimefactory.msg->param, DC_PARAM_GUARANTEE_E2EE, 0)==0) {
dc_param_set_int(mimefactory.msg->param, DC_PARAM_GUARANTEE_E2EE, 1); /* can upgrade to E2EE - fine! */
dc_msg_save_param_to_disk(mimefactory.msg);
}
// TODO: add to keyhistory
dc_add_to_keyhistory(context, NULL, 0, NULL, NULL);
dc_sqlite3_commit(context->sql);
success = dc_add_smtp_job(context, DC_JOB_SEND_MSG_TO_SMTP, &mimefactory);
cleanup:
dc_mimefactory_empty(&mimefactory);
return success;
}
static void dc_job_do_DC_JOB_SEND(dc_context_t* context, dc_job_t* job)
{
char* filename = NULL;
void* buf = NULL;
size_t buf_bytes = 0;
char* recipients = NULL;
clist* recipients_list = NULL;
sqlite3_stmt* stmt = NULL;
/* connect to SMTP server, if not yet done */
if (!dc_smtp_is_connected(context->smtp)) {
dc_loginparam_t* loginparam = dc_loginparam_new();
dc_loginparam_read(loginparam, context->sql, "configured_");
int connected = dc_smtp_connect(context->smtp, loginparam);
dc_loginparam_unref(loginparam);
if (!connected) {
dc_job_try_again_later(job, DC_STANDARD_DELAY, NULL);
goto cleanup;
}
}
/* load message data */
filename = dc_param_get(job->param, DC_PARAM_FILE, NULL);
if (!filename) {
dc_log_warning(context, 0, "Missing file name for job %d", job->job_id);
goto cleanup;
}
if (!dc_read_file(context, filename, &buf, &buf_bytes)) {
goto cleanup;