text
stringlengths
0
357
clist_free_content(factory->recipients_addr);
clist_free(factory->recipients_addr);
factory->recipients_addr = NULL;
}
dc_msg_unref(factory->msg);
factory->msg = NULL;
dc_chat_unref(factory->chat);
factory->chat = NULL;
free(factory->in_reply_to);
factory->in_reply_to = NULL;
free(factory->references);
factory->references = NULL;
if (factory->out) {
mmap_string_free(factory->out);
factory->out = NULL;
}
factory->out_encrypted = 0;
factory->loaded = DC_MF_NOTHING_LOADED;
free(factory->error);
factory->error = NULL;
factory->timestamp = 0;
}
static void set_error(dc_mimefactory_t* factory, const char* text)
{
if (factory==NULL) {
return;
}
free(factory->error);
factory->error = dc_strdup_keep_null(text);
}
static void load_from(dc_mimefactory_t* factory)
{
factory->from_addr = dc_sqlite3_get_config(factory->context->sql, "configured_addr", NULL);
factory->from_displayname = dc_sqlite3_get_config(factory->context->sql, "displayname", NULL);
factory->selfstatus = dc_sqlite3_get_config(factory->context->sql, "selfstatus", NULL);
if (factory->selfstatus==NULL) {
factory->selfstatus = dc_stock_str(factory->context, DC_STR_STATUSLINE);
}
}
int dc_mimefactory_load_msg(dc_mimefactory_t* factory, uint32_t msg_id)
{
int success = 0;
sqlite3_stmt* stmt = NULL;
if (factory==NULL || msg_id <= DC_MSG_ID_LAST_SPECIAL
|| factory->context==NULL
|| factory->msg /*call empty() before */) {
goto cleanup;
}
dc_context_t* context = factory->context;
factory->recipients_names = clist_new();
factory->recipients_addr = clist_new();
factory->msg = dc_msg_new_untyped(context);
factory->chat = dc_chat_new(context);
if (dc_msg_load_from_db(factory->msg, context, msg_id)
&& dc_chat_load_from_db(factory->chat, factory->msg->chat_id))
{
load_from(factory);
factory->req_mdn = 0;
if (dc_chat_is_self_talk(factory->chat))
{
clist_append(factory->recipients_names, (void*)dc_strdup_keep_null(factory->from_displayname));
clist_append(factory->recipients_addr, (void*)dc_strdup(factory->from_addr));
}
else
{
stmt = dc_sqlite3_prepare(context->sql,
"SELECT c.authname, c.addr "
" FROM chats_contacts cc "
" LEFT JOIN contacts c ON cc.contact_id=c.id "
" WHERE cc.chat_id=? AND cc.contact_id>" DC_STRINGIFY(DC_CONTACT_ID_LAST_SPECIAL) ";");
sqlite3_bind_int(stmt, 1, factory->msg->chat_id);
while (sqlite3_step(stmt)==SQLITE_ROW)
{
const char* authname = (const char*)sqlite3_column_text(stmt, 0);
const char* addr = (const char*)sqlite3_column_text(stmt, 1);
if (clist_search_string_nocase(factory->recipients_addr, addr)==0)
{
clist_append(factory->recipients_names, (void*)((authname&&authname[0])? dc_strdup(authname) : NULL));
clist_append(factory->recipients_addr, (void*)dc_strdup(addr));