mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-05 10:39:27 +02:00
style
This commit is contained in:
parent
54a27e86f1
commit
5a0f7d3c3a
22 changed files with 593 additions and 593 deletions
|
@ -38,7 +38,7 @@
|
||||||
*/
|
*/
|
||||||
void dc_aheader_empty(dc_aheader_t* aheader)
|
void dc_aheader_empty(dc_aheader_t* aheader)
|
||||||
{
|
{
|
||||||
if (aheader == NULL) {
|
if (aheader==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ char* dc_aheader_render(const dc_aheader_t* aheader)
|
||||||
|
|
||||||
/* adds a whitespace every 78 characters, this allows libEtPan to wrap the lines according to RFC 5322
|
/* adds a whitespace every 78 characters, this allows libEtPan to wrap the lines according to RFC 5322
|
||||||
(which may insert a linebreak before every whitespace) */
|
(which may insert a linebreak before every whitespace) */
|
||||||
if ((keybase64_wrapped = dc_key_render_base64(aheader->public_key, 78, " ", 0/*no checksum*/)) == NULL) {
|
if ((keybase64_wrapped = dc_key_render_base64(aheader->public_key, 78, " ", 0/*no checksum*/))==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ static int add_attribute(dc_aheader_t* aheader, const char* name, const char* va
|
||||||
/* returns 0 if the attribute will result in an invalid header, 1 if the attribute is okay */
|
/* returns 0 if the attribute will result in an invalid header, 1 if the attribute is okay */
|
||||||
if (strcasecmp(name, "addr")==0)
|
if (strcasecmp(name, "addr")==0)
|
||||||
{
|
{
|
||||||
if (value == NULL
|
if (value==NULL
|
||||||
|| strlen(value) < 3 || strchr(value, '@')==NULL || strchr(value, '.')==NULL /* rough check if email-address is valid */
|
|| strlen(value) < 3 || strchr(value, '@')==NULL || strchr(value, '.')==NULL /* rough check if email-address is valid */
|
||||||
|| aheader->addr /* email already given */) {
|
|| aheader->addr /* email already given */) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -121,7 +121,7 @@ static int add_attribute(dc_aheader_t* aheader, const char* name, const char* va
|
||||||
#if 0 /* autocrypt 11/2017 no longer uses the type attribute and it will make the autocrypt header invalid */
|
#if 0 /* autocrypt 11/2017 no longer uses the type attribute and it will make the autocrypt header invalid */
|
||||||
else if (strcasecmp(name, "type")==0)
|
else if (strcasecmp(name, "type")==0)
|
||||||
{
|
{
|
||||||
if (value == NULL) {
|
if (value==NULL) {
|
||||||
return 0; /* attribute with no value results in an invalid header */
|
return 0; /* attribute with no value results in an invalid header */
|
||||||
}
|
}
|
||||||
if (strcasecmp(value, "1")==0 || strcasecmp(value, "0" /*deprecated*/)==0 || strcasecmp(value, "p" /*deprecated*/)==0) {
|
if (strcasecmp(value, "1")==0 || strcasecmp(value, "0" /*deprecated*/)==0 || strcasecmp(value, "p" /*deprecated*/)==0) {
|
||||||
|
@ -140,7 +140,7 @@ static int add_attribute(dc_aheader_t* aheader, const char* name, const char* va
|
||||||
}
|
}
|
||||||
else if (strcasecmp(name, "keydata")==0)
|
else if (strcasecmp(name, "keydata")==0)
|
||||||
{
|
{
|
||||||
if (value == NULL
|
if (value==NULL
|
||||||
|| aheader->public_key->binary || aheader->public_key->bytes) {
|
|| aheader->public_key->binary || aheader->public_key->bytes) {
|
||||||
return 0; /* there is already a k*/
|
return 0; /* there is already a k*/
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ int dc_aheader_set_from_string(dc_aheader_t* aheader, const char* header_str__)
|
||||||
|
|
||||||
dc_aheader_empty(aheader);
|
dc_aheader_empty(aheader);
|
||||||
|
|
||||||
if (aheader == NULL || header_str__ == NULL) {
|
if (aheader==NULL || header_str__==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,19 +191,19 @@ int dc_aheader_set_from_string(dc_aheader_t* aheader, const char* header_str__)
|
||||||
beg_attr_name = p;
|
beg_attr_name = p;
|
||||||
beg_attr_value = NULL;
|
beg_attr_value = NULL;
|
||||||
p += strcspn(p, AHEADER_WS "=;"); /* get end of attribute name (an attribute may have no value) */
|
p += strcspn(p, AHEADER_WS "=;"); /* get end of attribute name (an attribute may have no value) */
|
||||||
if (p != beg_attr_name)
|
if (p!=beg_attr_name)
|
||||||
{
|
{
|
||||||
/* attribute found */
|
/* attribute found */
|
||||||
after_attr_name = p;
|
after_attr_name = p;
|
||||||
p += strspn(p, AHEADER_WS); /* skip whitespace between attribute name and possible `=` */
|
p += strspn(p, AHEADER_WS); /* skip whitespace between attribute name and possible `=` */
|
||||||
if (*p == '=')
|
if (*p=='=')
|
||||||
{
|
{
|
||||||
p += strspn(p, AHEADER_WS "="); /* skip spaces and equal signs */
|
p += strspn(p, AHEADER_WS "="); /* skip spaces and equal signs */
|
||||||
|
|
||||||
/* read unquoted attribute value until the first semicolon */
|
/* read unquoted attribute value until the first semicolon */
|
||||||
beg_attr_value = p;
|
beg_attr_value = p;
|
||||||
p += strcspn(p, ";");
|
p += strcspn(p, ";");
|
||||||
if (*p != '\0') {
|
if (*p!='\0') {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
@ -277,14 +277,14 @@ dc_aheader_t* dc_aheader_new_from_imffields(const char* wanted_from, const struc
|
||||||
clistiter* cur = NULL;
|
clistiter* cur = NULL;
|
||||||
dc_aheader_t* fine_header = NULL;
|
dc_aheader_t* fine_header = NULL;
|
||||||
|
|
||||||
if (wanted_from == NULL || header == NULL) {
|
if (wanted_from==NULL || header==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (cur = clist_begin(header->fld_list); cur!=NULL ; cur=clist_next(cur))
|
for (cur = clist_begin(header->fld_list); cur!=NULL ; cur=clist_next(cur))
|
||||||
{
|
{
|
||||||
struct mailimf_field* field = (struct mailimf_field*)clist_content(cur);
|
struct mailimf_field* field = (struct mailimf_field*)clist_content(cur);
|
||||||
if (field && field->fld_type == MAILIMF_FIELD_OPTIONAL_FIELD)
|
if (field && field->fld_type==MAILIMF_FIELD_OPTIONAL_FIELD)
|
||||||
{
|
{
|
||||||
struct mailimf_optional_field* optional_field = field->fld_data.fld_optional_field;
|
struct mailimf_optional_field* optional_field = field->fld_data.fld_optional_field;
|
||||||
if (optional_field && optional_field->fld_name && strcasecmp(optional_field->fld_name, "Autocrypt")==0)
|
if (optional_field && optional_field->fld_name && strcasecmp(optional_field->fld_name, "Autocrypt")==0)
|
||||||
|
@ -297,7 +297,7 @@ dc_aheader_t* dc_aheader_new_from_imffields(const char* wanted_from, const struc
|
||||||
test = NULL;
|
test = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fine_header == NULL) {
|
if (fine_header==NULL) {
|
||||||
fine_header = test; /* may still be NULL */
|
fine_header = test; /* may still be NULL */
|
||||||
}
|
}
|
||||||
else if (test) {
|
else if (test) {
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
static void dc_apeerstate_empty(dc_apeerstate_t* peerstate)
|
static void dc_apeerstate_empty(dc_apeerstate_t* peerstate)
|
||||||
{
|
{
|
||||||
if (peerstate == NULL) {
|
if (peerstate==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ int dc_apeerstate_load_by_addr(dc_apeerstate_t* peerstate, dc_sqlite3_t* sql, co
|
||||||
int success = 0;
|
int success = 0;
|
||||||
sqlite3_stmt* stmt = NULL;
|
sqlite3_stmt* stmt = NULL;
|
||||||
|
|
||||||
if (peerstate==NULL || sql == NULL || addr == NULL) {
|
if (peerstate==NULL || sql==NULL || addr==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ int dc_apeerstate_load_by_addr(dc_apeerstate_t* peerstate, dc_sqlite3_t* sql, co
|
||||||
" FROM acpeerstates "
|
" FROM acpeerstates "
|
||||||
" WHERE addr=? COLLATE NOCASE;");
|
" WHERE addr=? COLLATE NOCASE;");
|
||||||
sqlite3_bind_text(stmt, 1, addr, -1, SQLITE_STATIC);
|
sqlite3_bind_text(stmt, 1, addr, -1, SQLITE_STATIC);
|
||||||
if (sqlite3_step(stmt) != SQLITE_ROW) {
|
if (sqlite3_step(stmt)!=SQLITE_ROW) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
dc_apeerstate_set_from_stmt(peerstate, stmt);
|
dc_apeerstate_set_from_stmt(peerstate, stmt);
|
||||||
|
@ -141,7 +141,7 @@ int dc_apeerstate_load_by_fingerprint(dc_apeerstate_t* peerstate, dc_sqlite3_t*
|
||||||
int success = 0;
|
int success = 0;
|
||||||
sqlite3_stmt* stmt = NULL;
|
sqlite3_stmt* stmt = NULL;
|
||||||
|
|
||||||
if (peerstate==NULL || sql == NULL || fingerprint == NULL) {
|
if (peerstate==NULL || sql==NULL || fingerprint==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ int dc_apeerstate_load_by_fingerprint(dc_apeerstate_t* peerstate, dc_sqlite3_t*
|
||||||
sqlite3_bind_text(stmt, 1, fingerprint, -1, SQLITE_STATIC);
|
sqlite3_bind_text(stmt, 1, fingerprint, -1, SQLITE_STATIC);
|
||||||
sqlite3_bind_text(stmt, 2, fingerprint, -1, SQLITE_STATIC);
|
sqlite3_bind_text(stmt, 2, fingerprint, -1, SQLITE_STATIC);
|
||||||
sqlite3_bind_text(stmt, 3, fingerprint, -1, SQLITE_STATIC);
|
sqlite3_bind_text(stmt, 3, fingerprint, -1, SQLITE_STATIC);
|
||||||
if (sqlite3_step(stmt) != SQLITE_ROW) {
|
if (sqlite3_step(stmt)!=SQLITE_ROW) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
dc_apeerstate_set_from_stmt(peerstate, stmt);
|
dc_apeerstate_set_from_stmt(peerstate, stmt);
|
||||||
|
@ -204,7 +204,7 @@ int dc_apeerstate_save_to_db(const dc_apeerstate_t* peerstate, dc_sqlite3_t* sql
|
||||||
sqlite3_bind_blob (stmt, 9, peerstate->verified_key? peerstate->verified_key->binary : NULL/*results in sqlite3_bind_null()*/, peerstate->verified_key? peerstate->verified_key->bytes : 0, SQLITE_STATIC);
|
sqlite3_bind_blob (stmt, 9, peerstate->verified_key? peerstate->verified_key->binary : NULL/*results in sqlite3_bind_null()*/, peerstate->verified_key? peerstate->verified_key->bytes : 0, SQLITE_STATIC);
|
||||||
sqlite3_bind_text (stmt,10, peerstate->verified_key_fingerprint, -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt,10, peerstate->verified_key_fingerprint, -1, SQLITE_STATIC);
|
||||||
sqlite3_bind_text (stmt,11, peerstate->addr, -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt,11, peerstate->addr, -1, SQLITE_STATIC);
|
||||||
if (sqlite3_step(stmt) != SQLITE_DONE) {
|
if (sqlite3_step(stmt)!=SQLITE_DONE) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
|
@ -218,7 +218,7 @@ int dc_apeerstate_save_to_db(const dc_apeerstate_t* peerstate, dc_sqlite3_t* sql
|
||||||
sqlite3_bind_int64(stmt, 2, peerstate->last_seen_autocrypt);
|
sqlite3_bind_int64(stmt, 2, peerstate->last_seen_autocrypt);
|
||||||
sqlite3_bind_int64(stmt, 3, peerstate->gossip_timestamp);
|
sqlite3_bind_int64(stmt, 3, peerstate->gossip_timestamp);
|
||||||
sqlite3_bind_text (stmt, 4, peerstate->addr, -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt, 4, peerstate->addr, -1, SQLITE_STATIC);
|
||||||
if (sqlite3_step(stmt) != SQLITE_DONE) {
|
if (sqlite3_step(stmt)!=SQLITE_DONE) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
|
@ -282,7 +282,7 @@ char* dc_apeerstate_render_gossip_header(const dc_apeerstate_t* peerstate, int m
|
||||||
char* ret = NULL;
|
char* ret = NULL;
|
||||||
dc_aheader_t* autocryptheader = dc_aheader_new();
|
dc_aheader_t* autocryptheader = dc_aheader_new();
|
||||||
|
|
||||||
if (peerstate == NULL || peerstate->addr == NULL) {
|
if (peerstate==NULL || peerstate->addr==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,7 +318,7 @@ cleanup:
|
||||||
*/
|
*/
|
||||||
dc_key_t* dc_apeerstate_peek_key(const dc_apeerstate_t* peerstate, int min_verified)
|
dc_key_t* dc_apeerstate_peek_key(const dc_apeerstate_t* peerstate, int min_verified)
|
||||||
{
|
{
|
||||||
if ( peerstate == NULL
|
if ( peerstate==NULL
|
||||||
|| (peerstate->public_key && (peerstate->public_key->binary==NULL || peerstate->public_key->bytes<=0))
|
|| (peerstate->public_key && (peerstate->public_key->binary==NULL || peerstate->public_key->bytes<=0))
|
||||||
|| (peerstate->gossip_key && (peerstate->gossip_key->binary==NULL || peerstate->gossip_key->bytes<=0))
|
|| (peerstate->gossip_key && (peerstate->gossip_key->binary==NULL || peerstate->gossip_key->bytes<=0))
|
||||||
|| (peerstate->verified_key && (peerstate->verified_key->binary==NULL || peerstate->verified_key->bytes<=0))) {
|
|| (peerstate->verified_key && (peerstate->verified_key->binary==NULL || peerstate->verified_key->bytes<=0))) {
|
||||||
|
@ -346,7 +346,7 @@ dc_key_t* dc_apeerstate_peek_key(const dc_apeerstate_t* peerstate, int min_verif
|
||||||
|
|
||||||
int dc_apeerstate_init_from_header(dc_apeerstate_t* peerstate, const dc_aheader_t* header, time_t message_time)
|
int dc_apeerstate_init_from_header(dc_apeerstate_t* peerstate, const dc_aheader_t* header, time_t message_time)
|
||||||
{
|
{
|
||||||
if (peerstate == NULL || header == NULL) {
|
if (peerstate==NULL || header==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +367,7 @@ int dc_apeerstate_init_from_header(dc_apeerstate_t* peerstate, const dc_aheader_
|
||||||
|
|
||||||
int dc_apeerstate_init_from_gossip(dc_apeerstate_t* peerstate, const dc_aheader_t* gossip_header, time_t message_time)
|
int dc_apeerstate_init_from_gossip(dc_apeerstate_t* peerstate, const dc_aheader_t* gossip_header, time_t message_time)
|
||||||
{
|
{
|
||||||
if (peerstate == NULL || gossip_header == NULL) {
|
if (peerstate==NULL || gossip_header==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ int dc_apeerstate_degrade_encryption(dc_apeerstate_t* peerstate, time_t message_
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peerstate->prefer_encrypt == DC_PE_MUTUAL) {
|
if (peerstate->prefer_encrypt==DC_PE_MUTUAL) {
|
||||||
peerstate->degrade_event |= DC_DE_ENCRYPTION_PAUSED;
|
peerstate->degrade_event |= DC_DE_ENCRYPTION_PAUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,9 +418,9 @@ void dc_apeerstate_apply_header(dc_apeerstate_t* peerstate, const dc_aheader_t*
|
||||||
peerstate->to_save |= DC_SAVE_TIMESTAMPS;
|
peerstate->to_save |= DC_SAVE_TIMESTAMPS;
|
||||||
|
|
||||||
if ((header->prefer_encrypt==DC_PE_MUTUAL || header->prefer_encrypt==DC_PE_NOPREFERENCE) /*this also switches from DC_PE_RESET to DC_PE_NOPREFERENCE, which is just fine as the function is only called _if_ the Autocrypt:-header is preset at all */
|
if ((header->prefer_encrypt==DC_PE_MUTUAL || header->prefer_encrypt==DC_PE_NOPREFERENCE) /*this also switches from DC_PE_RESET to DC_PE_NOPREFERENCE, which is just fine as the function is only called _if_ the Autocrypt:-header is preset at all */
|
||||||
&& header->prefer_encrypt != peerstate->prefer_encrypt)
|
&& header->prefer_encrypt!=peerstate->prefer_encrypt)
|
||||||
{
|
{
|
||||||
if (peerstate->prefer_encrypt == DC_PE_MUTUAL && header->prefer_encrypt != DC_PE_MUTUAL) {
|
if (peerstate->prefer_encrypt==DC_PE_MUTUAL && header->prefer_encrypt!=DC_PE_MUTUAL) {
|
||||||
peerstate->degrade_event |= DC_DE_ENCRYPTION_PAUSED;
|
peerstate->degrade_event |= DC_DE_ENCRYPTION_PAUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,7 +428,7 @@ void dc_apeerstate_apply_header(dc_apeerstate_t* peerstate, const dc_aheader_t*
|
||||||
peerstate->to_save |= DC_SAVE_ALL;
|
peerstate->to_save |= DC_SAVE_ALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peerstate->public_key == NULL) {
|
if (peerstate->public_key==NULL) {
|
||||||
peerstate->public_key = dc_key_new();
|
peerstate->public_key = dc_key_new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,7 +456,7 @@ void dc_apeerstate_apply_gossip(dc_apeerstate_t* peerstate, const dc_aheader_t*
|
||||||
peerstate->gossip_timestamp = message_time;
|
peerstate->gossip_timestamp = message_time;
|
||||||
peerstate->to_save |= DC_SAVE_TIMESTAMPS;
|
peerstate->to_save |= DC_SAVE_TIMESTAMPS;
|
||||||
|
|
||||||
if (peerstate->gossip_key == NULL) {
|
if (peerstate->gossip_key==NULL) {
|
||||||
peerstate->gossip_key = dc_key_new();
|
peerstate->gossip_key = dc_key_new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,7 +485,7 @@ int dc_apeerstate_recalc_fingerprint(dc_apeerstate_t* peerstate)
|
||||||
char* old_public_fingerprint = NULL;
|
char* old_public_fingerprint = NULL;
|
||||||
char* old_gossip_fingerprint = NULL;
|
char* old_gossip_fingerprint = NULL;
|
||||||
|
|
||||||
if (peerstate == NULL) {
|
if (peerstate==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,11 +494,11 @@ int dc_apeerstate_recalc_fingerprint(dc_apeerstate_t* peerstate)
|
||||||
old_public_fingerprint = peerstate->public_key_fingerprint;
|
old_public_fingerprint = peerstate->public_key_fingerprint;
|
||||||
peerstate->public_key_fingerprint = dc_key_get_fingerprint(peerstate->public_key); /* returns the empty string for errors, however, this should be saved as well as it represents an erroneous key */
|
peerstate->public_key_fingerprint = dc_key_get_fingerprint(peerstate->public_key); /* returns the empty string for errors, however, this should be saved as well as it represents an erroneous key */
|
||||||
|
|
||||||
if (old_public_fingerprint == NULL
|
if (old_public_fingerprint==NULL
|
||||||
|| old_public_fingerprint[0] == 0
|
|| old_public_fingerprint[0]==0
|
||||||
|| peerstate->public_key_fingerprint == NULL
|
|| peerstate->public_key_fingerprint==NULL
|
||||||
|| peerstate->public_key_fingerprint[0] == 0
|
|| peerstate->public_key_fingerprint[0]==0
|
||||||
|| strcasecmp(old_public_fingerprint, peerstate->public_key_fingerprint) != 0)
|
|| strcasecmp(old_public_fingerprint, peerstate->public_key_fingerprint)!=0)
|
||||||
{
|
{
|
||||||
peerstate->to_save |= DC_SAVE_ALL;
|
peerstate->to_save |= DC_SAVE_ALL;
|
||||||
|
|
||||||
|
@ -513,11 +513,11 @@ int dc_apeerstate_recalc_fingerprint(dc_apeerstate_t* peerstate)
|
||||||
old_gossip_fingerprint = peerstate->gossip_key_fingerprint;
|
old_gossip_fingerprint = peerstate->gossip_key_fingerprint;
|
||||||
peerstate->gossip_key_fingerprint = dc_key_get_fingerprint(peerstate->gossip_key); /* returns the empty string for errors, however, this should be saved as well as it represents an erroneous key */
|
peerstate->gossip_key_fingerprint = dc_key_get_fingerprint(peerstate->gossip_key); /* returns the empty string for errors, however, this should be saved as well as it represents an erroneous key */
|
||||||
|
|
||||||
if (old_gossip_fingerprint == NULL
|
if (old_gossip_fingerprint==NULL
|
||||||
|| old_gossip_fingerprint[0] == 0
|
|| old_gossip_fingerprint[0]==0
|
||||||
|| peerstate->gossip_key_fingerprint == NULL
|
|| peerstate->gossip_key_fingerprint==NULL
|
||||||
|| peerstate->gossip_key_fingerprint[0] == 0
|
|| peerstate->gossip_key_fingerprint[0]==0
|
||||||
|| strcasecmp(old_gossip_fingerprint, peerstate->gossip_key_fingerprint) != 0)
|
|| strcasecmp(old_gossip_fingerprint, peerstate->gossip_key_fingerprint)!=0)
|
||||||
{
|
{
|
||||||
peerstate->to_save |= DC_SAVE_ALL;
|
peerstate->to_save |= DC_SAVE_ALL;
|
||||||
|
|
||||||
|
@ -560,17 +560,17 @@ int dc_apeerstate_set_verified(dc_apeerstate_t* peerstate, int which_key, const
|
||||||
{
|
{
|
||||||
int success = 0;
|
int success = 0;
|
||||||
|
|
||||||
if (peerstate == NULL
|
if (peerstate==NULL
|
||||||
|| (which_key!=DC_PS_GOSSIP_KEY && which_key!=DC_PS_PUBLIC_KEY)
|
|| (which_key!=DC_PS_GOSSIP_KEY && which_key!=DC_PS_PUBLIC_KEY)
|
||||||
|| (verified!=DC_BIDIRECT_VERIFIED)) {
|
|| (verified!=DC_BIDIRECT_VERIFIED)) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (which_key == DC_PS_PUBLIC_KEY
|
if (which_key==DC_PS_PUBLIC_KEY
|
||||||
&& peerstate->public_key_fingerprint != NULL
|
&& peerstate->public_key_fingerprint!=NULL
|
||||||
&& peerstate->public_key_fingerprint[0] != 0
|
&& peerstate->public_key_fingerprint[0]!=0
|
||||||
&& fingerprint[0] != 0
|
&& fingerprint[0]!=0
|
||||||
&& strcasecmp(peerstate->public_key_fingerprint, fingerprint) == 0)
|
&& strcasecmp(peerstate->public_key_fingerprint, fingerprint)==0)
|
||||||
{
|
{
|
||||||
peerstate->to_save |= DC_SAVE_ALL;
|
peerstate->to_save |= DC_SAVE_ALL;
|
||||||
peerstate->verified_key = dc_key_ref(peerstate->public_key);
|
peerstate->verified_key = dc_key_ref(peerstate->public_key);
|
||||||
|
@ -578,11 +578,11 @@ int dc_apeerstate_set_verified(dc_apeerstate_t* peerstate, int which_key, const
|
||||||
success = 1;
|
success = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (which_key == DC_PS_GOSSIP_KEY
|
if (which_key==DC_PS_GOSSIP_KEY
|
||||||
&& peerstate->gossip_key_fingerprint != NULL
|
&& peerstate->gossip_key_fingerprint!=NULL
|
||||||
&& peerstate->gossip_key_fingerprint[0] != 0
|
&& peerstate->gossip_key_fingerprint[0]!=0
|
||||||
&& fingerprint[0] != 0
|
&& fingerprint[0]!=0
|
||||||
&& strcasecmp(peerstate->gossip_key_fingerprint, fingerprint) == 0)
|
&& strcasecmp(peerstate->gossip_key_fingerprint, fingerprint)==0)
|
||||||
{
|
{
|
||||||
peerstate->to_save |= DC_SAVE_ALL;
|
peerstate->to_save |= DC_SAVE_ALL;
|
||||||
peerstate->verified_key = dc_key_ref(peerstate->gossip_key);
|
peerstate->verified_key = dc_key_ref(peerstate->gossip_key);
|
||||||
|
@ -597,7 +597,7 @@ cleanup:
|
||||||
|
|
||||||
int dc_apeerstate_has_verified_key(const dc_apeerstate_t* peerstate, const dc_hash_t* fingerprints)
|
int dc_apeerstate_has_verified_key(const dc_apeerstate_t* peerstate, const dc_hash_t* fingerprints)
|
||||||
{
|
{
|
||||||
if (peerstate == NULL || fingerprints == NULL) {
|
if (peerstate==NULL || fingerprints==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ dc_array_t* dc_array_new(dc_context_t* context, size_t initsize)
|
||||||
array->magic = DC_ARRAY_MAGIC;
|
array->magic = DC_ARRAY_MAGIC;
|
||||||
array->context = context;
|
array->context = context;
|
||||||
array->count = 0;
|
array->count = 0;
|
||||||
array->allocated = initsize < 1? 1 : initsize;
|
array->allocated = initsize<1? 1 : initsize;
|
||||||
array->array = malloc(array->allocated * sizeof(uintptr_t));
|
array->array = malloc(array->allocated * sizeof(uintptr_t));
|
||||||
if (array->array==NULL) {
|
if (array->array==NULL) {
|
||||||
exit(48);
|
exit(48);
|
||||||
|
@ -70,7 +70,7 @@ dc_array_t* dc_array_new(dc_context_t* context, size_t initsize)
|
||||||
*/
|
*/
|
||||||
void dc_array_unref(dc_array_t* array)
|
void dc_array_unref(dc_array_t* array)
|
||||||
{
|
{
|
||||||
if (array==NULL || array->magic != DC_ARRAY_MAGIC) {
|
if (array==NULL || array->magic!=DC_ARRAY_MAGIC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,11 +93,11 @@ void dc_array_unref(dc_array_t* array)
|
||||||
*/
|
*/
|
||||||
void dc_array_free_ptr(dc_array_t* array)
|
void dc_array_free_ptr(dc_array_t* array)
|
||||||
{
|
{
|
||||||
if (array==NULL || array->magic != DC_ARRAY_MAGIC) {
|
if (array==NULL || array->magic!=DC_ARRAY_MAGIC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < array->count; i++) {
|
for (size_t i = 0; i<array->count; i++) {
|
||||||
free((void*)array->array[i]);
|
free((void*)array->array[i]);
|
||||||
array->array[i] = 0;
|
array->array[i] = 0;
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ dc_array_t* dc_array_duplicate(const dc_array_t* array)
|
||||||
{
|
{
|
||||||
dc_array_t* ret = NULL;
|
dc_array_t* ret = NULL;
|
||||||
|
|
||||||
if (array==NULL || array->magic != DC_ARRAY_MAGIC) {
|
if (array==NULL || array->magic!=DC_ARRAY_MAGIC) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ static int cmp_intptr_t(const void* p1, const void* p2)
|
||||||
*/
|
*/
|
||||||
void dc_array_sort_ids(dc_array_t* array)
|
void dc_array_sort_ids(dc_array_t* array)
|
||||||
{
|
{
|
||||||
if (array == NULL || array->magic != DC_ARRAY_MAGIC || array->count <= 1) {
|
if (array==NULL || array->magic!=DC_ARRAY_MAGIC || array->count <= 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qsort(array->array, array->count, sizeof(uintptr_t), cmp_intptr_t);
|
qsort(array->array, array->count, sizeof(uintptr_t), cmp_intptr_t);
|
||||||
|
@ -178,7 +178,7 @@ static int cmp_strings_t(const void* p1, const void* p2)
|
||||||
*/
|
*/
|
||||||
void dc_array_sort_strings(dc_array_t* array)
|
void dc_array_sort_strings(dc_array_t* array)
|
||||||
{
|
{
|
||||||
if (array == NULL || array->magic != DC_ARRAY_MAGIC || array->count <= 1) {
|
if (array==NULL || array->magic!=DC_ARRAY_MAGIC || array->count <= 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qsort(array->array, array->count, sizeof(char*), cmp_strings_t);
|
qsort(array->array, array->count, sizeof(char*), cmp_strings_t);
|
||||||
|
@ -196,7 +196,7 @@ void dc_array_sort_strings(dc_array_t* array)
|
||||||
*/
|
*/
|
||||||
void dc_array_empty(dc_array_t* array)
|
void dc_array_empty(dc_array_t* array)
|
||||||
{
|
{
|
||||||
if (array == NULL || array->magic != DC_ARRAY_MAGIC) {
|
if (array==NULL || array->magic!=DC_ARRAY_MAGIC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,11 +217,11 @@ void dc_array_empty(dc_array_t* array)
|
||||||
*/
|
*/
|
||||||
void dc_array_add_uint(dc_array_t* array, uintptr_t item)
|
void dc_array_add_uint(dc_array_t* array, uintptr_t item)
|
||||||
{
|
{
|
||||||
if (array == NULL || array->magic != DC_ARRAY_MAGIC) {
|
if (array==NULL || array->magic!=DC_ARRAY_MAGIC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array->count == array->allocated) {
|
if (array->count==array->allocated) {
|
||||||
int newsize = (array->allocated * 2) + 10;
|
int newsize = (array->allocated * 2) + 10;
|
||||||
if ((array->array=realloc(array->array, newsize*sizeof(uintptr_t)))==NULL) {
|
if ((array->array=realloc(array->array, newsize*sizeof(uintptr_t)))==NULL) {
|
||||||
exit(49);
|
exit(49);
|
||||||
|
@ -279,7 +279,7 @@ void dc_array_add_ptr(dc_array_t* array, void* item)
|
||||||
*/
|
*/
|
||||||
size_t dc_array_get_cnt(const dc_array_t* array)
|
size_t dc_array_get_cnt(const dc_array_t* array)
|
||||||
{
|
{
|
||||||
if (array == NULL || array->magic != DC_ARRAY_MAGIC) {
|
if (array==NULL || array->magic!=DC_ARRAY_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,7 +300,7 @@ size_t dc_array_get_cnt(const dc_array_t* array)
|
||||||
*/
|
*/
|
||||||
uintptr_t dc_array_get_uint(const dc_array_t* array, size_t index)
|
uintptr_t dc_array_get_uint(const dc_array_t* array, size_t index)
|
||||||
{
|
{
|
||||||
if (array == NULL || array->magic != DC_ARRAY_MAGIC || index < 0 || index >= array->count) {
|
if (array==NULL || array->magic!=DC_ARRAY_MAGIC || index<0 || index>=array->count) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,7 +320,7 @@ uintptr_t dc_array_get_uint(const dc_array_t* array, size_t index)
|
||||||
*/
|
*/
|
||||||
uint32_t dc_array_get_id(const dc_array_t* array, size_t index)
|
uint32_t dc_array_get_id(const dc_array_t* array, size_t index)
|
||||||
{
|
{
|
||||||
if (array == NULL || array->magic != DC_ARRAY_MAGIC || index < 0 || index >= array->count) {
|
if (array==NULL || array->magic!=DC_ARRAY_MAGIC || index<0 || index>=array->count) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ uint32_t dc_array_get_id(const dc_array_t* array, size_t index)
|
||||||
*/
|
*/
|
||||||
void* dc_array_get_ptr(const dc_array_t* array, size_t index)
|
void* dc_array_get_ptr(const dc_array_t* array, size_t index)
|
||||||
{
|
{
|
||||||
if (array == NULL || array->magic != DC_ARRAY_MAGIC || index < 0 || index >= array->count) {
|
if (array==NULL || array->magic!=DC_ARRAY_MAGIC || index<0 || index>=array->count) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,7 +361,7 @@ void* dc_array_get_ptr(const dc_array_t* array, size_t index)
|
||||||
*/
|
*/
|
||||||
int dc_array_search_id(const dc_array_t* array, uint32_t needle, size_t* ret_index)
|
int dc_array_search_id(const dc_array_t* array, uint32_t needle, size_t* ret_index)
|
||||||
{
|
{
|
||||||
if (array == NULL || array->magic != DC_ARRAY_MAGIC) {
|
if (array==NULL || array->magic!=DC_ARRAY_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ int dc_array_search_id(const dc_array_t* array, uint32_t needle, size_t* ret_ind
|
||||||
size_t i, cnt = array->count;
|
size_t i, cnt = array->count;
|
||||||
for (i=0; i<cnt; i++)
|
for (i=0; i<cnt; i++)
|
||||||
{
|
{
|
||||||
if (data[i] == needle) {
|
if (data[i]==needle) {
|
||||||
if (ret_index) {
|
if (ret_index) {
|
||||||
*ret_index = i;
|
*ret_index = i;
|
||||||
}
|
}
|
||||||
|
@ -393,7 +393,7 @@ int dc_array_search_id(const dc_array_t* array, uint32_t needle, size_t* ret_ind
|
||||||
*/
|
*/
|
||||||
const uintptr_t* dc_array_get_raw(const dc_array_t* array)
|
const uintptr_t* dc_array_get_raw(const dc_array_t* array)
|
||||||
{
|
{
|
||||||
if (array == NULL || array->magic != DC_ARRAY_MAGIC) {
|
if (array==NULL || array->magic!=DC_ARRAY_MAGIC) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return array->array;
|
return array->array;
|
||||||
|
@ -414,7 +414,7 @@ char* dc_arr_to_string(const uint32_t* arr, int cnt)
|
||||||
#define INT_ARR_TO_STR(a, c) { \
|
#define INT_ARR_TO_STR(a, c) { \
|
||||||
int i; \
|
int i; \
|
||||||
ret = malloc((c)*(11+strlen(sep))/*sign,10 digits,sep*/+1/*terminating zero*/); \
|
ret = malloc((c)*(11+strlen(sep))/*sign,10 digits,sep*/+1/*terminating zero*/); \
|
||||||
if (ret == NULL) { exit(35); } \
|
if (ret==NULL) { exit(35); } \
|
||||||
ret[0] = 0; \
|
ret[0] = 0; \
|
||||||
for (i=0; i<(c); i++) { \
|
for (i=0; i<(c); i++) { \
|
||||||
if (i) { \
|
if (i) { \
|
||||||
|
@ -434,7 +434,7 @@ char* dc_array_get_string(const dc_array_t* array, const char* sep)
|
||||||
{
|
{
|
||||||
char* ret = NULL;
|
char* ret = NULL;
|
||||||
|
|
||||||
if (array == NULL || array->magic != DC_ARRAY_MAGIC || sep==NULL) {
|
if (array==NULL || array->magic!=DC_ARRAY_MAGIC || sep==NULL) {
|
||||||
return dc_strdup("");
|
return dc_strdup("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ dc_chatlist_t* dc_chatlist_new(dc_context_t* context)
|
||||||
*/
|
*/
|
||||||
void dc_chatlist_unref(dc_chatlist_t* chatlist)
|
void dc_chatlist_unref(dc_chatlist_t* chatlist)
|
||||||
{
|
{
|
||||||
if (chatlist==NULL || chatlist->magic != DC_CHATLIST_MAGIC) {
|
if (chatlist==NULL || chatlist->magic!=DC_CHATLIST_MAGIC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ void dc_chatlist_unref(dc_chatlist_t* chatlist)
|
||||||
*/
|
*/
|
||||||
void dc_chatlist_empty(dc_chatlist_t* chatlist)
|
void dc_chatlist_empty(dc_chatlist_t* chatlist)
|
||||||
{
|
{
|
||||||
if (chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC) {
|
if (chatlist==NULL || chatlist->magic!=DC_CHATLIST_MAGIC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ void dc_chatlist_empty(dc_chatlist_t* chatlist)
|
||||||
*/
|
*/
|
||||||
size_t dc_chatlist_get_cnt(const dc_chatlist_t* chatlist)
|
size_t dc_chatlist_get_cnt(const dc_chatlist_t* chatlist)
|
||||||
{
|
{
|
||||||
if (chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC) {
|
if (chatlist==NULL || chatlist->magic!=DC_CHATLIST_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ size_t dc_chatlist_get_cnt(const dc_chatlist_t* chatlist)
|
||||||
*/
|
*/
|
||||||
uint32_t dc_chatlist_get_chat_id(const dc_chatlist_t* chatlist, size_t index)
|
uint32_t dc_chatlist_get_chat_id(const dc_chatlist_t* chatlist, size_t index)
|
||||||
{
|
{
|
||||||
if (chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC || chatlist->chatNlastmsg_ids == NULL || index >= chatlist->cnt) {
|
if (chatlist==NULL || chatlist->magic!=DC_CHATLIST_MAGIC || chatlist->chatNlastmsg_ids==NULL || index>=chatlist->cnt) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ uint32_t dc_chatlist_get_chat_id(const dc_chatlist_t* chatlist, size_t index)
|
||||||
*/
|
*/
|
||||||
uint32_t dc_chatlist_get_msg_id(const dc_chatlist_t* chatlist, size_t index)
|
uint32_t dc_chatlist_get_msg_id(const dc_chatlist_t* chatlist, size_t index)
|
||||||
{
|
{
|
||||||
if (chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC || chatlist->chatNlastmsg_ids == NULL || index >= chatlist->cnt) {
|
if (chatlist==NULL || chatlist->magic!=DC_CHATLIST_MAGIC || chatlist->chatNlastmsg_ids==NULL || index>=chatlist->cnt) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ dc_lot_t* dc_chatlist_get_summary(const dc_chatlist_t* chatlist, size_t index, d
|
||||||
dc_contact_t* lastcontact = NULL;
|
dc_contact_t* lastcontact = NULL;
|
||||||
dc_chat_t* chat_to_delete = NULL;
|
dc_chat_t* chat_to_delete = NULL;
|
||||||
|
|
||||||
if (chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC || index >= chatlist->cnt) {
|
if (chatlist==NULL || chatlist->magic!=DC_CHATLIST_MAGIC || index>=chatlist->cnt) {
|
||||||
ret->text2 = dc_strdup("ErrBadChatlistIndex");
|
ret->text2 = dc_strdup("ErrBadChatlistIndex");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -226,14 +226,14 @@ dc_lot_t* dc_chatlist_get_summary(const dc_chatlist_t* chatlist, size_t index, d
|
||||||
lastmsg = dc_msg_new();
|
lastmsg = dc_msg_new();
|
||||||
dc_msg_load_from_db(lastmsg, chatlist->context, lastmsg_id);
|
dc_msg_load_from_db(lastmsg, chatlist->context, lastmsg_id);
|
||||||
|
|
||||||
if (lastmsg->from_id != DC_CONTACT_ID_SELF && DC_CHAT_TYPE_IS_MULTI(chat->type))
|
if (lastmsg->from_id!=DC_CONTACT_ID_SELF && DC_CHAT_TYPE_IS_MULTI(chat->type))
|
||||||
{
|
{
|
||||||
lastcontact = dc_contact_new(chatlist->context);
|
lastcontact = dc_contact_new(chatlist->context);
|
||||||
dc_contact_load_from_db(lastcontact, chatlist->context->sql, lastmsg->from_id);
|
dc_contact_load_from_db(lastcontact, chatlist->context->sql, lastmsg->from_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chat->id == DC_CHAT_ID_ARCHIVED_LINK)
|
if (chat->id==DC_CHAT_ID_ARCHIVED_LINK)
|
||||||
{
|
{
|
||||||
ret->text2 = dc_strdup(NULL);
|
ret->text2 = dc_strdup(NULL);
|
||||||
}
|
}
|
||||||
|
@ -250,7 +250,7 @@ dc_lot_t* dc_chatlist_get_summary(const dc_chatlist_t* chatlist, size_t index, d
|
||||||
|
|
||||||
ret->timestamp = chat->draft_timestamp;
|
ret->timestamp = chat->draft_timestamp;
|
||||||
}
|
}
|
||||||
else if (lastmsg == NULL || lastmsg->from_id == 0)
|
else if (lastmsg==NULL || lastmsg->from_id==0)
|
||||||
{
|
{
|
||||||
/* no messages */
|
/* no messages */
|
||||||
ret->text2 = dc_stock_str(chatlist->context, DC_STR_NOMESSAGES);
|
ret->text2 = dc_stock_str(chatlist->context, DC_STR_NOMESSAGES);
|
||||||
|
@ -280,7 +280,7 @@ cleanup:
|
||||||
*/
|
*/
|
||||||
dc_context_t* dc_chatlist_get_context(dc_chatlist_t* chatlist)
|
dc_context_t* dc_chatlist_get_context(dc_chatlist_t* chatlist)
|
||||||
{
|
{
|
||||||
if (chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC) {
|
if (chatlist==NULL || chatlist->magic!=DC_CHATLIST_MAGIC) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return chatlist->context;
|
return chatlist->context;
|
||||||
|
@ -330,7 +330,7 @@ int dc_chatlist_load_from_db(dc_chatlist_t* chatlist, int listflags, const char*
|
||||||
char* strLikeCmd = NULL;
|
char* strLikeCmd = NULL;
|
||||||
char* query = NULL;
|
char* query = NULL;
|
||||||
|
|
||||||
if (chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC || chatlist->context == NULL) {
|
if (chatlist==NULL || chatlist->magic!=DC_CHATLIST_MAGIC || chatlist->context==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ int dc_chatlist_load_from_db(dc_chatlist_t* chatlist, int listflags, const char*
|
||||||
sqlite3_bind_text(stmt, 1, strLikeCmd, -1, SQLITE_STATIC);
|
sqlite3_bind_text(stmt, 1, strLikeCmd, -1, SQLITE_STATIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (sqlite3_step(stmt) == SQLITE_ROW)
|
while (sqlite3_step(stmt)==SQLITE_ROW)
|
||||||
{
|
{
|
||||||
dc_array_add_id(chatlist->chatNlastmsg_ids, sqlite3_column_int(stmt, 0));
|
dc_array_add_id(chatlist->chatNlastmsg_ids, sqlite3_column_int(stmt, 0));
|
||||||
dc_array_add_id(chatlist->chatNlastmsg_ids, sqlite3_column_int(stmt, 1));
|
dc_array_add_id(chatlist->chatNlastmsg_ids, sqlite3_column_int(stmt, 1));
|
||||||
|
|
|
@ -62,7 +62,7 @@ dc_contact_t* dc_contact_new(dc_context_t* context)
|
||||||
*/
|
*/
|
||||||
void dc_contact_unref(dc_contact_t* contact)
|
void dc_contact_unref(dc_contact_t* contact)
|
||||||
{
|
{
|
||||||
if (contact==NULL || contact->magic != DC_CONTACT_MAGIC) {
|
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ void dc_contact_unref(dc_contact_t* contact)
|
||||||
*/
|
*/
|
||||||
void dc_contact_empty(dc_contact_t* contact)
|
void dc_contact_empty(dc_contact_t* contact)
|
||||||
{
|
{
|
||||||
if (contact == NULL || contact->magic != DC_CONTACT_MAGIC) {
|
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ void dc_contact_empty(dc_contact_t* contact)
|
||||||
*/
|
*/
|
||||||
uint32_t dc_contact_get_id(const dc_contact_t* contact)
|
uint32_t dc_contact_get_id(const dc_contact_t* contact)
|
||||||
{
|
{
|
||||||
if (contact == NULL || contact->magic != DC_CONTACT_MAGIC) {
|
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return contact->id;
|
return contact->id;
|
||||||
|
@ -128,7 +128,7 @@ uint32_t dc_contact_get_id(const dc_contact_t* contact)
|
||||||
*/
|
*/
|
||||||
char* dc_contact_get_addr(const dc_contact_t* contact)
|
char* dc_contact_get_addr(const dc_contact_t* contact)
|
||||||
{
|
{
|
||||||
if (contact == NULL || contact->magic != DC_CONTACT_MAGIC) {
|
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC) {
|
||||||
return dc_strdup(NULL);
|
return dc_strdup(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ char* dc_contact_get_addr(const dc_contact_t* contact)
|
||||||
*/
|
*/
|
||||||
char* dc_contact_get_name(const dc_contact_t* contact)
|
char* dc_contact_get_name(const dc_contact_t* contact)
|
||||||
{
|
{
|
||||||
if (contact == NULL || contact->magic != DC_CONTACT_MAGIC) {
|
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC) {
|
||||||
return dc_strdup(NULL);
|
return dc_strdup(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ char* dc_contact_get_name(const dc_contact_t* contact)
|
||||||
*/
|
*/
|
||||||
char* dc_contact_get_display_name(const dc_contact_t* contact)
|
char* dc_contact_get_display_name(const dc_contact_t* contact)
|
||||||
{
|
{
|
||||||
if (contact == NULL || contact->magic != DC_CONTACT_MAGIC) {
|
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC) {
|
||||||
return dc_strdup(NULL);
|
return dc_strdup(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ char* dc_contact_get_display_name(const dc_contact_t* contact)
|
||||||
*/
|
*/
|
||||||
char* dc_contact_get_name_n_addr(const dc_contact_t* contact)
|
char* dc_contact_get_name_n_addr(const dc_contact_t* contact)
|
||||||
{
|
{
|
||||||
if (contact == NULL || contact->magic != DC_CONTACT_MAGIC) {
|
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC) {
|
||||||
return dc_strdup(NULL);
|
return dc_strdup(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ char* dc_contact_get_name_n_addr(const dc_contact_t* contact)
|
||||||
*/
|
*/
|
||||||
char* dc_contact_get_first_name(const dc_contact_t* contact)
|
char* dc_contact_get_first_name(const dc_contact_t* contact)
|
||||||
{
|
{
|
||||||
if (contact == NULL || contact->magic != DC_CONTACT_MAGIC) {
|
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC) {
|
||||||
return dc_strdup(NULL);
|
return dc_strdup(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ char* dc_contact_get_first_name(const dc_contact_t* contact)
|
||||||
*/
|
*/
|
||||||
int dc_contact_is_blocked(const dc_contact_t* contact)
|
int dc_contact_is_blocked(const dc_contact_t* contact)
|
||||||
{
|
{
|
||||||
if (contact == NULL || contact->magic != DC_CONTACT_MAGIC) {
|
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return contact->blocked;
|
return contact->blocked;
|
||||||
|
@ -265,11 +265,11 @@ int dc_contact_is_verified_ex(dc_contact_t* contact, const dc_apeerstate_t* peer
|
||||||
int contact_verified = DC_NOT_VERIFIED;
|
int contact_verified = DC_NOT_VERIFIED;
|
||||||
dc_apeerstate_t* peerstate_to_delete = NULL;
|
dc_apeerstate_t* peerstate_to_delete = NULL;
|
||||||
|
|
||||||
if (contact == NULL || contact->magic != DC_CONTACT_MAGIC) {
|
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contact->id == DC_CONTACT_ID_SELF) {
|
if (contact->id==DC_CONTACT_ID_SELF) {
|
||||||
contact_verified = DC_BIDIRECT_VERIFIED;
|
contact_verified = DC_BIDIRECT_VERIFIED;
|
||||||
goto cleanup; // we're always sort of secured-verified as we could verify the key on this device any time with the key on this device
|
goto cleanup; // we're always sort of secured-verified as we could verify the key on this device any time with the key on this device
|
||||||
}
|
}
|
||||||
|
@ -319,13 +319,13 @@ int dc_contact_load_from_db(dc_contact_t* contact, dc_sqlite3_t* sql, uint32_t c
|
||||||
int success = 0;
|
int success = 0;
|
||||||
sqlite3_stmt* stmt = NULL;
|
sqlite3_stmt* stmt = NULL;
|
||||||
|
|
||||||
if (contact == NULL || contact->magic != DC_CONTACT_MAGIC || sql == NULL) {
|
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC || sql==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_contact_empty(contact);
|
dc_contact_empty(contact);
|
||||||
|
|
||||||
if (contact_id == DC_CONTACT_ID_SELF)
|
if (contact_id==DC_CONTACT_ID_SELF)
|
||||||
{
|
{
|
||||||
contact->id = contact_id;
|
contact->id = contact_id;
|
||||||
contact->name = dc_stock_str(contact->context, DC_STR_SELF);
|
contact->name = dc_stock_str(contact->context, DC_STR_SELF);
|
||||||
|
@ -338,7 +338,7 @@ int dc_contact_load_from_db(dc_contact_t* contact, dc_sqlite3_t* sql, uint32_t c
|
||||||
" FROM contacts c "
|
" FROM contacts c "
|
||||||
" WHERE c.id=?;");
|
" WHERE c.id=?;");
|
||||||
sqlite3_bind_int(stmt, 1, contact_id);
|
sqlite3_bind_int(stmt, 1, contact_id);
|
||||||
if (sqlite3_step(stmt) != SQLITE_ROW) {
|
if (sqlite3_step(stmt)!=SQLITE_ROW) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,7 +380,7 @@ char* dc_get_first_name(const char* full_name)
|
||||||
if (p1) {
|
if (p1) {
|
||||||
*p1 = 0;
|
*p1 = 0;
|
||||||
dc_rtrim(first_name);
|
dc_rtrim(first_name);
|
||||||
if (first_name[0] == 0) { /*empty result? use the original string in this case */
|
if (first_name[0]==0) { /*empty result? use the original string in this case */
|
||||||
free(first_name);
|
free(first_name);
|
||||||
first_name = dc_strdup(full_name);
|
first_name = dc_strdup(full_name);
|
||||||
}
|
}
|
||||||
|
@ -406,7 +406,7 @@ char* dc_get_first_name(const char* full_name)
|
||||||
*/
|
*/
|
||||||
void dc_normalize_name(char* full_name)
|
void dc_normalize_name(char* full_name)
|
||||||
{
|
{
|
||||||
if (full_name == NULL) {
|
if (full_name==NULL) {
|
||||||
return; /* error, however, this can be treated as documented behaviour */
|
return; /* error, however, this can be treated as documented behaviour */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
106
src/dc_e2ee.c
106
src/dc_e2ee.c
|
@ -46,7 +46,7 @@ static struct mailmime* new_data_part(void* data, size_t data_bytes, char* defau
|
||||||
char * content_type_str;
|
char * content_type_str;
|
||||||
int do_encoding;
|
int do_encoding;
|
||||||
|
|
||||||
/*if (filename != NULL) {
|
/*if (filename!=NULL) {
|
||||||
strncpy(basename_buf, filename, PATH_MAX);
|
strncpy(basename_buf, filename, PATH_MAX);
|
||||||
libetpan_basename(basename_buf);
|
libetpan_basename(basename_buf);
|
||||||
}*/
|
}*/
|
||||||
|
@ -54,25 +54,25 @@ static struct mailmime* new_data_part(void* data, size_t data_bytes, char* defau
|
||||||
encoding = NULL;
|
encoding = NULL;
|
||||||
|
|
||||||
/* default content-type */
|
/* default content-type */
|
||||||
if (default_content_type == NULL)
|
if (default_content_type==NULL)
|
||||||
content_type_str = "application/octet-stream";
|
content_type_str = "application/octet-stream";
|
||||||
else
|
else
|
||||||
content_type_str = default_content_type;
|
content_type_str = default_content_type;
|
||||||
|
|
||||||
content = mailmime_content_new_with_str(content_type_str);
|
content = mailmime_content_new_with_str(content_type_str);
|
||||||
if (content == NULL) {
|
if (content==NULL) {
|
||||||
goto free_content;
|
goto free_content;
|
||||||
}
|
}
|
||||||
|
|
||||||
do_encoding = 1;
|
do_encoding = 1;
|
||||||
if (content->ct_type->tp_type == MAILMIME_TYPE_COMPOSITE_TYPE) {
|
if (content->ct_type->tp_type==MAILMIME_TYPE_COMPOSITE_TYPE) {
|
||||||
struct mailmime_composite_type * composite;
|
struct mailmime_composite_type * composite;
|
||||||
|
|
||||||
composite = content->ct_type->tp_data.tp_composite_type;
|
composite = content->ct_type->tp_data.tp_composite_type;
|
||||||
|
|
||||||
switch (composite->ct_type) {
|
switch (composite->ct_type) {
|
||||||
case MAILMIME_COMPOSITE_TYPE_MESSAGE:
|
case MAILMIME_COMPOSITE_TYPE_MESSAGE:
|
||||||
if (strcasecmp(content->ct_subtype, "rfc822") == 0)
|
if (strcasecmp(content->ct_subtype, "rfc822")==0)
|
||||||
do_encoding = 0;
|
do_encoding = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -83,44 +83,44 @@ static struct mailmime* new_data_part(void* data, size_t data_bytes, char* defau
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_encoding) {
|
if (do_encoding) {
|
||||||
if (default_encoding == -1)
|
if (default_encoding==-1)
|
||||||
encoding_type = MAILMIME_MECHANISM_BASE64;
|
encoding_type = MAILMIME_MECHANISM_BASE64;
|
||||||
else
|
else
|
||||||
encoding_type = default_encoding;
|
encoding_type = default_encoding;
|
||||||
|
|
||||||
/* default Content-Transfer-Encoding */
|
/* default Content-Transfer-Encoding */
|
||||||
encoding = mailmime_mechanism_new(encoding_type, NULL);
|
encoding = mailmime_mechanism_new(encoding_type, NULL);
|
||||||
if (encoding == NULL) {
|
if (encoding==NULL) {
|
||||||
goto free_content;
|
goto free_content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mime_fields = mailmime_fields_new_with_data(encoding,
|
mime_fields = mailmime_fields_new_with_data(encoding,
|
||||||
NULL, NULL, NULL, NULL);
|
NULL, NULL, NULL, NULL);
|
||||||
if (mime_fields == NULL) {
|
if (mime_fields==NULL) {
|
||||||
goto free_content;
|
goto free_content;
|
||||||
}
|
}
|
||||||
|
|
||||||
mime = mailmime_new_empty(content, mime_fields);
|
mime = mailmime_new_empty(content, mime_fields);
|
||||||
if (mime == NULL) {
|
if (mime==NULL) {
|
||||||
goto free_mime_fields;
|
goto free_mime_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if ((filename != NULL) && (mime->mm_type == MAILMIME_SINGLE)) {
|
/*if ((filename!=NULL) && (mime->mm_type==MAILMIME_SINGLE)) {
|
||||||
// duplicates the file so that the file can be deleted when
|
// duplicates the file so that the file can be deleted when
|
||||||
// the MIME part is done
|
// the MIME part is done
|
||||||
dup_filename = dup_file(privacy, filename);
|
dup_filename = dup_file(privacy, filename);
|
||||||
if (dup_filename == NULL) {
|
if (dup_filename==NULL) {
|
||||||
goto free_mime;
|
goto free_mime;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = mailmime_set_body_file(mime, dup_filename);
|
r = mailmime_set_body_file(mime, dup_filename);
|
||||||
if (r != MAILIMF_NO_ERROR) {
|
if (r!=MAILIMF_NO_ERROR) {
|
||||||
free(dup_filename);
|
free(dup_filename);
|
||||||
goto free_mime;
|
goto free_mime;
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
if (data!=NULL && data_bytes>0 && mime->mm_type == MAILMIME_SINGLE) {
|
if (data!=NULL && data_bytes>0 && mime->mm_type==MAILMIME_SINGLE) {
|
||||||
mailmime_set_body_text(mime, data, data_bytes);
|
mailmime_set_body_text(mime, data, data_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,9 +134,9 @@ static struct mailmime* new_data_part(void* data, size_t data_bytes, char* defau
|
||||||
mailmime_content_free(content);
|
mailmime_content_free(content);
|
||||||
goto err;
|
goto err;
|
||||||
free_content:
|
free_content:
|
||||||
if (encoding != NULL)
|
if (encoding!=NULL)
|
||||||
mailmime_mechanism_free(encoding);
|
mailmime_mechanism_free(encoding);
|
||||||
if (content != NULL)
|
if (content!=NULL)
|
||||||
mailmime_content_free(content);
|
mailmime_content_free(content);
|
||||||
err:
|
err:
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -161,10 +161,10 @@ static struct mailmime* new_data_part(void* data, size_t data_bytes, char* defau
|
||||||
*/
|
*/
|
||||||
static int contains_report(struct mailmime* mime)
|
static int contains_report(struct mailmime* mime)
|
||||||
{
|
{
|
||||||
if (mime->mm_type == MAILMIME_MULTIPLE)
|
if (mime->mm_type==MAILMIME_MULTIPLE)
|
||||||
{
|
{
|
||||||
if (mime->mm_content_type->ct_type->tp_type==MAILMIME_TYPE_COMPOSITE_TYPE
|
if (mime->mm_content_type->ct_type->tp_type==MAILMIME_TYPE_COMPOSITE_TYPE
|
||||||
&& mime->mm_content_type->ct_type->tp_data.tp_composite_type->ct_type == MAILMIME_COMPOSITE_TYPE_MULTIPART
|
&& mime->mm_content_type->ct_type->tp_data.tp_composite_type->ct_type==MAILMIME_COMPOSITE_TYPE_MULTIPART
|
||||||
&& strcmp(mime->mm_content_type->ct_subtype, "report")==0) {
|
&& strcmp(mime->mm_content_type->ct_subtype, "report")==0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ static int contains_report(struct mailmime* mime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mime->mm_type == MAILMIME_MESSAGE)
|
else if (mime->mm_type==MAILMIME_MESSAGE)
|
||||||
{
|
{
|
||||||
if (contains_report(mime->mm_data.mm_message.mm_msg_mime)) {
|
if (contains_report(mime->mm_data.mm_message.mm_msg_mime)) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -198,7 +198,7 @@ static int load_or_generate_self_public_key(dc_context_t* context, dc_key_t* pub
|
||||||
int key_created = 0;
|
int key_created = 0;
|
||||||
int success = 0, key_creation_here = 0;
|
int success = 0, key_creation_here = 0;
|
||||||
|
|
||||||
if (context == NULL || context->magic != DC_CONTEXT_MAGIC || public_key == NULL) {
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || public_key==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ int dc_ensure_secret_key_exists(dc_context_t* context)
|
||||||
dc_key_t* public_key = dc_key_new();
|
dc_key_t* public_key = dc_key_new();
|
||||||
char* self_addr = NULL;
|
char* self_addr = NULL;
|
||||||
|
|
||||||
if (context==NULL || context->magic != DC_CONTEXT_MAGIC || public_key==NULL) {
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || public_key==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,9 +328,9 @@ void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr,
|
||||||
|
|
||||||
if (helper) { memset(helper, 0, sizeof(dc_e2ee_helper_t)); }
|
if (helper) { memset(helper, 0, sizeof(dc_e2ee_helper_t)); }
|
||||||
|
|
||||||
if (context == NULL || context->magic != DC_CONTEXT_MAGIC || recipients_addr == NULL || in_out_message == NULL
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || recipients_addr==NULL || in_out_message==NULL
|
||||||
|| in_out_message->mm_parent /* libEtPan's pgp_encrypt_mime() takes the parent as the new root. We just expect the root as being given to this function. */
|
|| in_out_message->mm_parent /* libEtPan's pgp_encrypt_mime() takes the parent as the new root. We just expect the root as being given to this function. */
|
||||||
|| autocryptheader == NULL || keyring==NULL || sign_key==NULL || plain == NULL || helper == NULL) {
|
|| autocryptheader==NULL || keyring==NULL || sign_key==NULL || plain==NULL || helper==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr,
|
||||||
}
|
}
|
||||||
|
|
||||||
autocryptheader->addr = dc_sqlite3_get_config(context->sql, "configured_addr", NULL);
|
autocryptheader->addr = dc_sqlite3_get_config(context->sql, "configured_addr", NULL);
|
||||||
if (autocryptheader->addr == NULL) {
|
if (autocryptheader->addr==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,12 +358,12 @@ void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr,
|
||||||
const char* recipient_addr = clist_content(iter1);
|
const char* recipient_addr = clist_content(iter1);
|
||||||
dc_apeerstate_t* peerstate = dc_apeerstate_new(context);
|
dc_apeerstate_t* peerstate = dc_apeerstate_new(context);
|
||||||
dc_key_t* key_to_use = NULL;
|
dc_key_t* key_to_use = NULL;
|
||||||
if (strcasecmp(recipient_addr, autocryptheader->addr) == 0)
|
if (strcasecmp(recipient_addr, autocryptheader->addr)==0)
|
||||||
{
|
{
|
||||||
; // encrypt to SELF, this key is added below
|
; // encrypt to SELF, this key is added below
|
||||||
}
|
}
|
||||||
else if (dc_apeerstate_load_by_addr(peerstate, context->sql, recipient_addr)
|
else if (dc_apeerstate_load_by_addr(peerstate, context->sql, recipient_addr)
|
||||||
&& (key_to_use=dc_apeerstate_peek_key(peerstate, min_verified)) != NULL
|
&& (key_to_use=dc_apeerstate_peek_key(peerstate, min_verified))!=NULL
|
||||||
&& (peerstate->prefer_encrypt==DC_PE_MUTUAL || e2ee_guaranteed))
|
&& (peerstate->prefer_encrypt==DC_PE_MUTUAL || e2ee_guaranteed))
|
||||||
{
|
{
|
||||||
dc_keyring_add(keyring, key_to_use); /* we always add all recipients (even on IMAP upload) as otherwise forwarding may fail */
|
dc_keyring_add(keyring, key_to_use); /* we always add all recipients (even on IMAP upload) as otherwise forwarding may fail */
|
||||||
|
@ -423,10 +423,10 @@ void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr,
|
||||||
|
|
||||||
struct mailimf_field* field = (struct mailimf_field*)clist_content(cur);
|
struct mailimf_field* field = (struct mailimf_field*)clist_content(cur);
|
||||||
if (field) {
|
if (field) {
|
||||||
if (field->fld_type == MAILIMF_FIELD_SUBJECT) {
|
if (field->fld_type==MAILIMF_FIELD_SUBJECT) {
|
||||||
move_to_encrypted = 1;
|
move_to_encrypted = 1;
|
||||||
}
|
}
|
||||||
else if (field->fld_type == MAILIMF_FIELD_OPTIONAL_FIELD) {
|
else if (field->fld_type==MAILIMF_FIELD_OPTIONAL_FIELD) {
|
||||||
struct mailimf_optional_field* opt_field = field->fld_data.fld_optional_field;
|
struct mailimf_optional_field* opt_field = field->fld_data.fld_optional_field;
|
||||||
if (opt_field && opt_field->fld_name) {
|
if (opt_field && opt_field->fld_name) {
|
||||||
if ( strncmp(opt_field->fld_name, "Secure-Join", 11)==0
|
if ( strncmp(opt_field->fld_name, "Secure-Join", 11)==0
|
||||||
|
@ -455,7 +455,7 @@ void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr,
|
||||||
|
|
||||||
/* convert part to encrypt to plain text */
|
/* convert part to encrypt to plain text */
|
||||||
mailmime_write_mem(plain, &col, message_to_encrypt);
|
mailmime_write_mem(plain, &col, message_to_encrypt);
|
||||||
if (plain->str == NULL || plain->len<=0) {
|
if (plain->str==NULL || plain->len<=0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
//char* t1=dc_null_terminate(plain->str,plain->len);printf("PLAIN:\n%s\n",t1);free(t1); // DEBUG OUTPUT
|
//char* t1=dc_null_terminate(plain->str,plain->len);printf("PLAIN:\n%s\n",t1);free(t1); // DEBUG OUTPUT
|
||||||
|
@ -489,7 +489,7 @@ void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr,
|
||||||
}
|
}
|
||||||
|
|
||||||
char* p = dc_aheader_render(autocryptheader);
|
char* p = dc_aheader_render(autocryptheader);
|
||||||
if (p == NULL) {
|
if (p==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
mailimf_fields_add(imffields_unprotected, mailimf_field_new_custom(strdup("Autocrypt"), p/*takes ownership of pointer*/));
|
mailimf_fields_add(imffields_unprotected, mailimf_field_new_custom(strdup("Autocrypt"), p/*takes ownership of pointer*/));
|
||||||
|
@ -507,7 +507,7 @@ cleanup:
|
||||||
|
|
||||||
void dc_e2ee_thanks(dc_e2ee_helper_t* helper)
|
void dc_e2ee_thanks(dc_e2ee_helper_t* helper)
|
||||||
{
|
{
|
||||||
if (helper == NULL) {
|
if (helper==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,19 +573,19 @@ static int decrypt_part(dc_context_t* context,
|
||||||
|
|
||||||
/* get data pointer from `mime` */
|
/* get data pointer from `mime` */
|
||||||
mime_data = mime->mm_data.mm_single;
|
mime_data = mime->mm_data.mm_single;
|
||||||
if (mime_data->dt_type != MAILMIME_DATA_TEXT /* MAILMIME_DATA_FILE indicates, the data is in a file; AFAIK this is not used on parsing */
|
if (mime_data->dt_type!=MAILMIME_DATA_TEXT /* MAILMIME_DATA_FILE indicates, the data is in a file; AFAIK this is not used on parsing */
|
||||||
|| mime_data->dt_data.dt_text.dt_data == NULL
|
|| mime_data->dt_data.dt_text.dt_data==NULL
|
||||||
|| mime_data->dt_data.dt_text.dt_length <= 0) {
|
|| mime_data->dt_data.dt_text.dt_length <= 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check headers in `mime` */
|
/* check headers in `mime` */
|
||||||
if (mime->mm_mime_fields != NULL) {
|
if (mime->mm_mime_fields!=NULL) {
|
||||||
clistiter* cur;
|
clistiter* cur;
|
||||||
for (cur = clist_begin(mime->mm_mime_fields->fld_list); cur != NULL; cur = clist_next(cur)) {
|
for (cur = clist_begin(mime->mm_mime_fields->fld_list); cur!=NULL; cur = clist_next(cur)) {
|
||||||
struct mailmime_field* field = (struct mailmime_field*)clist_content(cur);
|
struct mailmime_field* field = (struct mailmime_field*)clist_content(cur);
|
||||||
if (field) {
|
if (field) {
|
||||||
if (field->fld_type == MAILMIME_FIELD_TRANSFER_ENCODING && field->fld_data.fld_encoding) {
|
if (field->fld_type==MAILMIME_FIELD_TRANSFER_ENCODING && field->fld_data.fld_encoding) {
|
||||||
mime_transfer_encoding = field->fld_data.fld_encoding->enc_type;
|
mime_transfer_encoding = field->fld_data.fld_encoding->enc_type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -593,13 +593,13 @@ static int decrypt_part(dc_context_t* context,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* regard `Content-Transfer-Encoding:` */
|
/* regard `Content-Transfer-Encoding:` */
|
||||||
if (mime_transfer_encoding == MAILMIME_MECHANISM_7BIT
|
if (mime_transfer_encoding==MAILMIME_MECHANISM_7BIT
|
||||||
|| mime_transfer_encoding == MAILMIME_MECHANISM_8BIT
|
|| mime_transfer_encoding==MAILMIME_MECHANISM_8BIT
|
||||||
|| mime_transfer_encoding == MAILMIME_MECHANISM_BINARY)
|
|| mime_transfer_encoding==MAILMIME_MECHANISM_BINARY)
|
||||||
{
|
{
|
||||||
decoded_data = mime_data->dt_data.dt_text.dt_data;
|
decoded_data = mime_data->dt_data.dt_text.dt_data;
|
||||||
decoded_data_bytes = mime_data->dt_data.dt_text.dt_length;
|
decoded_data_bytes = mime_data->dt_data.dt_text.dt_length;
|
||||||
if (decoded_data == NULL || decoded_data_bytes <= 0) {
|
if (decoded_data==NULL || decoded_data_bytes <= 0) {
|
||||||
goto cleanup; /* no error - but no data */
|
goto cleanup; /* no error - but no data */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -610,7 +610,7 @@ static int decrypt_part(dc_context_t* context,
|
||||||
r = mailmime_part_parse(mime_data->dt_data.dt_text.dt_data, mime_data->dt_data.dt_text.dt_length,
|
r = mailmime_part_parse(mime_data->dt_data.dt_text.dt_data, mime_data->dt_data.dt_text.dt_length,
|
||||||
¤t_index, mime_transfer_encoding,
|
¤t_index, mime_transfer_encoding,
|
||||||
&transfer_decoding_buffer, &decoded_data_bytes);
|
&transfer_decoding_buffer, &decoded_data_bytes);
|
||||||
if (r != MAILIMF_NO_ERROR || transfer_decoding_buffer == NULL || decoded_data_bytes <= 0) {
|
if (r!=MAILIMF_NO_ERROR || transfer_decoding_buffer==NULL || decoded_data_bytes <= 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
decoded_data = transfer_decoding_buffer;
|
decoded_data = transfer_decoding_buffer;
|
||||||
|
@ -635,7 +635,7 @@ static int decrypt_part(dc_context_t* context,
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
struct mailmime* decrypted_mime = NULL;
|
struct mailmime* decrypted_mime = NULL;
|
||||||
if (mailmime_parse(plain_buf, plain_bytes, &index, &decrypted_mime)!=MAIL_NO_ERROR
|
if (mailmime_parse(plain_buf, plain_bytes, &index, &decrypted_mime)!=MAIL_NO_ERROR
|
||||||
|| decrypted_mime == NULL) {
|
|| decrypted_mime==NULL) {
|
||||||
if(decrypted_mime) {mailmime_free(decrypted_mime);}
|
if(decrypted_mime) {mailmime_free(decrypted_mime);}
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -668,11 +668,11 @@ static int decrypt_recursive(dc_context_t* context,
|
||||||
struct mailmime_content* ct = NULL;
|
struct mailmime_content* ct = NULL;
|
||||||
clistiter* cur = NULL;
|
clistiter* cur = NULL;
|
||||||
|
|
||||||
if (context == NULL || mime == NULL) {
|
if (context==NULL || mime==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mime->mm_type == MAILMIME_MULTIPLE)
|
if (mime->mm_type==MAILMIME_MULTIPLE)
|
||||||
{
|
{
|
||||||
ct = mime->mm_content_type;
|
ct = mime->mm_content_type;
|
||||||
if (ct && ct->ct_subtype && strcmp(ct->ct_subtype, "encrypted")==0) {
|
if (ct && ct->ct_subtype && strcmp(ct->ct_subtype, "encrypted")==0) {
|
||||||
|
@ -683,7 +683,7 @@ static int decrypt_recursive(dc_context_t* context,
|
||||||
if (decrypt_part(context, (struct mailmime*)clist_content(cur), private_keyring, public_keyring_for_validate, ret_valid_signatures, &decrypted_mime))
|
if (decrypt_part(context, (struct mailmime*)clist_content(cur), private_keyring, public_keyring_for_validate, ret_valid_signatures, &decrypted_mime))
|
||||||
{
|
{
|
||||||
/* remember the header containing potentially Autocrypt-Gossip */
|
/* remember the header containing potentially Autocrypt-Gossip */
|
||||||
if (*ret_gossip_headers == NULL /* use the outermost decrypted part */
|
if (*ret_gossip_headers==NULL /* use the outermost decrypted part */
|
||||||
&& dc_hash_cnt(ret_valid_signatures) > 0 /* do not trust the gossipped keys when the message cannot be validated eg. due to a bad signature */)
|
&& dc_hash_cnt(ret_valid_signatures) > 0 /* do not trust the gossipped keys when the message cannot be validated eg. due to a bad signature */)
|
||||||
{
|
{
|
||||||
size_t dummy = 0;
|
size_t dummy = 0;
|
||||||
|
@ -710,7 +710,7 @@ static int decrypt_recursive(dc_context_t* context,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mime->mm_type == MAILMIME_MESSAGE)
|
else if (mime->mm_type==MAILMIME_MESSAGE)
|
||||||
{
|
{
|
||||||
if (decrypt_recursive(context, mime->mm_data.mm_message.mm_msg_mime, private_keyring, public_keyring_for_validate, ret_valid_signatures, ret_gossip_headers, ret_has_unencrypted_parts)) {
|
if (decrypt_recursive(context, mime->mm_data.mm_message.mm_msg_mime, private_keyring, public_keyring_for_validate, ret_valid_signatures, ret_gossip_headers, ret_has_unencrypted_parts)) {
|
||||||
return 1; /* sth. decrypted, start over from root searching for encrypted parts */
|
return 1; /* sth. decrypted, start over from root searching for encrypted parts */
|
||||||
|
@ -734,7 +734,7 @@ static dc_hash_t* update_gossip_peerstates(dc_context_t* context, time_t message
|
||||||
for (cur1 = clist_begin(gossip_headers->fld_list); cur1!=NULL ; cur1=clist_next(cur1))
|
for (cur1 = clist_begin(gossip_headers->fld_list); cur1!=NULL ; cur1=clist_next(cur1))
|
||||||
{
|
{
|
||||||
struct mailimf_field* field = (struct mailimf_field*)clist_content(cur1);
|
struct mailimf_field* field = (struct mailimf_field*)clist_content(cur1);
|
||||||
if (field->fld_type == MAILIMF_FIELD_OPTIONAL_FIELD)
|
if (field->fld_type==MAILIMF_FIELD_OPTIONAL_FIELD)
|
||||||
{
|
{
|
||||||
const struct mailimf_optional_field* optional_field = field->fld_data.fld_optional_field;
|
const struct mailimf_optional_field* optional_field = field->fld_data.fld_optional_field;
|
||||||
if (optional_field && optional_field->fld_name && strcasecmp(optional_field->fld_name, "Autocrypt-Gossip")==0)
|
if (optional_field && optional_field->fld_name && strcasecmp(optional_field->fld_name, "Autocrypt-Gossip")==0)
|
||||||
|
@ -744,7 +744,7 @@ static dc_hash_t* update_gossip_peerstates(dc_context_t* context, time_t message
|
||||||
&& dc_pgp_is_valid_key(context, gossip_header->public_key))
|
&& dc_pgp_is_valid_key(context, gossip_header->public_key))
|
||||||
{
|
{
|
||||||
/* found an Autocrypt-Gossip entry, create recipents list and check if addr matches */
|
/* found an Autocrypt-Gossip entry, create recipents list and check if addr matches */
|
||||||
if (recipients == NULL) {
|
if (recipients==NULL) {
|
||||||
recipients = mailimf_get_recipients(imffields);
|
recipients = mailimf_get_recipients(imffields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,7 +769,7 @@ static dc_hash_t* update_gossip_peerstates(dc_context_t* context, time_t message
|
||||||
|
|
||||||
// collect all gossipped addresses; we need them later to mark them as being
|
// collect all gossipped addresses; we need them later to mark them as being
|
||||||
// verified when used in a verified group by a verified sender
|
// verified when used in a verified group by a verified sender
|
||||||
if (gossipped_addr == NULL) {
|
if (gossipped_addr==NULL) {
|
||||||
gossipped_addr = malloc(sizeof(dc_hash_t));
|
gossipped_addr = malloc(sizeof(dc_hash_t));
|
||||||
dc_hash_init(gossipped_addr, DC_HASH_STRING, 1/*copy key*/);
|
dc_hash_init(gossipped_addr, DC_HASH_STRING, 1/*copy key*/);
|
||||||
}
|
}
|
||||||
|
@ -811,8 +811,8 @@ void dc_e2ee_decrypt(dc_context_t* context, struct mailmime* in_out_message,
|
||||||
|
|
||||||
if (helper) { memset(helper, 0, sizeof(dc_e2ee_helper_t)); }
|
if (helper) { memset(helper, 0, sizeof(dc_e2ee_helper_t)); }
|
||||||
|
|
||||||
if (context==NULL || context->magic != DC_CONTEXT_MAGIC || in_out_message==NULL
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || in_out_message==NULL
|
||||||
|| helper == NULL || imffields==NULL) {
|
|| helper==NULL || imffields==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -832,7 +832,7 @@ void dc_e2ee_decrypt(dc_context_t* context, struct mailmime* in_out_message,
|
||||||
struct mailimf_orig_date* orig_date = field->fld_data.fld_orig_date;
|
struct mailimf_orig_date* orig_date = field->fld_data.fld_orig_date;
|
||||||
if (orig_date) {
|
if (orig_date) {
|
||||||
message_time = dc_timestamp_from_date(orig_date->dt_date_time); /* is not yet checked against bad times! */
|
message_time = dc_timestamp_from_date(orig_date->dt_date_time); /* is not yet checked against bad times! */
|
||||||
if (message_time != DC_INVALID_TIMESTAMP && message_time > time(NULL)) {
|
if (message_time!=DC_INVALID_TIMESTAMP && message_time > time(NULL)) {
|
||||||
message_time = time(NULL);
|
message_time = time(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -882,7 +882,7 @@ void dc_e2ee_decrypt(dc_context_t* context, struct mailmime* in_out_message,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if not yet done, load peer with public key for verification (should be last as the peer may be modified above) */
|
/* if not yet done, load peer with public key for verification (should be last as the peer may be modified above) */
|
||||||
if (peerstate->last_seen == 0) {
|
if (peerstate->last_seen==0) {
|
||||||
dc_apeerstate_load_by_addr(peerstate, context->sql, from);
|
dc_apeerstate_load_by_addr(peerstate, context->sql, from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -911,7 +911,7 @@ void dc_e2ee_decrypt(dc_context_t* context, struct mailmime* in_out_message,
|
||||||
// if we're here, sth. was encrypted. if we're on top-level, and there are no
|
// if we're here, sth. was encrypted. if we're on top-level, and there are no
|
||||||
// additional unencrypted parts in the message the encryption was fine
|
// additional unencrypted parts in the message the encryption was fine
|
||||||
// (signature is handled separately and returned as `signatures`)
|
// (signature is handled separately and returned as `signatures`)
|
||||||
if (iterations == 0
|
if (iterations==0
|
||||||
&& !has_unencrypted_parts) {
|
&& !has_unencrypted_parts) {
|
||||||
helper->encrypted = 1;
|
helper->encrypted = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ char* dc_render_setup_file(dc_context_t* context, const char* passphrase)
|
||||||
|
|
||||||
char* ret_setupfilecontent = NULL;
|
char* ret_setupfilecontent = NULL;
|
||||||
|
|
||||||
if (context==NULL || context->magic != DC_CONTEXT_MAGIC || passphrase==NULL
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || passphrase==NULL
|
||||||
|| strlen(passphrase)<2 || curr_private_key==NULL) {
|
|| strlen(passphrase)<2 || curr_private_key==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ char* dc_render_setup_file(dc_context_t* context, const char* passphrase)
|
||||||
dc_key_load_self_private(curr_private_key, self_addr, context->sql);
|
dc_key_load_self_private(curr_private_key, self_addr, context->sql);
|
||||||
|
|
||||||
char* payload_key_asc = dc_key_render_asc(curr_private_key, context->e2ee_enabled? "Autocrypt-Prefer-Encrypt: mutual\r\n" : NULL);
|
char* payload_key_asc = dc_key_render_asc(curr_private_key, context->e2ee_enabled? "Autocrypt-Prefer-Encrypt: mutual\r\n" : NULL);
|
||||||
if (payload_key_asc == NULL) {
|
if (payload_key_asc==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ char* dc_render_setup_file(dc_context_t* context, const char* passphrase)
|
||||||
int s2k_spec = PGP_S2KS_ITERATED_AND_SALTED; // 0=simple, 1=salted, 3=salted+iterated
|
int s2k_spec = PGP_S2KS_ITERATED_AND_SALTED; // 0=simple, 1=salted, 3=salted+iterated
|
||||||
int s2k_iter_id = 96; // 0=1024 iterations, 96=65536 iterations
|
int s2k_iter_id = 96; // 0=1024 iterations, 96=65536 iterations
|
||||||
#define HASH_ALG PGP_HASH_SHA256
|
#define HASH_ALG PGP_HASH_SHA256
|
||||||
if ((key = pgp_s2k_do(passphrase, crypt_info.keysize, s2k_spec, HASH_ALG, salt, s2k_iter_id)) == NULL) {
|
if ((key = pgp_s2k_do(passphrase, crypt_info.keysize, s2k_spec, HASH_ALG, salt, s2k_iter_id))==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ char* dc_render_setup_file(dc_context_t* context, const char* passphrase)
|
||||||
/* Tag 18 - PGP_PTAG_CT_SE_IP_DATA */
|
/* Tag 18 - PGP_PTAG_CT_SE_IP_DATA */
|
||||||
//pgp_write_symm_enc_data((const uint8_t*)payload_mem->buf, payload_mem->length, PGP_SA_AES_128, key, encr_output); //-- would generate Tag 9
|
//pgp_write_symm_enc_data((const uint8_t*)payload_mem->buf, payload_mem->length, PGP_SA_AES_128, key, encr_output); //-- would generate Tag 9
|
||||||
{
|
{
|
||||||
uint8_t* iv = calloc(1, crypt_info.blocksize); if (iv == NULL) { goto cleanup; }
|
uint8_t* iv = calloc(1, crypt_info.blocksize); if (iv==NULL) { goto cleanup; }
|
||||||
crypt_info.set_iv(&crypt_info, iv);
|
crypt_info.set_iv(&crypt_info, iv);
|
||||||
free(iv);
|
free(iv);
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ char* dc_decrypt_setup_file(dc_context_t* context, const char* passphrase, const
|
||||||
|
|
||||||
/* convert base64 to binary */
|
/* convert base64 to binary */
|
||||||
if (mailmime_base64_body_parse(fc_base64, strlen(fc_base64), &indx, &binary/*must be freed using mmap_string_unref()*/, &binary_bytes)!=MAILIMF_NO_ERROR
|
if (mailmime_base64_body_parse(fc_base64, strlen(fc_base64), &indx, &binary/*must be freed using mmap_string_unref()*/, &binary_bytes)!=MAILIMF_NO_ERROR
|
||||||
|| binary == NULL || binary_bytes == 0) {
|
|| binary==NULL || binary_bytes==0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,7 +330,7 @@ char* dc_decrypt_setup_file(dc_context_t* context, const char* passphrase, const
|
||||||
io.outs = stdout;
|
io.outs = stdout;
|
||||||
io.errs = stderr;
|
io.errs = stderr;
|
||||||
io.res = stderr;
|
io.res = stderr;
|
||||||
if ((outmem=pgp_decrypt_buf(&io, binary, binary_bytes, NULL, NULL, 0, 0, passphrase)) == NULL) {
|
if ((outmem=pgp_decrypt_buf(&io, binary, binary_bytes, NULL, NULL, 0, 0, passphrase))==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
payload = strndup((const char*)outmem->buf, outmem->length);
|
payload = strndup((const char*)outmem->buf, outmem->length);
|
||||||
|
@ -387,7 +387,7 @@ char* dc_create_setup_code(dc_context_t* context)
|
||||||
/* Function remove all special characters from the given code and brings it to the 9x4 form */
|
/* Function remove all special characters from the given code and brings it to the 9x4 form */
|
||||||
char* dc_normalize_setup_code(dc_context_t* context, const char* in)
|
char* dc_normalize_setup_code(dc_context_t* context, const char* in)
|
||||||
{
|
{
|
||||||
if (in == NULL) {
|
if (in==NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,7 +400,7 @@ char* dc_normalize_setup_code(dc_context_t* context, const char* in)
|
||||||
if (*p1 >= '0' && *p1 <= '9') {
|
if (*p1 >= '0' && *p1 <= '9') {
|
||||||
dc_strbuilder_catf(&out, "%c", *p1);
|
dc_strbuilder_catf(&out, "%c", *p1);
|
||||||
outlen = strlen(out.buf);
|
outlen = strlen(out.buf);
|
||||||
if (outlen==4 || outlen==9 || outlen==14 || outlen==19 || outlen==24 || outlen == 29 || outlen == 34 || outlen == 39) {
|
if (outlen==4 || outlen==9 || outlen==14 || outlen==19 || outlen==24 || outlen==29 || outlen==34 || outlen==39) {
|
||||||
dc_strbuilder_cat(&out, "-");
|
dc_strbuilder_cat(&out, "-");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -471,7 +471,7 @@ char* dc_initiate_key_transfer(dc_context_t* context)
|
||||||
}
|
}
|
||||||
#define CHECK_EXIT if (context->shall_stop_ongoing) { goto cleanup; }
|
#define CHECK_EXIT if (context->shall_stop_ongoing) { goto cleanup; }
|
||||||
|
|
||||||
if ((setup_code=dc_create_setup_code(context)) == NULL) { /* this may require a keypair to be created. this may take a second ... */
|
if ((setup_code=dc_create_setup_code(context))==NULL) { /* this may require a keypair to be created. this may take a second ... */
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,7 +483,7 @@ char* dc_initiate_key_transfer(dc_context_t* context)
|
||||||
|
|
||||||
CHECK_EXIT
|
CHECK_EXIT
|
||||||
|
|
||||||
if ((setup_file_name=dc_get_fine_pathNfilename(context->blobdir, "autocrypt-setup-message.html")) == NULL
|
if ((setup_file_name=dc_get_fine_pathNfilename(context->blobdir, "autocrypt-setup-message.html"))==NULL
|
||||||
|| !dc_write_file(setup_file_name, setup_file_content, strlen(setup_file_content), context)) {
|
|| !dc_write_file(setup_file_name, setup_file_content, strlen(setup_file_content), context)) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -501,7 +501,7 @@ char* dc_initiate_key_transfer(dc_context_t* context)
|
||||||
|
|
||||||
CHECK_EXIT
|
CHECK_EXIT
|
||||||
|
|
||||||
if ((msg_id = dc_send_msg_object(context, chat_id, msg)) == 0) {
|
if ((msg_id = dc_send_msg_object(context, chat_id, msg))==0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -553,7 +553,7 @@ static int set_self_key(dc_context_t* context, const char* armored, int set_defa
|
||||||
|
|
||||||
buf = dc_strdup(armored);
|
buf = dc_strdup(armored);
|
||||||
if (!dc_split_armored_data(buf, &buf_headerline, NULL, &buf_preferencrypt, &buf_base64)
|
if (!dc_split_armored_data(buf, &buf_headerline, NULL, &buf_preferencrypt, &buf_base64)
|
||||||
|| strcmp(buf_headerline, "-----BEGIN PGP PRIVATE KEY BLOCK-----")!=0 || buf_base64 == NULL) {
|
|| strcmp(buf_headerline, "-----BEGIN PGP PRIVATE KEY BLOCK-----")!=0 || buf_base64==NULL) {
|
||||||
dc_log_warning(context, 0, "File does not contain a private key."); /* do not log as error - this is quite normal after entering the bad setup code */
|
dc_log_warning(context, 0, "File does not contain a private key."); /* do not log as error - this is quite normal after entering the bad setup code */
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -635,7 +635,7 @@ int dc_continue_key_transfer(dc_context_t* context, uint32_t msg_id, const char*
|
||||||
char* armored_key = NULL;
|
char* armored_key = NULL;
|
||||||
char* norm_sc = NULL;
|
char* norm_sc = NULL;
|
||||||
|
|
||||||
if (context == NULL || context->magic != DC_CONTEXT_MAGIC || msg_id <= DC_MSG_ID_LAST_SPECIAL || setup_code == NULL) {
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || msg_id <= DC_MSG_ID_LAST_SPECIAL || setup_code==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -645,7 +645,7 @@ int dc_continue_key_transfer(dc_context_t* context, uint32_t msg_id, const char*
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dc_read_file(filename, (void**)&filecontent, &filebytes, msg->context) || filecontent == NULL || filebytes <= 0) {
|
if (!dc_read_file(filename, (void**)&filecontent, &filebytes, msg->context) || filecontent==NULL || filebytes <= 0) {
|
||||||
dc_log_error(context, 0, "Cannot read Autocrypt Setup Message file.");
|
dc_log_error(context, 0, "Cannot read Autocrypt Setup Message file.");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -655,7 +655,7 @@ int dc_continue_key_transfer(dc_context_t* context, uint32_t msg_id, const char*
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((armored_key=dc_decrypt_setup_file(context, norm_sc, filecontent)) == NULL) {
|
if ((armored_key=dc_decrypt_setup_file(context, norm_sc, filecontent))==NULL) {
|
||||||
dc_log_warning(context, 0, "Cannot decrypt Autocrypt Setup Message."); /* do not log as error - this is quite normal after entering the bad setup code */
|
dc_log_warning(context, 0, "Cannot decrypt Autocrypt Setup Message."); /* do not log as error - this is quite normal after entering the bad setup code */
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -758,7 +758,7 @@ static int import_self_keys(dc_context_t* context, const char* dir_name)
|
||||||
char* buf2 = NULL;
|
char* buf2 = NULL;
|
||||||
const char* buf2_headerline = NULL; // a pointer inside buf2, MUST NOT be free()'d
|
const char* buf2_headerline = NULL; // a pointer inside buf2, MUST NOT be free()'d
|
||||||
|
|
||||||
if (context==NULL || context->magic != DC_CONTEXT_MAGIC || dir_name==NULL) {
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || dir_name==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((dir_handle=opendir(dir_name))==NULL) {
|
if ((dir_handle=opendir(dir_name))==NULL) {
|
||||||
|
@ -794,7 +794,7 @@ static int import_self_keys(dc_context_t* context, const char* dir_name)
|
||||||
* However some programs (Thunderbird/Enigmail) put public and private key
|
* However some programs (Thunderbird/Enigmail) put public and private key
|
||||||
* in the same file, so we check if there is a private key following */
|
* in the same file, so we check if there is a private key following */
|
||||||
private_key = strstr(buf, "-----BEGIN PGP PRIVATE KEY BLOCK");
|
private_key = strstr(buf, "-----BEGIN PGP PRIVATE KEY BLOCK");
|
||||||
if (private_key == NULL) {
|
if (private_key==NULL) {
|
||||||
continue; /* this is no error but quite normal as we always export the public keys together with the private ones */
|
continue; /* this is no error but quite normal as we always export the public keys together with the private ones */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -812,7 +812,7 @@ static int import_self_keys(dc_context_t* context, const char* dir_name)
|
||||||
imported_cnt++;
|
imported_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imported_cnt == 0) {
|
if (imported_cnt==0) {
|
||||||
dc_log_error(context, 0, "No private keys found in \"%s\".", dir_name);
|
dc_log_error(context, 0, "No private keys found in \"%s\".", dir_name);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -993,8 +993,8 @@ static void ensure_no_slash(char* path)
|
||||||
{
|
{
|
||||||
int path_len = strlen(path);
|
int path_len = strlen(path);
|
||||||
if (path_len > 0) {
|
if (path_len > 0) {
|
||||||
if (path[path_len-1] == '/'
|
if (path[path_len-1]=='/'
|
||||||
|| path[path_len-1] == '\\') {
|
|| path[path_len-1]=='\\') {
|
||||||
path[path_len-1] = 0;
|
path[path_len-1] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1056,7 +1056,7 @@ static int import_backup(dc_context_t* context, const char* backup_to_import)
|
||||||
stmt = NULL;
|
stmt = NULL;
|
||||||
|
|
||||||
stmt = dc_sqlite3_prepare(context->sql, "SELECT file_name, file_content FROM backup_blobs ORDER BY id;");
|
stmt = dc_sqlite3_prepare(context->sql, "SELECT file_name, file_content FROM backup_blobs ORDER BY id;");
|
||||||
while (sqlite3_step(stmt) == SQLITE_ROW)
|
while (sqlite3_step(stmt)==SQLITE_ROW)
|
||||||
{
|
{
|
||||||
if (context->shall_stop_ongoing) {
|
if (context->shall_stop_ongoing) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -1095,8 +1095,8 @@ static int import_backup(dc_context_t* context, const char* backup_to_import)
|
||||||
|
|
||||||
dc_log_info(context, 0, "Rewriting paths from '%s' to '%s' ...", repl_from, repl_to);
|
dc_log_info(context, 0, "Rewriting paths from '%s' to '%s' ...", repl_from, repl_to);
|
||||||
|
|
||||||
assert( 'f' == DC_PARAM_FILE);
|
assert( 'f'==DC_PARAM_FILE);
|
||||||
assert( 'i' == DC_PARAM_PROFILE_IMAGE);
|
assert( 'i'==DC_PARAM_PROFILE_IMAGE);
|
||||||
|
|
||||||
char* q3 = sqlite3_mprintf("UPDATE msgs SET param=replace(param, 'f=%q/', 'f=%q/');", repl_from, repl_to); /* cannot use dc_mprintf() because of "%q" */
|
char* q3 = sqlite3_mprintf("UPDATE msgs SET param=replace(param, 'f=%q/', 'f=%q/');", repl_from, repl_to); /* cannot use dc_mprintf() because of "%q" */
|
||||||
dc_sqlite3_execute(context->sql, q3);
|
dc_sqlite3_execute(context->sql, q3);
|
||||||
|
@ -1198,7 +1198,7 @@ void dc_job_do_DC_JOB_IMEX_IMAP(dc_context_t* context, dc_job_t* job)
|
||||||
char* param1 = NULL;
|
char* param1 = NULL;
|
||||||
char* param2 = NULL;
|
char* param2 = NULL;
|
||||||
|
|
||||||
if (context==NULL || context->magic != DC_CONTEXT_MAGIC || context->sql==NULL) {
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || context->sql==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1211,7 +1211,7 @@ void dc_job_do_DC_JOB_IMEX_IMAP(dc_context_t* context, dc_job_t* job)
|
||||||
param1 = dc_param_get (job->param, DC_PARAM_CMD_ARG, NULL);
|
param1 = dc_param_get (job->param, DC_PARAM_CMD_ARG, NULL);
|
||||||
param2 = dc_param_get (job->param, DC_PARAM_CMD_ARG2, NULL);
|
param2 = dc_param_get (job->param, DC_PARAM_CMD_ARG2, NULL);
|
||||||
|
|
||||||
if (param1 == NULL) {
|
if (param1==NULL) {
|
||||||
dc_log_error(context, 0, "No Import/export dir/file given.");
|
dc_log_error(context, 0, "No Import/export dir/file given.");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -1337,7 +1337,7 @@ char* dc_imex_has_backup(dc_context_t* context, const char* dir_name)
|
||||||
char* curr_pathNfilename = NULL;
|
char* curr_pathNfilename = NULL;
|
||||||
dc_sqlite3_t* test_sql = NULL;
|
dc_sqlite3_t* test_sql = NULL;
|
||||||
|
|
||||||
if (context == NULL || context->magic != DC_CONTEXT_MAGIC) {
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1398,7 +1398,7 @@ int dc_check_password(dc_context_t* context, const char* test_pw)
|
||||||
dc_loginparam_t* loginparam = dc_loginparam_new();
|
dc_loginparam_t* loginparam = dc_loginparam_new();
|
||||||
int success = 0;
|
int success = 0;
|
||||||
|
|
||||||
if (context==NULL || context->magic != DC_CONTEXT_MAGIC) {
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
34
src/dc_key.c
34
src/dc_key.c
|
@ -36,7 +36,7 @@
|
||||||
void dc_wipe_secret_mem(void* buf, size_t buf_bytes)
|
void dc_wipe_secret_mem(void* buf, size_t buf_bytes)
|
||||||
{
|
{
|
||||||
/* wipe private keys or othere secrets with zeros so that secrets are no longer in RAM */
|
/* wipe private keys or othere secrets with zeros so that secrets are no longer in RAM */
|
||||||
if (buf == NULL || buf_bytes <= 0) {
|
if (buf==NULL || buf_bytes <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ void dc_wipe_secret_mem(void* buf, size_t buf_bytes)
|
||||||
|
|
||||||
static void dc_key_empty(dc_key_t* key) /* only use before calling setters; take care when using this function together with reference counting, prefer new objects instead */
|
static void dc_key_empty(dc_key_t* key) /* only use before calling setters; take care when using this function together with reference counting, prefer new objects instead */
|
||||||
{
|
{
|
||||||
if (key == NULL) {
|
if (key==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ int dc_key_set_from_binary(dc_key_t* key, const void* data, int bytes, int type)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
key->binary = malloc(bytes);
|
key->binary = malloc(bytes);
|
||||||
if (key->binary == NULL) {
|
if (key->binary==NULL) {
|
||||||
exit(40);
|
exit(40);
|
||||||
}
|
}
|
||||||
memcpy(key->binary, data, bytes);
|
memcpy(key->binary, data, bytes);
|
||||||
|
@ -148,7 +148,7 @@ int dc_key_set_from_base64(dc_key_t* key, const char* base64, int type)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mailmime_base64_body_parse(base64, strlen(base64), &indx, &result/*must be freed using mmap_string_unref()*/, &result_len)!=MAILIMF_NO_ERROR
|
if (mailmime_base64_body_parse(base64, strlen(base64), &indx, &result/*must be freed using mmap_string_unref()*/, &result_len)!=MAILIMF_NO_ERROR
|
||||||
|| result == NULL || result_len == 0) {
|
|| result==NULL || result_len==0) {
|
||||||
return 0; /* bad key */
|
return 0; /* bad key */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ int dc_key_set_from_file(dc_key_t* key, const char* pathNfilename, dc_context_t*
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dc_split_armored_data(buf, &headerline, NULL, NULL, &base64)
|
if (!dc_split_armored_data(buf, &headerline, NULL, NULL, &base64)
|
||||||
|| headerline == NULL || base64 == NULL) {
|
|| headerline==NULL || base64==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ int dc_key_save_self_keypair(const dc_key_t* public_key, const dc_key_t* private
|
||||||
sqlite3_bind_blob (stmt, 3, public_key->binary, public_key->bytes, SQLITE_STATIC);
|
sqlite3_bind_blob (stmt, 3, public_key->binary, public_key->bytes, SQLITE_STATIC);
|
||||||
sqlite3_bind_blob (stmt, 4, private_key->binary, private_key->bytes, SQLITE_STATIC);
|
sqlite3_bind_blob (stmt, 4, private_key->binary, private_key->bytes, SQLITE_STATIC);
|
||||||
sqlite3_bind_int64(stmt, 5, time(NULL));
|
sqlite3_bind_int64(stmt, 5, time(NULL));
|
||||||
if (sqlite3_step(stmt) != SQLITE_DONE) {
|
if (sqlite3_step(stmt)!=SQLITE_DONE) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ int dc_key_load_self_public(dc_key_t* key, const char* self_addr, dc_sqlite3_t*
|
||||||
stmt = dc_sqlite3_prepare(sql,
|
stmt = dc_sqlite3_prepare(sql,
|
||||||
"SELECT public_key FROM keypairs WHERE addr=? AND is_default=1;");
|
"SELECT public_key FROM keypairs WHERE addr=? AND is_default=1;");
|
||||||
sqlite3_bind_text (stmt, 1, self_addr, -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt, 1, self_addr, -1, SQLITE_STATIC);
|
||||||
if (sqlite3_step(stmt) != SQLITE_ROW) {
|
if (sqlite3_step(stmt)!=SQLITE_ROW) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
dc_key_set_from_stmt(key, stmt, 0, DC_KEY_PUBLIC);
|
dc_key_set_from_stmt(key, stmt, 0, DC_KEY_PUBLIC);
|
||||||
|
@ -299,7 +299,7 @@ int dc_key_load_self_private(dc_key_t* key, const char* self_addr, dc_sqlite3_t*
|
||||||
stmt = dc_sqlite3_prepare(sql,
|
stmt = dc_sqlite3_prepare(sql,
|
||||||
"SELECT private_key FROM keypairs WHERE addr=? AND is_default=1;");
|
"SELECT private_key FROM keypairs WHERE addr=? AND is_default=1;");
|
||||||
sqlite3_bind_text (stmt, 1, self_addr, -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt, 1, self_addr, -1, SQLITE_STATIC);
|
||||||
if (sqlite3_step(stmt) != SQLITE_ROW) {
|
if (sqlite3_step(stmt)!=SQLITE_ROW) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
dc_key_set_from_stmt(key, stmt, 0, DC_KEY_PRIVATE);
|
dc_key_set_from_stmt(key, stmt, 0, DC_KEY_PRIVATE);
|
||||||
|
@ -347,7 +347,7 @@ char* dc_render_base64(const void* buf, size_t buf_bytes, int break_every, const
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (add_checksum == 1/*appended checksum*/) {
|
if (add_checksum==1/*appended checksum*/) {
|
||||||
long checksum = crc_octets(buf, buf_bytes);
|
long checksum = crc_octets(buf, buf_bytes);
|
||||||
uint8_t c[3];
|
uint8_t c[3];
|
||||||
c[0] = (uint8_t)((checksum >> 16)&0xFF);
|
c[0] = (uint8_t)((checksum >> 16)&0xFF);
|
||||||
|
@ -367,7 +367,7 @@ char* dc_render_base64(const void* buf, size_t buf_bytes, int break_every, const
|
||||||
free(temp);
|
free(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add_checksum == 2/*checksum with break character*/) {
|
if (add_checksum==2/*checksum with break character*/) {
|
||||||
long checksum = crc_octets(buf, buf_bytes);
|
long checksum = crc_octets(buf, buf_bytes);
|
||||||
uint8_t c[3];
|
uint8_t c[3];
|
||||||
c[0] = (uint8_t)((checksum >> 16)&0xFF);
|
c[0] = (uint8_t)((checksum >> 16)&0xFF);
|
||||||
|
@ -425,12 +425,12 @@ int dc_key_render_asc_to_file(const dc_key_t* key, const char* file, dc_context_
|
||||||
int success = 0;
|
int success = 0;
|
||||||
char* file_content = NULL;
|
char* file_content = NULL;
|
||||||
|
|
||||||
if (key == NULL || file == NULL || context == NULL) {
|
if (key==NULL || file==NULL || context==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
file_content = dc_key_render_asc(key, NULL);
|
file_content = dc_key_render_asc(key, NULL);
|
||||||
if (file_content == NULL) {
|
if (file_content==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,11 +456,11 @@ char* dc_format_fingerprint(const char* fingerprint)
|
||||||
while (fingerprint[i]) {
|
while (fingerprint[i]) {
|
||||||
dc_strbuilder_catf(&ret, "%c", fingerprint[i]);
|
dc_strbuilder_catf(&ret, "%c", fingerprint[i]);
|
||||||
i++;
|
i++;
|
||||||
if (i != fingerprint_len) {
|
if (i!=fingerprint_len) {
|
||||||
if (i%20 == 0) {
|
if (i%20==0) {
|
||||||
dc_strbuilder_cat(&ret, "\n");
|
dc_strbuilder_cat(&ret, "\n");
|
||||||
}
|
}
|
||||||
else if (i%4 == 0) {
|
else if (i%4==0) {
|
||||||
dc_strbuilder_cat(&ret, " ");
|
dc_strbuilder_cat(&ret, " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -474,7 +474,7 @@ char* dc_format_fingerprint(const char* fingerprint)
|
||||||
40-characters-uppercase-hex format */
|
40-characters-uppercase-hex format */
|
||||||
char* dc_normalize_fingerprint(const char* in)
|
char* dc_normalize_fingerprint(const char* in)
|
||||||
{
|
{
|
||||||
if (in == NULL) {
|
if (in==NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,7 +499,7 @@ char* dc_key_get_fingerprint(const dc_key_t* key)
|
||||||
size_t fingerprint_bytes = 0;
|
size_t fingerprint_bytes = 0;
|
||||||
char* fingerprint_hex = NULL;
|
char* fingerprint_hex = NULL;
|
||||||
|
|
||||||
if (key == NULL) {
|
if (key==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
src/dc_lot.c
22
src/dc_lot.c
|
@ -53,7 +53,7 @@ dc_lot_t* dc_lot_new()
|
||||||
*/
|
*/
|
||||||
void dc_lot_unref(dc_lot_t* set)
|
void dc_lot_unref(dc_lot_t* set)
|
||||||
{
|
{
|
||||||
if (set==NULL || set->magic != DC_LOT_MAGIC) {
|
if (set==NULL || set->magic!=DC_LOT_MAGIC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ void dc_lot_unref(dc_lot_t* set)
|
||||||
|
|
||||||
void dc_lot_empty(dc_lot_t* lot)
|
void dc_lot_empty(dc_lot_t* lot)
|
||||||
{
|
{
|
||||||
if (lot == NULL || lot->magic != DC_LOT_MAGIC) {
|
if (lot==NULL || lot->magic!=DC_LOT_MAGIC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ void dc_lot_empty(dc_lot_t* lot)
|
||||||
*/
|
*/
|
||||||
char* dc_lot_get_text1(const dc_lot_t* lot)
|
char* dc_lot_get_text1(const dc_lot_t* lot)
|
||||||
{
|
{
|
||||||
if (lot == NULL || lot->magic != DC_LOT_MAGIC) {
|
if (lot==NULL || lot->magic!=DC_LOT_MAGIC) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return dc_strdup_keep_null(lot->text1);
|
return dc_strdup_keep_null(lot->text1);
|
||||||
|
@ -118,7 +118,7 @@ char* dc_lot_get_text1(const dc_lot_t* lot)
|
||||||
*/
|
*/
|
||||||
char* dc_lot_get_text2(const dc_lot_t* lot)
|
char* dc_lot_get_text2(const dc_lot_t* lot)
|
||||||
{
|
{
|
||||||
if (lot == NULL || lot->magic != DC_LOT_MAGIC) {
|
if (lot==NULL || lot->magic!=DC_LOT_MAGIC) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return dc_strdup_keep_null(lot->text2);
|
return dc_strdup_keep_null(lot->text2);
|
||||||
|
@ -136,7 +136,7 @@ char* dc_lot_get_text2(const dc_lot_t* lot)
|
||||||
*/
|
*/
|
||||||
int dc_lot_get_text1_meaning(const dc_lot_t* lot)
|
int dc_lot_get_text1_meaning(const dc_lot_t* lot)
|
||||||
{
|
{
|
||||||
if (lot == NULL || lot->magic != DC_LOT_MAGIC) {
|
if (lot==NULL || lot->magic!=DC_LOT_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return lot->text1_meaning;
|
return lot->text1_meaning;
|
||||||
|
@ -154,7 +154,7 @@ int dc_lot_get_text1_meaning(const dc_lot_t* lot)
|
||||||
*/
|
*/
|
||||||
int dc_lot_get_state(const dc_lot_t* lot)
|
int dc_lot_get_state(const dc_lot_t* lot)
|
||||||
{
|
{
|
||||||
if (lot == NULL || lot->magic != DC_LOT_MAGIC) {
|
if (lot==NULL || lot->magic!=DC_LOT_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return lot->state;
|
return lot->state;
|
||||||
|
@ -170,7 +170,7 @@ int dc_lot_get_state(const dc_lot_t* lot)
|
||||||
*/
|
*/
|
||||||
uint32_t dc_lot_get_id(const dc_lot_t* lot)
|
uint32_t dc_lot_get_id(const dc_lot_t* lot)
|
||||||
{
|
{
|
||||||
if (lot == NULL || lot->magic != DC_LOT_MAGIC) {
|
if (lot==NULL || lot->magic!=DC_LOT_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return lot->id;
|
return lot->id;
|
||||||
|
@ -188,7 +188,7 @@ uint32_t dc_lot_get_id(const dc_lot_t* lot)
|
||||||
*/
|
*/
|
||||||
time_t dc_lot_get_timestamp(const dc_lot_t* lot)
|
time_t dc_lot_get_timestamp(const dc_lot_t* lot)
|
||||||
{
|
{
|
||||||
if (lot == NULL || lot->magic != DC_LOT_MAGIC) {
|
if (lot==NULL || lot->magic!=DC_LOT_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return lot->timestamp;
|
return lot->timestamp;
|
||||||
|
@ -197,11 +197,11 @@ time_t dc_lot_get_timestamp(const dc_lot_t* lot)
|
||||||
|
|
||||||
void dc_lot_fill(dc_lot_t* lot, const dc_msg_t* msg, const dc_chat_t* chat, const dc_contact_t* contact, dc_context_t* context)
|
void dc_lot_fill(dc_lot_t* lot, const dc_msg_t* msg, const dc_chat_t* chat, const dc_contact_t* contact, dc_context_t* context)
|
||||||
{
|
{
|
||||||
if (lot == NULL || lot->magic != DC_LOT_MAGIC || msg == NULL) {
|
if (lot==NULL || lot->magic!=DC_LOT_MAGIC || msg==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg->from_id == DC_CONTACT_ID_SELF)
|
if (msg->from_id==DC_CONTACT_ID_SELF)
|
||||||
{
|
{
|
||||||
if (dc_msg_is_info(msg)) {
|
if (dc_msg_is_info(msg)) {
|
||||||
lot->text1 = NULL;
|
lot->text1 = NULL;
|
||||||
|
@ -212,7 +212,7 @@ void dc_lot_fill(dc_lot_t* lot, const dc_msg_t* msg, const dc_chat_t* chat, cons
|
||||||
lot->text1_meaning = DC_TEXT1_SELF;
|
lot->text1_meaning = DC_TEXT1_SELF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (chat == NULL)
|
else if (chat==NULL)
|
||||||
{
|
{
|
||||||
lot->text1 = NULL;
|
lot->text1 = NULL;
|
||||||
lot->text1_meaning = 0;
|
lot->text1_meaning = 0;
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
void dc_mimefactory_init(dc_mimefactory_t* factory, dc_context_t* context)
|
void dc_mimefactory_init(dc_mimefactory_t* factory, dc_context_t* context)
|
||||||
{
|
{
|
||||||
if (factory == NULL || context == NULL) {
|
if (factory==NULL || context==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ void dc_mimefactory_init(dc_mimefactory_t* factory, dc_context_t* context)
|
||||||
|
|
||||||
void dc_mimefactory_empty(dc_mimefactory_t* factory)
|
void dc_mimefactory_empty(dc_mimefactory_t* factory)
|
||||||
{
|
{
|
||||||
if (factory == NULL) {
|
if (factory==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ static void load_from(dc_mimefactory_t* factory)
|
||||||
factory->from_displayname = dc_sqlite3_get_config(factory->context->sql, "displayname", NULL);
|
factory->from_displayname = dc_sqlite3_get_config(factory->context->sql, "displayname", NULL);
|
||||||
|
|
||||||
factory->selfstatus = dc_sqlite3_get_config(factory->context->sql, "selfstatus", NULL);
|
factory->selfstatus = dc_sqlite3_get_config(factory->context->sql, "selfstatus", NULL);
|
||||||
if (factory->selfstatus == NULL) {
|
if (factory->selfstatus==NULL) {
|
||||||
factory->selfstatus = dc_stock_str(factory->context, DC_STR_STATUSLINE);
|
factory->selfstatus = dc_stock_str(factory->context, DC_STR_STATUSLINE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,8 +106,8 @@ int dc_mimefactory_load_msg(dc_mimefactory_t* factory, uint32_t msg_id)
|
||||||
int success = 0;
|
int success = 0;
|
||||||
sqlite3_stmt* stmt = NULL;
|
sqlite3_stmt* stmt = NULL;
|
||||||
|
|
||||||
if (factory == NULL || msg_id <= DC_MSG_ID_LAST_SPECIAL
|
if (factory==NULL || msg_id <= DC_MSG_ID_LAST_SPECIAL
|
||||||
|| factory->context == NULL
|
|| factory->context==NULL
|
||||||
|| factory->msg /*call empty() before */) {
|
|| factory->msg /*call empty() before */) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ int dc_mimefactory_load_msg(dc_mimefactory_t* factory, uint32_t msg_id)
|
||||||
" LEFT JOIN contacts c ON cc.contact_id=c.id "
|
" 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) ";");
|
" WHERE cc.chat_id=? AND cc.contact_id>" DC_STRINGIFY(DC_CONTACT_ID_LAST_SPECIAL) ";");
|
||||||
sqlite3_bind_int(stmt, 1, factory->msg->chat_id);
|
sqlite3_bind_int(stmt, 1, factory->msg->chat_id);
|
||||||
while (sqlite3_step(stmt) == SQLITE_ROW)
|
while (sqlite3_step(stmt)==SQLITE_ROW)
|
||||||
{
|
{
|
||||||
const char* authname = (const char*)sqlite3_column_text(stmt, 0);
|
const char* authname = (const char*)sqlite3_column_text(stmt, 0);
|
||||||
const char* addr = (const char*)sqlite3_column_text(stmt, 1);
|
const char* addr = (const char*)sqlite3_column_text(stmt, 1);
|
||||||
|
@ -190,7 +190,7 @@ int dc_mimefactory_load_msg(dc_mimefactory_t* factory, uint32_t msg_id)
|
||||||
"SELECT rfc724_mid FROM msgs WHERE timestamp=(SELECT max(timestamp) FROM msgs WHERE chat_id=? AND from_id!=?);");
|
"SELECT rfc724_mid FROM msgs WHERE timestamp=(SELECT max(timestamp) FROM msgs WHERE chat_id=? AND from_id!=?);");
|
||||||
sqlite3_bind_int (stmt, 1, factory->msg->chat_id);
|
sqlite3_bind_int (stmt, 1, factory->msg->chat_id);
|
||||||
sqlite3_bind_int (stmt, 2, DC_CONTACT_ID_SELF);
|
sqlite3_bind_int (stmt, 2, DC_CONTACT_ID_SELF);
|
||||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
if (sqlite3_step(stmt)==SQLITE_ROW) {
|
||||||
factory->predecessor = dc_strdup_keep_null((const char*)sqlite3_column_text(stmt, 0));
|
factory->predecessor = dc_strdup_keep_null((const char*)sqlite3_column_text(stmt, 0));
|
||||||
}
|
}
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
|
@ -208,18 +208,18 @@ int dc_mimefactory_load_msg(dc_mimefactory_t* factory, uint32_t msg_id)
|
||||||
"SELECT max(timestamp) FROM msgs WHERE chat_id=? AND id!=?");
|
"SELECT max(timestamp) FROM msgs WHERE chat_id=? AND id!=?");
|
||||||
sqlite3_bind_int (stmt, 1, factory->msg->chat_id);
|
sqlite3_bind_int (stmt, 1, factory->msg->chat_id);
|
||||||
sqlite3_bind_int (stmt, 2, factory->msg->id);
|
sqlite3_bind_int (stmt, 2, factory->msg->id);
|
||||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
if (sqlite3_step(stmt)==SQLITE_ROW) {
|
||||||
prev_msg_time = sqlite3_column_int64(stmt, 0);
|
prev_msg_time = sqlite3_column_int64(stmt, 0);
|
||||||
}
|
}
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
stmt = NULL;
|
stmt = NULL;
|
||||||
|
|
||||||
#define NEW_THREAD_THRESHOLD 24*60*60
|
#define NEW_THREAD_THRESHOLD 24*60*60
|
||||||
if (prev_msg_time != 0 && factory->msg->timestamp - prev_msg_time < NEW_THREAD_THRESHOLD) {
|
if (prev_msg_time!=0 && factory->msg->timestamp - prev_msg_time < NEW_THREAD_THRESHOLD) {
|
||||||
factory->references = dc_param_get(factory->chat->param, DC_PARAM_REFERENCES, NULL);
|
factory->references = dc_param_get(factory->chat->param, DC_PARAM_REFERENCES, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (factory->references == NULL) {
|
if (factory->references==NULL) {
|
||||||
factory->references = dc_create_dummy_references_mid();
|
factory->references = dc_create_dummy_references_mid();
|
||||||
dc_param_set(factory->chat->param, DC_PARAM_REFERENCES, factory->references);
|
dc_param_set(factory->chat->param, DC_PARAM_REFERENCES, factory->references);
|
||||||
dc_chat_update_param(factory->chat);
|
dc_chat_update_param(factory->chat);
|
||||||
|
@ -246,7 +246,7 @@ int dc_mimefactory_load_mdn(dc_mimefactory_t* factory, uint32_t msg_id)
|
||||||
int success = 0;
|
int success = 0;
|
||||||
dc_contact_t* contact = dc_contact_new(factory->context);
|
dc_contact_t* contact = dc_contact_new(factory->context);
|
||||||
|
|
||||||
if (factory == NULL) {
|
if (factory==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,12 +325,12 @@ static struct mailmime* build_body_file(const dc_msg_t* msg, const char* base_na
|
||||||
char* filename_to_send = NULL;
|
char* filename_to_send = NULL;
|
||||||
char* filename_encoded = NULL;
|
char* filename_encoded = NULL;
|
||||||
|
|
||||||
if (pathNfilename == NULL) {
|
if (pathNfilename==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get file name to use for sending (for privacy purposes, we do not transfer the original filenames eg. for images; these names are normally not needed and contain timesamps, running numbers etc.) */
|
/* get file name to use for sending (for privacy purposes, we do not transfer the original filenames eg. for images; these names are normally not needed and contain timesamps, running numbers etc.) */
|
||||||
if (msg->type == DC_MSG_VOICE) {
|
if (msg->type==DC_MSG_VOICE) {
|
||||||
struct tm wanted_struct;
|
struct tm wanted_struct;
|
||||||
memcpy(&wanted_struct, localtime(&msg->timestamp), sizeof(struct tm));
|
memcpy(&wanted_struct, localtime(&msg->timestamp), sizeof(struct tm));
|
||||||
filename_to_send = dc_mprintf("voice-message_%04i-%02i-%02i_%02i-%02i-%02i.%s",
|
filename_to_send = dc_mprintf("voice-message_%04i-%02i-%02i_%02i-%02i-%02i.%s",
|
||||||
|
@ -338,7 +338,7 @@ static struct mailmime* build_body_file(const dc_msg_t* msg, const char* base_na
|
||||||
(int)wanted_struct.tm_hour, (int)wanted_struct.tm_min, (int)wanted_struct.tm_sec,
|
(int)wanted_struct.tm_hour, (int)wanted_struct.tm_min, (int)wanted_struct.tm_sec,
|
||||||
suffix? suffix : "dat");
|
suffix? suffix : "dat");
|
||||||
}
|
}
|
||||||
else if (msg->type == DC_MSG_AUDIO) {
|
else if (msg->type==DC_MSG_AUDIO) {
|
||||||
char* author = dc_param_get(msg->param, DC_PARAM_AUTHORNAME, NULL);
|
char* author = dc_param_get(msg->param, DC_PARAM_AUTHORNAME, NULL);
|
||||||
char* title = dc_param_get(msg->param, DC_PARAM_TRACKNAME, NULL);
|
char* title = dc_param_get(msg->param, DC_PARAM_TRACKNAME, NULL);
|
||||||
if (author && author[0] && title && title[0] && suffix) {
|
if (author && author[0] && title && title[0] && suffix) {
|
||||||
|
@ -350,13 +350,13 @@ static struct mailmime* build_body_file(const dc_msg_t* msg, const char* base_na
|
||||||
free(author);
|
free(author);
|
||||||
free(title);
|
free(title);
|
||||||
}
|
}
|
||||||
else if (msg->type == DC_MSG_IMAGE || msg->type == DC_MSG_GIF) {
|
else if (msg->type==DC_MSG_IMAGE || msg->type==DC_MSG_GIF) {
|
||||||
if (base_name == NULL) {
|
if (base_name==NULL) {
|
||||||
base_name = "image";
|
base_name = "image";
|
||||||
}
|
}
|
||||||
filename_to_send = dc_mprintf("%s.%s", base_name, suffix? suffix : "dat");
|
filename_to_send = dc_mprintf("%s.%s", base_name, suffix? suffix : "dat");
|
||||||
}
|
}
|
||||||
else if (msg->type == DC_MSG_VIDEO) {
|
else if (msg->type==DC_MSG_VIDEO) {
|
||||||
filename_to_send = dc_mprintf("video.%s", suffix? suffix : "dat");
|
filename_to_send = dc_mprintf("video.%s", suffix? suffix : "dat");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -364,7 +364,7 @@ static struct mailmime* build_body_file(const dc_msg_t* msg, const char* base_na
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check mimetype */
|
/* check mimetype */
|
||||||
if (mimetype == NULL && suffix != NULL) {
|
if (mimetype==NULL && suffix!=NULL) {
|
||||||
if (strcmp(suffix, "png")==0) {
|
if (strcmp(suffix, "png")==0) {
|
||||||
mimetype = dc_strdup("image/png");
|
mimetype = dc_strdup("image/png");
|
||||||
}
|
}
|
||||||
|
@ -379,7 +379,7 @@ static struct mailmime* build_body_file(const dc_msg_t* msg, const char* base_na
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mimetype == NULL) {
|
if (mimetype==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,9 +392,9 @@ static struct mailmime* build_body_file(const dc_msg_t* msg, const char* base_na
|
||||||
needs_ext? NULL : dc_strdup(filename_to_send), MAILMIME_MECHANISM_BASE64);
|
needs_ext? NULL : dc_strdup(filename_to_send), MAILMIME_MECHANISM_BASE64);
|
||||||
|
|
||||||
if (needs_ext) {
|
if (needs_ext) {
|
||||||
for (clistiter* cur1 = clist_begin(mime_fields->fld_list); cur1 != NULL; cur1 = clist_next(cur1)) {
|
for (clistiter* cur1 = clist_begin(mime_fields->fld_list); cur1!=NULL; cur1 = clist_next(cur1)) {
|
||||||
struct mailmime_field* field = (struct mailmime_field*)clist_content(cur1);
|
struct mailmime_field* field = (struct mailmime_field*)clist_content(cur1);
|
||||||
if (field && field->fld_type == MAILMIME_FIELD_DISPOSITION && field->fld_data.fld_disposition)
|
if (field && field->fld_type==MAILMIME_FIELD_DISPOSITION && field->fld_data.fld_disposition)
|
||||||
{
|
{
|
||||||
struct mailmime_disposition* file_disposition = field->fld_data.fld_disposition;
|
struct mailmime_disposition* file_disposition = field->fld_data.fld_disposition;
|
||||||
if (file_disposition)
|
if (file_disposition)
|
||||||
|
@ -441,7 +441,7 @@ static char* get_subject(const dc_chat_t* chat, const dc_msg_t* msg, int afwd_em
|
||||||
char* raw_subject = dc_msg_get_summarytext_by_raw(msg->type, msg->text, msg->param, DC_APPROX_SUBJECT_CHARS, context);
|
char* raw_subject = dc_msg_get_summarytext_by_raw(msg->type, msg->text, msg->param, DC_APPROX_SUBJECT_CHARS, context);
|
||||||
const char* fwd = afwd_email? "Fwd: " : "";
|
const char* fwd = afwd_email? "Fwd: " : "";
|
||||||
|
|
||||||
if (dc_param_get_int(msg->param, DC_PARAM_CMD, 0) == DC_CMD_AUTOCRYPT_SETUP_MESSAGE)
|
if (dc_param_get_int(msg->param, DC_PARAM_CMD, 0)==DC_CMD_AUTOCRYPT_SETUP_MESSAGE)
|
||||||
{
|
{
|
||||||
ret = dc_stock_str(context, DC_STR_AC_SETUP_MSG_SUBJECT); /* do not add the "Chat:" prefix for setup messages */
|
ret = dc_stock_str(context, DC_STR_AC_SETUP_MSG_SUBJECT); /* do not add the "Chat:" prefix for setup messages */
|
||||||
}
|
}
|
||||||
|
@ -461,8 +461,8 @@ static char* get_subject(const dc_chat_t* chat, const dc_msg_t* msg, int afwd_em
|
||||||
|
|
||||||
int dc_mimefactory_render(dc_mimefactory_t* factory)
|
int dc_mimefactory_render(dc_mimefactory_t* factory)
|
||||||
{
|
{
|
||||||
if (factory == NULL
|
if (factory==NULL
|
||||||
|| factory->loaded == DC_MF_NOTHING_LOADED
|
|| factory->loaded==DC_MF_NOTHING_LOADED
|
||||||
|| factory->out/*call empty() before*/) {
|
|| factory->out/*call empty() before*/) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -536,7 +536,7 @@ int dc_mimefactory_render(dc_mimefactory_t* factory)
|
||||||
mailmime_set_imf_fields(message, imf_fields);
|
mailmime_set_imf_fields(message, imf_fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (factory->loaded == DC_MF_MSG_LOADED)
|
if (factory->loaded==DC_MF_MSG_LOADED)
|
||||||
{
|
{
|
||||||
/* Render a normal message
|
/* Render a normal message
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
@ -547,14 +547,14 @@ int dc_mimefactory_render(dc_mimefactory_t* factory)
|
||||||
struct mailmime* meta_part = NULL;
|
struct mailmime* meta_part = NULL;
|
||||||
char* placeholdertext = NULL;
|
char* placeholdertext = NULL;
|
||||||
|
|
||||||
if (chat->type == DC_CHAT_TYPE_VERIFIED_GROUP) {
|
if (chat->type==DC_CHAT_TYPE_VERIFIED_GROUP) {
|
||||||
mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Verified"), strdup("1")));
|
mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Verified"), strdup("1")));
|
||||||
force_plaintext = 0;
|
force_plaintext = 0;
|
||||||
e2ee_guaranteed = 1;
|
e2ee_guaranteed = 1;
|
||||||
min_verified = DC_BIDIRECT_VERIFIED;
|
min_verified = DC_BIDIRECT_VERIFIED;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ((force_plaintext = dc_param_get_int(factory->msg->param, DC_PARAM_FORCE_PLAINTEXT, 0)) == 0) {
|
if ((force_plaintext = dc_param_get_int(factory->msg->param, DC_PARAM_FORCE_PLAINTEXT, 0))==0) {
|
||||||
e2ee_guaranteed = dc_param_get_int(factory->msg->param, DC_PARAM_GUARANTEE_E2EE, 0);
|
e2ee_guaranteed = dc_param_get_int(factory->msg->param, DC_PARAM_GUARANTEE_E2EE, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -567,14 +567,14 @@ int dc_mimefactory_render(dc_mimefactory_t* factory)
|
||||||
mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-Name"), dc_encode_header_words(chat->name)));
|
mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-Name"), dc_encode_header_words(chat->name)));
|
||||||
|
|
||||||
|
|
||||||
if (command == DC_CMD_MEMBER_REMOVED_FROM_GROUP)
|
if (command==DC_CMD_MEMBER_REMOVED_FROM_GROUP)
|
||||||
{
|
{
|
||||||
char* email_to_remove = dc_param_get(msg->param, DC_PARAM_CMD_ARG, NULL);
|
char* email_to_remove = dc_param_get(msg->param, DC_PARAM_CMD_ARG, NULL);
|
||||||
if (email_to_remove) {
|
if (email_to_remove) {
|
||||||
mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-Member-Removed"), email_to_remove));
|
mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-Member-Removed"), email_to_remove));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (command == DC_CMD_MEMBER_ADDED_TO_GROUP)
|
else if (command==DC_CMD_MEMBER_ADDED_TO_GROUP)
|
||||||
{
|
{
|
||||||
char* email_to_add = dc_param_get(msg->param, DC_PARAM_CMD_ARG, NULL);
|
char* email_to_add = dc_param_get(msg->param, DC_PARAM_CMD_ARG, NULL);
|
||||||
if (email_to_add) {
|
if (email_to_add) {
|
||||||
|
@ -587,11 +587,11 @@ int dc_mimefactory_render(dc_mimefactory_t* factory)
|
||||||
mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Secure-Join"), strdup("vg-member-added")));
|
mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Secure-Join"), strdup("vg-member-added")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (command == DC_CMD_GROUPNAME_CHANGED)
|
else if (command==DC_CMD_GROUPNAME_CHANGED)
|
||||||
{
|
{
|
||||||
mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-Name-Changed"), strdup("1")));
|
mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-Name-Changed"), strdup("1")));
|
||||||
}
|
}
|
||||||
else if (command == DC_CMD_GROUPIMAGE_CHANGED)
|
else if (command==DC_CMD_GROUPIMAGE_CHANGED)
|
||||||
{
|
{
|
||||||
grpimage = dc_param_get(msg->param, DC_PARAM_CMD_ARG, NULL);
|
grpimage = dc_param_get(msg->param, DC_PARAM_CMD_ARG, NULL);
|
||||||
if (grpimage==NULL) {
|
if (grpimage==NULL) {
|
||||||
|
@ -600,12 +600,12 @@ int dc_mimefactory_render(dc_mimefactory_t* factory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command == DC_CMD_AUTOCRYPT_SETUP_MESSAGE) {
|
if (command==DC_CMD_AUTOCRYPT_SETUP_MESSAGE) {
|
||||||
mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Autocrypt-Setup-Message"), strdup("v1")));
|
mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Autocrypt-Setup-Message"), strdup("v1")));
|
||||||
placeholdertext = dc_stock_str(factory->context, DC_STR_AC_SETUP_MSG_BODY);
|
placeholdertext = dc_stock_str(factory->context, DC_STR_AC_SETUP_MSG_BODY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command == DC_CMD_SECUREJOIN_MESSAGE) {
|
if (command==DC_CMD_SECUREJOIN_MESSAGE) {
|
||||||
char* step = dc_param_get(msg->param, DC_PARAM_CMD_ARG, NULL);
|
char* step = dc_param_get(msg->param, DC_PARAM_CMD_ARG, NULL);
|
||||||
if (step) {
|
if (step) {
|
||||||
dc_log_info(msg->context, 0, "sending secure-join message '%s' >>>>>>>>>>>>>>>>>>>>>>>>>", step);
|
dc_log_info(msg->context, 0, "sending secure-join message '%s' >>>>>>>>>>>>>>>>>>>>>>>>>", step);
|
||||||
|
@ -647,9 +647,9 @@ int dc_mimefactory_render(dc_mimefactory_t* factory)
|
||||||
dc_msg_unref(meta);
|
dc_msg_unref(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg->type == DC_MSG_VOICE || msg->type == DC_MSG_AUDIO || msg->type == DC_MSG_VIDEO)
|
if (msg->type==DC_MSG_VOICE || msg->type==DC_MSG_AUDIO || msg->type==DC_MSG_VIDEO)
|
||||||
{
|
{
|
||||||
if (msg->type == DC_MSG_VOICE) {
|
if (msg->type==DC_MSG_VOICE) {
|
||||||
mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Voice-Message"), strdup("1")));
|
mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Voice-Message"), strdup("1")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -700,7 +700,7 @@ int dc_mimefactory_render(dc_mimefactory_t* factory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parts == 0) {
|
if (parts==0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -709,7 +709,7 @@ int dc_mimefactory_render(dc_mimefactory_t* factory)
|
||||||
parts++;
|
parts++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (factory->loaded == DC_MF_MDN_LOADED)
|
else if (factory->loaded==DC_MF_MDN_LOADED)
|
||||||
{
|
{
|
||||||
/* Render a MDN
|
/* Render a MDN
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
@ -784,7 +784,7 @@ int dc_mimefactory_render(dc_mimefactory_t* factory)
|
||||||
struct mailimf_subject* subject = mailimf_subject_new(dc_encode_header_words(subject_str));
|
struct mailimf_subject* subject = mailimf_subject_new(dc_encode_header_words(subject_str));
|
||||||
mailimf_fields_add(imf_fields, mailimf_field_new(MAILIMF_FIELD_SUBJECT, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, subject, NULL, NULL, NULL));
|
mailimf_fields_add(imf_fields, mailimf_field_new(MAILIMF_FIELD_SUBJECT, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, subject, NULL, NULL, NULL));
|
||||||
|
|
||||||
if (force_plaintext != DC_FP_NO_AUTOCRYPT_HEADER) {
|
if (force_plaintext!=DC_FP_NO_AUTOCRYPT_HEADER) {
|
||||||
dc_e2ee_encrypt(factory->context, factory->recipients_addr, force_plaintext, e2ee_guaranteed, min_verified, message, &e2ee_helper);
|
dc_e2ee_encrypt(factory->context, factory->recipients_addr, force_plaintext, e2ee_guaranteed, min_verified, message, &e2ee_helper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ static void display_mime_disposition(struct mailmime_disposition * disposition)
|
||||||
clistiter * cur;
|
clistiter * cur;
|
||||||
|
|
||||||
for(cur = clist_begin(disposition->dsp_parms) ;
|
for(cur = clist_begin(disposition->dsp_parms) ;
|
||||||
cur != NULL ; cur = clist_next(cur)) {
|
cur!=NULL ; cur = clist_next(cur)) {
|
||||||
struct mailmime_disposition_parm * param;
|
struct mailmime_disposition_parm * param;
|
||||||
|
|
||||||
param = (struct mailmime_disposition_parm*)clist_content(cur);
|
param = (struct mailmime_disposition_parm*)clist_content(cur);
|
||||||
|
@ -98,7 +98,7 @@ static void display_mime_fields(struct mailmime_fields * fields)
|
||||||
{
|
{
|
||||||
clistiter * cur;
|
clistiter * cur;
|
||||||
|
|
||||||
for(cur = clist_begin(fields->fld_list) ; cur != NULL ; cur = clist_next(cur)) {
|
for(cur = clist_begin(fields->fld_list) ; cur!=NULL ; cur = clist_next(cur)) {
|
||||||
struct mailmime_field * field;
|
struct mailmime_field * field;
|
||||||
|
|
||||||
field = (struct mailmime_field*)clist_content(cur);
|
field = (struct mailmime_field*)clist_content(cur);
|
||||||
|
@ -120,7 +120,7 @@ static void display_orig_date(struct mailimf_orig_date * orig_date)
|
||||||
|
|
||||||
static void display_mailbox(struct mailimf_mailbox * mb)
|
static void display_mailbox(struct mailimf_mailbox * mb)
|
||||||
{
|
{
|
||||||
if (mb->mb_display_name != NULL)
|
if (mb->mb_display_name!=NULL)
|
||||||
printf("%s ", mb->mb_display_name);
|
printf("%s ", mb->mb_display_name);
|
||||||
printf("<%s>", mb->mb_addr_spec);
|
printf("<%s>", mb->mb_addr_spec);
|
||||||
}
|
}
|
||||||
|
@ -129,14 +129,14 @@ static void display_mailbox_list(struct mailimf_mailbox_list * mb_list)
|
||||||
{
|
{
|
||||||
clistiter * cur;
|
clistiter * cur;
|
||||||
|
|
||||||
for(cur = clist_begin(mb_list->mb_list) ; cur != NULL ;
|
for(cur = clist_begin(mb_list->mb_list) ; cur!=NULL ;
|
||||||
cur = clist_next(cur)) {
|
cur = clist_next(cur)) {
|
||||||
struct mailimf_mailbox * mb;
|
struct mailimf_mailbox * mb;
|
||||||
|
|
||||||
mb = (struct mailimf_mailbox*)clist_content(cur);
|
mb = (struct mailimf_mailbox*)clist_content(cur);
|
||||||
|
|
||||||
display_mailbox(mb);
|
display_mailbox(mb);
|
||||||
if (clist_next(cur) != NULL) {
|
if (clist_next(cur)!=NULL) {
|
||||||
printf(", ");
|
printf(", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ static void display_group(struct mailimf_group * group)
|
||||||
clistiter * cur;
|
clistiter * cur;
|
||||||
|
|
||||||
printf("%s: ", group->grp_display_name);
|
printf("%s: ", group->grp_display_name);
|
||||||
for(cur = clist_begin(group->grp_mb_list->mb_list) ; cur != NULL ; cur = clist_next(cur)) {
|
for(cur = clist_begin(group->grp_mb_list->mb_list) ; cur!=NULL ; cur = clist_next(cur)) {
|
||||||
struct mailimf_mailbox * mb;
|
struct mailimf_mailbox * mb;
|
||||||
|
|
||||||
mb = (struct mailimf_mailbox*)clist_content(cur);
|
mb = (struct mailimf_mailbox*)clist_content(cur);
|
||||||
|
@ -173,7 +173,7 @@ static void display_address_list(struct mailimf_address_list * addr_list)
|
||||||
{
|
{
|
||||||
clistiter * cur;
|
clistiter * cur;
|
||||||
|
|
||||||
for(cur = clist_begin(addr_list->ad_list) ; cur != NULL ;
|
for(cur = clist_begin(addr_list->ad_list) ; cur!=NULL ;
|
||||||
cur = clist_next(cur)) {
|
cur = clist_next(cur)) {
|
||||||
struct mailimf_address * addr;
|
struct mailimf_address * addr;
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ static void display_address_list(struct mailimf_address_list * addr_list)
|
||||||
|
|
||||||
display_address(addr);
|
display_address(addr);
|
||||||
|
|
||||||
if (clist_next(cur) != NULL) {
|
if (clist_next(cur)!=NULL) {
|
||||||
printf(", ");
|
printf(", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ static void display_fields(struct mailimf_fields * fields)
|
||||||
{
|
{
|
||||||
clistiter * cur;
|
clistiter * cur;
|
||||||
|
|
||||||
for(cur = clist_begin(fields->fld_list) ; cur != NULL ;
|
for(cur = clist_begin(fields->fld_list) ; cur!=NULL ;
|
||||||
cur = clist_next(cur)) {
|
cur = clist_next(cur)) {
|
||||||
struct mailimf_field * f;
|
struct mailimf_field * f;
|
||||||
|
|
||||||
|
@ -336,7 +336,7 @@ static void print_mime(struct mailmime * mime)
|
||||||
{
|
{
|
||||||
clistiter * cur;
|
clistiter * cur;
|
||||||
|
|
||||||
if (mime == NULL) {
|
if (mime==NULL) {
|
||||||
printf("ERROR: NULL given to print_mime()\n");
|
printf("ERROR: NULL given to print_mime()\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -353,8 +353,8 @@ static void print_mime(struct mailmime * mime)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mime->mm_mime_fields != NULL) {
|
if (mime->mm_mime_fields!=NULL) {
|
||||||
if (clist_begin(mime->mm_mime_fields->fld_list) != NULL) {
|
if (clist_begin(mime->mm_mime_fields->fld_list)!=NULL) {
|
||||||
printf("--------------------------------<mime-headers>--------------------------------\n");
|
printf("--------------------------------<mime-headers>--------------------------------\n");
|
||||||
display_mime_fields(mime->mm_mime_fields);
|
display_mime_fields(mime->mm_mime_fields);
|
||||||
printf("--------------------------------</mime-headers>-------------------------------\n");
|
printf("--------------------------------</mime-headers>-------------------------------\n");
|
||||||
|
@ -369,7 +369,7 @@ static void print_mime(struct mailmime * mime)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MAILMIME_MULTIPLE:
|
case MAILMIME_MULTIPLE:
|
||||||
for(cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
|
for(cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur!=NULL ; cur = clist_next(cur)) {
|
||||||
printf("---------------------------<mime-part-of-multiple>----------------------------\n");
|
printf("---------------------------<mime-part-of-multiple>----------------------------\n");
|
||||||
print_mime((struct mailmime*)clist_content(cur));
|
print_mime((struct mailmime*)clist_content(cur));
|
||||||
printf("---------------------------</mime-part-of-multiple>---------------------------\n");
|
printf("---------------------------</mime-part-of-multiple>---------------------------\n");
|
||||||
|
@ -378,13 +378,13 @@ static void print_mime(struct mailmime * mime)
|
||||||
|
|
||||||
case MAILMIME_MESSAGE:
|
case MAILMIME_MESSAGE:
|
||||||
if (mime->mm_data.mm_message.mm_fields) {
|
if (mime->mm_data.mm_message.mm_fields) {
|
||||||
if (clist_begin(mime->mm_data.mm_message.mm_fields->fld_list) != NULL) {
|
if (clist_begin(mime->mm_data.mm_message.mm_fields->fld_list)!=NULL) {
|
||||||
printf("-------------------------------<email-headers>--------------------------------\n");
|
printf("-------------------------------<email-headers>--------------------------------\n");
|
||||||
display_fields(mime->mm_data.mm_message.mm_fields);
|
display_fields(mime->mm_data.mm_message.mm_fields);
|
||||||
printf("-------------------------------</email-headers>-------------------------------\n");
|
printf("-------------------------------</email-headers>-------------------------------\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
|
if (mime->mm_data.mm_message.mm_msg_mime!=NULL) {
|
||||||
printf("----------------------------<mime-part-of-message>----------------------------\n");
|
printf("----------------------------<mime-part-of-message>----------------------------\n");
|
||||||
print_mime(mime->mm_data.mm_message.mm_msg_mime);
|
print_mime(mime->mm_data.mm_message.mm_msg_mime);
|
||||||
printf("----------------------------</mime-part-of-message>---------------------------\n");
|
printf("----------------------------</mime-part-of-message>---------------------------\n");
|
||||||
|
@ -446,10 +446,10 @@ dc_hash_t* mailimf_get_recipients(struct mailimf_fields* imffields)
|
||||||
for (cur2 = clist_begin(addr_list->ad_list); cur2!=NULL ; cur2=clist_next(cur2)) {
|
for (cur2 = clist_begin(addr_list->ad_list); cur2!=NULL ; cur2=clist_next(cur2)) {
|
||||||
struct mailimf_address* adr = (struct mailimf_address*)clist_content(cur2);
|
struct mailimf_address* adr = (struct mailimf_address*)clist_content(cur2);
|
||||||
if (adr) {
|
if (adr) {
|
||||||
if (adr->ad_type == MAILIMF_ADDRESS_MAILBOX) {
|
if (adr->ad_type==MAILIMF_ADDRESS_MAILBOX) {
|
||||||
mailimf_get_recipients__add_addr(recipients, adr->ad_data.ad_mailbox);
|
mailimf_get_recipients__add_addr(recipients, adr->ad_data.ad_mailbox);
|
||||||
}
|
}
|
||||||
else if (adr->ad_type == MAILIMF_ADDRESS_GROUP) {
|
else if (adr->ad_type==MAILIMF_ADDRESS_GROUP) {
|
||||||
struct mailimf_group* group = adr->ad_data.ad_group;
|
struct mailimf_group* group = adr->ad_data.ad_group;
|
||||||
if (group && group->grp_mb_list) {
|
if (group && group->grp_mb_list) {
|
||||||
clistiter* cur3;
|
clistiter* cur3;
|
||||||
|
@ -482,7 +482,7 @@ struct mailmime_parameter* mailmime_find_ct_parameter(struct mailmime* mime, con
|
||||||
}
|
}
|
||||||
|
|
||||||
clistiter* cur;
|
clistiter* cur;
|
||||||
for (cur = clist_begin(mime->mm_content_type->ct_parameters); cur != NULL; cur = clist_next(cur)) {
|
for (cur = clist_begin(mime->mm_content_type->ct_parameters); cur!=NULL; cur = clist_next(cur)) {
|
||||||
struct mailmime_parameter* param = (struct mailmime_parameter*)clist_content(cur);
|
struct mailmime_parameter* param = (struct mailmime_parameter*)clist_content(cur);
|
||||||
if (param && param->pa_name) {
|
if (param && param->pa_name) {
|
||||||
if (strcmp(param->pa_name, name)==0) {
|
if (strcmp(param->pa_name, name)==0) {
|
||||||
|
@ -503,18 +503,18 @@ int mailmime_transfer_decode(struct mailmime* mime, const char** ret_decoded_dat
|
||||||
size_t decoded_data_bytes = 0;
|
size_t decoded_data_bytes = 0;
|
||||||
char* transfer_decoding_buffer = NULL; /* mmap_string_unref()'d if set */
|
char* transfer_decoding_buffer = NULL; /* mmap_string_unref()'d if set */
|
||||||
|
|
||||||
if (mime == NULL || ret_decoded_data == NULL || ret_decoded_data_bytes == NULL || ret_to_mmap_string_unref == NULL
|
if (mime==NULL || ret_decoded_data==NULL || ret_decoded_data_bytes==NULL || ret_to_mmap_string_unref==NULL
|
||||||
|| *ret_decoded_data != NULL || *ret_decoded_data_bytes != 0 || *ret_to_mmap_string_unref != NULL) {
|
|| *ret_decoded_data!=NULL || *ret_decoded_data_bytes!=0 || *ret_to_mmap_string_unref!=NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mime_data = mime->mm_data.mm_single;
|
mime_data = mime->mm_data.mm_single;
|
||||||
|
|
||||||
if (mime->mm_mime_fields != NULL) {
|
if (mime->mm_mime_fields!=NULL) {
|
||||||
clistiter* cur;
|
clistiter* cur;
|
||||||
for (cur = clist_begin(mime->mm_mime_fields->fld_list); cur != NULL; cur = clist_next(cur)) {
|
for (cur = clist_begin(mime->mm_mime_fields->fld_list); cur!=NULL; cur = clist_next(cur)) {
|
||||||
struct mailmime_field* field = (struct mailmime_field*)clist_content(cur);
|
struct mailmime_field* field = (struct mailmime_field*)clist_content(cur);
|
||||||
if (field && field->fld_type == MAILMIME_FIELD_TRANSFER_ENCODING && field->fld_data.fld_encoding) {
|
if (field && field->fld_type==MAILMIME_FIELD_TRANSFER_ENCODING && field->fld_data.fld_encoding) {
|
||||||
mime_transfer_encoding = field->fld_data.fld_encoding->enc_type;
|
mime_transfer_encoding = field->fld_data.fld_encoding->enc_type;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -522,13 +522,13 @@ int mailmime_transfer_decode(struct mailmime* mime, const char** ret_decoded_dat
|
||||||
}
|
}
|
||||||
|
|
||||||
/* regard `Content-Transfer-Encoding:` */
|
/* regard `Content-Transfer-Encoding:` */
|
||||||
if (mime_transfer_encoding == MAILMIME_MECHANISM_7BIT
|
if (mime_transfer_encoding==MAILMIME_MECHANISM_7BIT
|
||||||
|| mime_transfer_encoding == MAILMIME_MECHANISM_8BIT
|
|| mime_transfer_encoding==MAILMIME_MECHANISM_8BIT
|
||||||
|| mime_transfer_encoding == MAILMIME_MECHANISM_BINARY)
|
|| mime_transfer_encoding==MAILMIME_MECHANISM_BINARY)
|
||||||
{
|
{
|
||||||
decoded_data = mime_data->dt_data.dt_text.dt_data;
|
decoded_data = mime_data->dt_data.dt_text.dt_data;
|
||||||
decoded_data_bytes = mime_data->dt_data.dt_text.dt_length;
|
decoded_data_bytes = mime_data->dt_data.dt_text.dt_length;
|
||||||
if (decoded_data == NULL || decoded_data_bytes <= 0) {
|
if (decoded_data==NULL || decoded_data_bytes <= 0) {
|
||||||
return 0; /* no error - but no data */
|
return 0; /* no error - but no data */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -539,7 +539,7 @@ int mailmime_transfer_decode(struct mailmime* mime, const char** ret_decoded_dat
|
||||||
r = mailmime_part_parse(mime_data->dt_data.dt_text.dt_data, mime_data->dt_data.dt_text.dt_length,
|
r = mailmime_part_parse(mime_data->dt_data.dt_text.dt_data, mime_data->dt_data.dt_text.dt_length,
|
||||||
¤t_index, mime_transfer_encoding,
|
¤t_index, mime_transfer_encoding,
|
||||||
&transfer_decoding_buffer, &decoded_data_bytes);
|
&transfer_decoding_buffer, &decoded_data_bytes);
|
||||||
if (r != MAILIMF_NO_ERROR || transfer_decoding_buffer == NULL || decoded_data_bytes <= 0) {
|
if (r!=MAILIMF_NO_ERROR || transfer_decoding_buffer==NULL || decoded_data_bytes <= 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
decoded_data = transfer_decoding_buffer;
|
decoded_data = transfer_decoding_buffer;
|
||||||
|
@ -554,7 +554,7 @@ int mailmime_transfer_decode(struct mailmime* mime, const char** ret_decoded_dat
|
||||||
|
|
||||||
struct mailimf_fields* mailmime_find_mailimf_fields(struct mailmime* mime)
|
struct mailimf_fields* mailmime_find_mailimf_fields(struct mailmime* mime)
|
||||||
{
|
{
|
||||||
if (mime == NULL) {
|
if (mime==NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -577,7 +577,7 @@ struct mailimf_fields* mailmime_find_mailimf_fields(struct mailmime* mime)
|
||||||
|
|
||||||
char* mailimf_find_first_addr(const struct mailimf_mailbox_list* mb_list)
|
char* mailimf_find_first_addr(const struct mailimf_mailbox_list* mb_list)
|
||||||
{
|
{
|
||||||
if (mb_list == NULL) {
|
if (mb_list==NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -593,7 +593,7 @@ char* mailimf_find_first_addr(const struct mailimf_mailbox_list* mb_list)
|
||||||
|
|
||||||
struct mailimf_field* mailimf_find_field(struct mailimf_fields* header, int wanted_fld_type)
|
struct mailimf_field* mailimf_find_field(struct mailimf_fields* header, int wanted_fld_type)
|
||||||
{
|
{
|
||||||
if (header == NULL || header->fld_list == NULL) {
|
if (header==NULL || header->fld_list==NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,7 +602,7 @@ struct mailimf_field* mailimf_find_field(struct mailimf_fields* header, int want
|
||||||
struct mailimf_field* field = (struct mailimf_field*)clist_content(cur1);
|
struct mailimf_field* field = (struct mailimf_field*)clist_content(cur1);
|
||||||
if (field)
|
if (field)
|
||||||
{
|
{
|
||||||
if (field->fld_type == wanted_fld_type) {
|
if (field->fld_type==wanted_fld_type) {
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -615,14 +615,14 @@ struct mailimf_field* mailimf_find_field(struct mailimf_fields* header, int want
|
||||||
struct mailimf_optional_field* mailimf_find_optional_field(struct mailimf_fields* header, const char* wanted_fld_name)
|
struct mailimf_optional_field* mailimf_find_optional_field(struct mailimf_fields* header, const char* wanted_fld_name)
|
||||||
{
|
{
|
||||||
/* Note: the function does not return fields with no value set! */
|
/* Note: the function does not return fields with no value set! */
|
||||||
if (header == NULL || header->fld_list == NULL) {
|
if (header==NULL || header->fld_list==NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (clistiter* cur1 = clist_begin(header->fld_list); cur1!=NULL ; cur1=clist_next(cur1))
|
for (clistiter* cur1 = clist_begin(header->fld_list); cur1!=NULL ; cur1=clist_next(cur1))
|
||||||
{
|
{
|
||||||
struct mailimf_field* field = (struct mailimf_field*)clist_content(cur1);
|
struct mailimf_field* field = (struct mailimf_field*)clist_content(cur1);
|
||||||
if (field && field->fld_type == MAILIMF_FIELD_OPTIONAL_FIELD)
|
if (field && field->fld_type==MAILIMF_FIELD_OPTIONAL_FIELD)
|
||||||
{
|
{
|
||||||
struct mailimf_optional_field* optional_field = field->fld_data.fld_optional_field;
|
struct mailimf_optional_field* optional_field = field->fld_data.fld_optional_field;
|
||||||
if (optional_field && optional_field->fld_name && optional_field->fld_value && strcasecmp(optional_field->fld_name, wanted_fld_name)==0) {
|
if (optional_field && optional_field->fld_name && optional_field->fld_value && strcasecmp(optional_field->fld_name, wanted_fld_name)==0) {
|
||||||
|
@ -637,10 +637,10 @@ struct mailimf_optional_field* mailimf_find_optional_field(struct mailimf_fields
|
||||||
|
|
||||||
static int mailmime_is_attachment_disposition(struct mailmime* mime)
|
static int mailmime_is_attachment_disposition(struct mailmime* mime)
|
||||||
{
|
{
|
||||||
if (mime->mm_mime_fields != NULL) {
|
if (mime->mm_mime_fields!=NULL) {
|
||||||
for (clistiter* cur = clist_begin(mime->mm_mime_fields->fld_list); cur != NULL; cur = clist_next(cur)) {
|
for (clistiter* cur = clist_begin(mime->mm_mime_fields->fld_list); cur!=NULL; cur = clist_next(cur)) {
|
||||||
struct mailmime_field* field = (struct mailmime_field*)clist_content(cur);
|
struct mailmime_field* field = (struct mailmime_field*)clist_content(cur);
|
||||||
if (field && field->fld_type == MAILMIME_FIELD_DISPOSITION && field->fld_data.fld_disposition) {
|
if (field && field->fld_type==MAILMIME_FIELD_DISPOSITION && field->fld_data.fld_disposition) {
|
||||||
if (field->fld_data.fld_disposition->dsp_type
|
if (field->fld_data.fld_disposition->dsp_type
|
||||||
&& field->fld_data.fld_disposition->dsp_type->dsp_type==MAILMIME_DISPOSITION_TYPE_ATTACHMENT)
|
&& field->fld_data.fld_disposition->dsp_type->dsp_type==MAILMIME_DISPOSITION_TYPE_ATTACHMENT)
|
||||||
{
|
{
|
||||||
|
@ -671,10 +671,10 @@ static int mailmime_get_mime_type(struct mailmime* mime, int* msg_type)
|
||||||
#define DC_MIMETYPE_AC_SETUP_FILE 111
|
#define DC_MIMETYPE_AC_SETUP_FILE 111
|
||||||
|
|
||||||
struct mailmime_content* c = mime->mm_content_type;
|
struct mailmime_content* c = mime->mm_content_type;
|
||||||
int dummy = 0; if (msg_type == NULL) { msg_type = &dummy; }
|
int dummy = 0; if (msg_type==NULL) { msg_type = &dummy; }
|
||||||
*msg_type = DC_MSG_UNDEFINED;
|
*msg_type = DC_MSG_UNDEFINED;
|
||||||
|
|
||||||
if (c == NULL || c->ct_type == NULL) {
|
if (c==NULL || c->ct_type==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -721,7 +721,7 @@ static int mailmime_get_mime_type(struct mailmime* mime, int* msg_type)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
*msg_type = DC_MSG_FILE;
|
*msg_type = DC_MSG_FILE;
|
||||||
if (c->ct_type->tp_data.tp_discrete_type->dt_type == MAILMIME_DISCRETE_TYPE_APPLICATION
|
if (c->ct_type->tp_data.tp_discrete_type->dt_type==MAILMIME_DISCRETE_TYPE_APPLICATION
|
||||||
&& strcmp(c->ct_subtype, "autocrypt-setup")==0) {
|
&& strcmp(c->ct_subtype, "autocrypt-setup")==0) {
|
||||||
return DC_MIMETYPE_AC_SETUP_FILE; /* application/autocrypt-setup */
|
return DC_MIMETYPE_AC_SETUP_FILE; /* application/autocrypt-setup */
|
||||||
}
|
}
|
||||||
|
@ -730,7 +730,7 @@ static int mailmime_get_mime_type(struct mailmime* mime, int* msg_type)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MAILMIME_TYPE_COMPOSITE_TYPE:
|
case MAILMIME_TYPE_COMPOSITE_TYPE:
|
||||||
if (c->ct_type->tp_data.tp_composite_type->ct_type == MAILMIME_COMPOSITE_TYPE_MULTIPART)
|
if (c->ct_type->tp_data.tp_composite_type->ct_type==MAILMIME_COMPOSITE_TYPE_MULTIPART)
|
||||||
{
|
{
|
||||||
if (strcmp(c->ct_subtype, "alternative")==0) {
|
if (strcmp(c->ct_subtype, "alternative")==0) {
|
||||||
return DC_MIMETYPE_MP_ALTERNATIVE;
|
return DC_MIMETYPE_MP_ALTERNATIVE;
|
||||||
|
@ -754,7 +754,7 @@ static int mailmime_get_mime_type(struct mailmime* mime, int* msg_type)
|
||||||
return DC_MIMETYPE_MP_OTHER;
|
return DC_MIMETYPE_MP_OTHER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (c->ct_type->tp_data.tp_composite_type->ct_type == MAILMIME_COMPOSITE_TYPE_MESSAGE)
|
else if (c->ct_type->tp_data.tp_composite_type->ct_type==MAILMIME_COMPOSITE_TYPE_MESSAGE)
|
||||||
{
|
{
|
||||||
/* Enacapsulated messages, see https://www.w3.org/Protocols/rfc1341/7_3_Message.html
|
/* Enacapsulated messages, see https://www.w3.org/Protocols/rfc1341/7_3_Message.html
|
||||||
Also used as part "message/disposition-notification" of "multipart/report", which, however, will be handled separatedly.
|
Also used as part "message/disposition-notification" of "multipart/report", which, however, will be handled separatedly.
|
||||||
|
@ -795,7 +795,7 @@ static dc_mimepart_t* dc_mimepart_new(void)
|
||||||
|
|
||||||
static void dc_mimepart_unref(dc_mimepart_t* mimepart)
|
static void dc_mimepart_unref(dc_mimepart_t* mimepart)
|
||||||
{
|
{
|
||||||
if (mimepart == NULL) {
|
if (mimepart==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -862,7 +862,7 @@ dc_mimeparser_t* dc_mimeparser_new(const char* blobdir, dc_context_t* context)
|
||||||
*/
|
*/
|
||||||
void dc_mimeparser_unref(dc_mimeparser_t* mimeparser)
|
void dc_mimeparser_unref(dc_mimeparser_t* mimeparser)
|
||||||
{
|
{
|
||||||
if (mimeparser == NULL) {
|
if (mimeparser==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -888,7 +888,7 @@ void dc_mimeparser_unref(dc_mimeparser_t* mimeparser)
|
||||||
*/
|
*/
|
||||||
void dc_mimeparser_empty(dc_mimeparser_t* mimeparser)
|
void dc_mimeparser_empty(dc_mimeparser_t* mimeparser)
|
||||||
{
|
{
|
||||||
if (mimeparser == NULL) {
|
if (mimeparser==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -957,7 +957,7 @@ static void do_add_single_file_part(dc_mimeparser_t* parser, int msg_type, int m
|
||||||
char* pathNfilename = NULL;
|
char* pathNfilename = NULL;
|
||||||
|
|
||||||
/* create a free file name to use */
|
/* create a free file name to use */
|
||||||
if ((pathNfilename=dc_get_fine_pathNfilename(parser->blobdir, desired_filename)) == NULL) {
|
if ((pathNfilename=dc_get_fine_pathNfilename(parser->blobdir, desired_filename))==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -978,7 +978,7 @@ static void do_add_single_file_part(dc_mimeparser_t* parser, int msg_type, int m
|
||||||
part->msg = dc_get_filesuffix_lc(pathNfilename);
|
part->msg = dc_get_filesuffix_lc(pathNfilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mime_type == DC_MIMETYPE_IMAGE) {
|
if (mime_type==DC_MIMETYPE_IMAGE) {
|
||||||
uint32_t w = 0, h = 0;
|
uint32_t w = 0, h = 0;
|
||||||
if (dc_get_filemeta(decoded_data, decoded_data_bytes, &w, &h)) {
|
if (dc_get_filemeta(decoded_data, decoded_data_bytes, &w, &h)) {
|
||||||
dc_param_set_int(part->param, DC_PARAM_WIDTH, w);
|
dc_param_set_int(part->param, DC_PARAM_WIDTH, w);
|
||||||
|
@ -987,7 +987,7 @@ static void do_add_single_file_part(dc_mimeparser_t* parser, int msg_type, int m
|
||||||
}
|
}
|
||||||
|
|
||||||
/* split author/title from the original filename (if we do it from the real filename, we'll also get numbers appended by dc_get_fine_pathNfilename()) */
|
/* split author/title from the original filename (if we do it from the real filename, we'll also get numbers appended by dc_get_fine_pathNfilename()) */
|
||||||
if (msg_type == DC_MSG_AUDIO) {
|
if (msg_type==DC_MSG_AUDIO) {
|
||||||
char* author = NULL, *title = NULL;
|
char* author = NULL, *title = NULL;
|
||||||
dc_msg_get_authorNtitle_from_filename(desired_filename, &author, &title);
|
dc_msg_get_authorNtitle_from_filename(desired_filename, &author, &title);
|
||||||
dc_param_set(part->param, DC_PARAM_AUTHORNAME, author);
|
dc_param_set(part->param, DC_PARAM_AUTHORNAME, author);
|
||||||
|
@ -1022,7 +1022,7 @@ static int dc_mimeparser_add_single_part_if_known(dc_mimeparser_t* mimeparser, s
|
||||||
size_t decoded_data_bytes = 0;
|
size_t decoded_data_bytes = 0;
|
||||||
dc_simplify_t* simplifier = NULL;
|
dc_simplify_t* simplifier = NULL;
|
||||||
|
|
||||||
if (mime == NULL || mime->mm_data.mm_single == NULL) {
|
if (mime==NULL || mime->mm_data.mm_single==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1031,8 +1031,8 @@ static int dc_mimeparser_add_single_part_if_known(dc_mimeparser_t* mimeparser, s
|
||||||
|
|
||||||
/* get data pointer from `mime` */
|
/* get data pointer from `mime` */
|
||||||
mime_data = mime->mm_data.mm_single;
|
mime_data = mime->mm_data.mm_single;
|
||||||
if (mime_data->dt_type != MAILMIME_DATA_TEXT /* MAILMIME_DATA_FILE indicates, the data is in a file; AFAIK this is not used on parsing */
|
if (mime_data->dt_type!=MAILMIME_DATA_TEXT /* MAILMIME_DATA_FILE indicates, the data is in a file; AFAIK this is not used on parsing */
|
||||||
|| mime_data->dt_data.dt_text.dt_data == NULL
|
|| mime_data->dt_data.dt_text.dt_data==NULL
|
||||||
|| mime_data->dt_data.dt_text.dt_length <= 0) {
|
|| mime_data->dt_data.dt_text.dt_length <= 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -1059,7 +1059,7 @@ static int dc_mimeparser_add_single_part_if_known(dc_mimeparser_t* mimeparser, s
|
||||||
if (charset!=NULL && strcmp(charset, "utf-8")!=0 && strcmp(charset, "UTF-8")!=0) {
|
if (charset!=NULL && strcmp(charset, "utf-8")!=0 && strcmp(charset, "UTF-8")!=0) {
|
||||||
size_t ret_bytes = 0;
|
size_t ret_bytes = 0;
|
||||||
int r = charconv_buffer("utf-8", charset, decoded_data, decoded_data_bytes, &charset_buffer, &ret_bytes);
|
int r = charconv_buffer("utf-8", charset, decoded_data, decoded_data_bytes, &charset_buffer, &ret_bytes);
|
||||||
if (r != MAIL_CHARCONV_NO_ERROR) {
|
if (r!=MAIL_CHARCONV_NO_ERROR) {
|
||||||
dc_log_warning(mimeparser->context, 0, "Cannot convert %i bytes from \"%s\" to \"utf-8\"; errorcode is %i.", /* if this warning comes up for usual character sets, maybe libetpan is compiled without iconv? */
|
dc_log_warning(mimeparser->context, 0, "Cannot convert %i bytes from \"%s\" to \"utf-8\"; errorcode is %i.", /* if this warning comes up for usual character sets, maybe libetpan is compiled without iconv? */
|
||||||
(int)decoded_data_bytes, charset, (int)r); /* continue, however */
|
(int)decoded_data_bytes, charset, (int)r); /* continue, however */
|
||||||
}
|
}
|
||||||
|
@ -1078,10 +1078,10 @@ static int dc_mimeparser_add_single_part_if_known(dc_mimeparser_t* mimeparser, s
|
||||||
char* uu_blob = NULL, *uu_filename = NULL, *new_txt = NULL;
|
char* uu_blob = NULL, *uu_filename = NULL, *new_txt = NULL;
|
||||||
size_t uu_blob_bytes = 0;
|
size_t uu_blob_bytes = 0;
|
||||||
int uu_msg_type = 0, added_uu_parts = 0;
|
int uu_msg_type = 0, added_uu_parts = 0;
|
||||||
while ((new_txt=dc_uudecode_do(txt, &uu_blob, &uu_blob_bytes, &uu_filename)) != NULL)
|
while ((new_txt=dc_uudecode_do(txt, &uu_blob, &uu_blob_bytes, &uu_filename))!=NULL)
|
||||||
{
|
{
|
||||||
dc_msg_guess_msgtype_from_suffix(uu_filename, &uu_msg_type, NULL);
|
dc_msg_guess_msgtype_from_suffix(uu_filename, &uu_msg_type, NULL);
|
||||||
if (uu_msg_type == 0) {
|
if (uu_msg_type==0) {
|
||||||
uu_msg_type = DC_MSG_FILE;
|
uu_msg_type = DC_MSG_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1135,15 +1135,15 @@ static int dc_mimeparser_add_single_part_if_known(dc_mimeparser_t* mimeparser, s
|
||||||
or `Content-Disposition: ... filename=...` */
|
or `Content-Disposition: ... filename=...` */
|
||||||
dc_strbuilder_t filename_parts;
|
dc_strbuilder_t filename_parts;
|
||||||
dc_strbuilder_init(&filename_parts, 0);
|
dc_strbuilder_init(&filename_parts, 0);
|
||||||
for (clistiter* cur1 = clist_begin(mime->mm_mime_fields->fld_list); cur1 != NULL; cur1 = clist_next(cur1))
|
for (clistiter* cur1 = clist_begin(mime->mm_mime_fields->fld_list); cur1!=NULL; cur1 = clist_next(cur1))
|
||||||
{
|
{
|
||||||
struct mailmime_field* field = (struct mailmime_field*)clist_content(cur1);
|
struct mailmime_field* field = (struct mailmime_field*)clist_content(cur1);
|
||||||
if (field && field->fld_type == MAILMIME_FIELD_DISPOSITION && field->fld_data.fld_disposition)
|
if (field && field->fld_type==MAILMIME_FIELD_DISPOSITION && field->fld_data.fld_disposition)
|
||||||
{
|
{
|
||||||
struct mailmime_disposition* file_disposition = field->fld_data.fld_disposition;
|
struct mailmime_disposition* file_disposition = field->fld_data.fld_disposition;
|
||||||
if (file_disposition)
|
if (file_disposition)
|
||||||
{
|
{
|
||||||
for (clistiter* cur2 = clist_begin(file_disposition->dsp_parms); cur2 != NULL; cur2 = clist_next(cur2))
|
for (clistiter* cur2 = clist_begin(file_disposition->dsp_parms); cur2!=NULL; cur2 = clist_next(cur2))
|
||||||
{
|
{
|
||||||
struct mailmime_disposition_parm* dsp_param = (struct mailmime_disposition_parm*)clist_content(cur2);
|
struct mailmime_disposition_parm* dsp_param = (struct mailmime_disposition_parm*)clist_content(cur2);
|
||||||
if (dsp_param)
|
if (dsp_param)
|
||||||
|
@ -1219,7 +1219,7 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc
|
||||||
int any_part_added = 0;
|
int any_part_added = 0;
|
||||||
clistiter* cur = NULL;
|
clistiter* cur = NULL;
|
||||||
|
|
||||||
if (mimeparser == NULL || mime == NULL) {
|
if (mimeparser==NULL || mime==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1260,7 +1260,7 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc
|
||||||
If we find a multipart/mixed inside mutlipart/alternative, we use this (happens eg in apple mail: "plaintext" as an alternative to "html+PDF attachment") */
|
If we find a multipart/mixed inside mutlipart/alternative, we use this (happens eg in apple mail: "plaintext" as an alternative to "html+PDF attachment") */
|
||||||
for (cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list); cur!=NULL; cur=clist_next(cur)) {
|
for (cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list); cur!=NULL; cur=clist_next(cur)) {
|
||||||
struct mailmime* childmime = (struct mailmime*)clist_content(cur);
|
struct mailmime* childmime = (struct mailmime*)clist_content(cur);
|
||||||
if (mailmime_get_mime_type(childmime, NULL) == DC_MIMETYPE_MP_MIXED) {
|
if (mailmime_get_mime_type(childmime, NULL)==DC_MIMETYPE_MP_MIXED) {
|
||||||
any_part_added = dc_mimeparser_parse_mime_recursive(mimeparser, childmime);
|
any_part_added = dc_mimeparser_parse_mime_recursive(mimeparser, childmime);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1271,7 +1271,7 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc
|
||||||
/* search for text/plain and add this */
|
/* search for text/plain and add this */
|
||||||
for (cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list); cur!=NULL; cur=clist_next(cur)) {
|
for (cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list); cur!=NULL; cur=clist_next(cur)) {
|
||||||
struct mailmime* childmime = (struct mailmime*)clist_content(cur);
|
struct mailmime* childmime = (struct mailmime*)clist_content(cur);
|
||||||
if (mailmime_get_mime_type(childmime, NULL) == DC_MIMETYPE_TEXT_PLAIN) {
|
if (mailmime_get_mime_type(childmime, NULL)==DC_MIMETYPE_TEXT_PLAIN) {
|
||||||
any_part_added = dc_mimeparser_parse_mime_recursive(mimeparser, childmime);
|
any_part_added = dc_mimeparser_parse_mime_recursive(mimeparser, childmime);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1317,7 +1317,7 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc
|
||||||
The second body part contains the control information necessary to verify the digital signature."
|
The second body part contains the control information necessary to verify the digital signature."
|
||||||
We simpliy take the first body part and skip the rest.
|
We simpliy take the first body part and skip the rest.
|
||||||
(see https://k9mail.github.io/2016/11/24/OpenPGP-Considerations-Part-I.html for background information why we use encrypted+signed) */
|
(see https://k9mail.github.io/2016/11/24/OpenPGP-Considerations-Part-I.html for background information why we use encrypted+signed) */
|
||||||
if ((cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list)) != NULL)
|
if ((cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list))!=NULL)
|
||||||
{
|
{
|
||||||
any_part_added = dc_mimeparser_parse_mime_recursive(mimeparser, (struct mailmime*)clist_content(cur));
|
any_part_added = dc_mimeparser_parse_mime_recursive(mimeparser, (struct mailmime*)clist_content(cur));
|
||||||
}
|
}
|
||||||
|
@ -1328,7 +1328,7 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc
|
||||||
{
|
{
|
||||||
struct mailmime_parameter* report_type = mailmime_find_ct_parameter(mime, "report-type");
|
struct mailmime_parameter* report_type = mailmime_find_ct_parameter(mime, "report-type");
|
||||||
if (report_type && report_type->pa_value
|
if (report_type && report_type->pa_value
|
||||||
&& strcmp(report_type->pa_value, "disposition-notification") == 0)
|
&& strcmp(report_type->pa_value, "disposition-notification")==0)
|
||||||
{
|
{
|
||||||
carray_add(mimeparser->reports, (void*)mime, NULL);
|
carray_add(mimeparser->reports, (void*)mime, NULL);
|
||||||
}
|
}
|
||||||
|
@ -1351,10 +1351,10 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc
|
||||||
int plain_cnt = 0, html_cnt = 0;
|
int plain_cnt = 0, html_cnt = 0;
|
||||||
for (cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list); cur!=NULL; cur=clist_next(cur)) {
|
for (cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list); cur!=NULL; cur=clist_next(cur)) {
|
||||||
struct mailmime* childmime = (struct mailmime*)clist_content(cur);
|
struct mailmime* childmime = (struct mailmime*)clist_content(cur);
|
||||||
if (mailmime_get_mime_type(childmime, NULL) == DC_MIMETYPE_TEXT_PLAIN) {
|
if (mailmime_get_mime_type(childmime, NULL)==DC_MIMETYPE_TEXT_PLAIN) {
|
||||||
plain_cnt++;
|
plain_cnt++;
|
||||||
}
|
}
|
||||||
else if (mailmime_get_mime_type(childmime, NULL) == DC_MIMETYPE_TEXT_HTML) {
|
else if (mailmime_get_mime_type(childmime, NULL)==DC_MIMETYPE_TEXT_HTML) {
|
||||||
html_part = childmime;
|
html_part = childmime;
|
||||||
html_cnt++;
|
html_cnt++;
|
||||||
}
|
}
|
||||||
|
@ -1368,7 +1368,7 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc
|
||||||
|
|
||||||
for (cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list); cur!=NULL; cur=clist_next(cur)) {
|
for (cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list); cur!=NULL; cur=clist_next(cur)) {
|
||||||
struct mailmime* childmime = (struct mailmime*)clist_content(cur);
|
struct mailmime* childmime = (struct mailmime*)clist_content(cur);
|
||||||
if (childmime != skip_part) {
|
if (childmime!=skip_part) {
|
||||||
if (dc_mimeparser_parse_mime_recursive(mimeparser, childmime)) {
|
if (dc_mimeparser_parse_mime_recursive(mimeparser, childmime)) {
|
||||||
any_part_added = 1;
|
any_part_added = 1;
|
||||||
}
|
}
|
||||||
|
@ -1380,7 +1380,7 @@ static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struc
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MAILMIME_MESSAGE:
|
case MAILMIME_MESSAGE:
|
||||||
if (mimeparser->header_root == NULL)
|
if (mimeparser->header_root==NULL)
|
||||||
{
|
{
|
||||||
mimeparser->header_root = mime->mm_data.mm_message.mm_fields;
|
mimeparser->header_root = mime->mm_data.mm_message.mm_fields;
|
||||||
}
|
}
|
||||||
|
@ -1479,7 +1479,7 @@ void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_termi
|
||||||
|
|
||||||
/* parse body */
|
/* parse body */
|
||||||
r = mailmime_parse(body_not_terminated, body_bytes, &index, &mimeparser->mimeroot);
|
r = mailmime_parse(body_not_terminated, body_bytes, &index, &mimeparser->mimeroot);
|
||||||
if(r != MAILIMF_NO_ERROR || mimeparser->mimeroot == NULL) {
|
if(r!=MAILIMF_NO_ERROR || mimeparser->mimeroot==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1505,7 +1505,7 @@ void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_termi
|
||||||
/* set some basic data */
|
/* set some basic data */
|
||||||
{
|
{
|
||||||
struct mailimf_field* field = dc_mimeparser_lookup_field(mimeparser, "Subject");
|
struct mailimf_field* field = dc_mimeparser_lookup_field(mimeparser, "Subject");
|
||||||
if (field && field->fld_type == MAILIMF_FIELD_SUBJECT) {
|
if (field && field->fld_type==MAILIMF_FIELD_SUBJECT) {
|
||||||
mimeparser->subject = dc_decode_header_words(field->fld_data.fld_subject->sbj_value);
|
mimeparser->subject = dc_decode_header_words(field->fld_data.fld_subject->sbj_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1545,8 +1545,8 @@ void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_termi
|
||||||
if (!mimeparser->decrypting_failed /* if decryption has failed, we always prepend the subject as this may contain cleartext hints from non-Delta MUAs. */)
|
if (!mimeparser->decrypting_failed /* if decryption has failed, we always prepend the subject as this may contain cleartext hints from non-Delta MUAs. */)
|
||||||
{
|
{
|
||||||
char* p = strchr(mimeparser->subject, ':');
|
char* p = strchr(mimeparser->subject, ':');
|
||||||
if ((p-mimeparser->subject) == 2 /*Re: etc.*/
|
if ((p-mimeparser->subject)==2 /*Re: etc.*/
|
||||||
|| (p-mimeparser->subject) == 3 /*Fwd: etc.*/
|
|| (p-mimeparser->subject)==3 /*Fwd: etc.*/
|
||||||
|| mimeparser->is_send_by_messenger
|
|| mimeparser->is_send_by_messenger
|
||||||
|| strstr(mimeparser->subject, DC_CHAT_PREFIX)!=NULL) {
|
|| strstr(mimeparser->subject, DC_CHAT_PREFIX)!=NULL) {
|
||||||
prepend_subject = 0;
|
prepend_subject = 0;
|
||||||
|
@ -1565,7 +1565,7 @@ void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_termi
|
||||||
int i, icnt = carray_count(mimeparser->parts); /* should be at least one - maybe empty - part */
|
int i, icnt = carray_count(mimeparser->parts); /* should be at least one - maybe empty - part */
|
||||||
for (i = 0; i < icnt; i++) {
|
for (i = 0; i < icnt; i++) {
|
||||||
dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->parts, i);
|
dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->parts, i);
|
||||||
if (part->type == DC_MSG_TEXT) {
|
if (part->type==DC_MSG_TEXT) {
|
||||||
#define DC_NDASH "\xE2\x80\x93"
|
#define DC_NDASH "\xE2\x80\x93"
|
||||||
char* new_txt = dc_mprintf("%s " DC_NDASH " %s", subj, part->msg);
|
char* new_txt = dc_mprintf("%s " DC_NDASH " %s", subj, part->msg);
|
||||||
free(part->msg);
|
free(part->msg);
|
||||||
|
@ -1592,7 +1592,7 @@ void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_termi
|
||||||
/* mark audio as voice message, if appropriate (we have to do this on global level as we do not know the global header in the recursice parse).
|
/* mark audio as voice message, if appropriate (we have to do this on global level as we do not know the global header in the recursice parse).
|
||||||
and read some additional parameters */
|
and read some additional parameters */
|
||||||
dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->parts, 0);
|
dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->parts, 0);
|
||||||
if (part->type == DC_MSG_AUDIO) {
|
if (part->type==DC_MSG_AUDIO) {
|
||||||
if (dc_mimeparser_lookup_optional_field2(mimeparser, "Chat-Voice-Message", "X-MrVoiceMessage")) {
|
if (dc_mimeparser_lookup_optional_field2(mimeparser, "Chat-Voice-Message", "X-MrVoiceMessage")) {
|
||||||
free(part->msg);
|
free(part->msg);
|
||||||
part->msg = strdup("ogg"); /* DC_MSG_AUDIO adds sets the whole filename which is useless. however, the extension is useful. */
|
part->msg = strdup("ogg"); /* DC_MSG_AUDIO adds sets the whole filename which is useless. however, the extension is useful. */
|
||||||
|
@ -1602,7 +1602,7 @@ void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_termi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (part->type == DC_MSG_AUDIO || part->type == DC_MSG_VOICE || part->type == DC_MSG_VIDEO) {
|
if (part->type==DC_MSG_AUDIO || part->type==DC_MSG_VOICE || part->type==DC_MSG_VIDEO) {
|
||||||
const struct mailimf_optional_field* field = dc_mimeparser_lookup_optional_field2(mimeparser, "Chat-Duration", "X-MrDurationMs");
|
const struct mailimf_optional_field* field = dc_mimeparser_lookup_optional_field2(mimeparser, "Chat-Duration", "X-MrDurationMs");
|
||||||
if (field) {
|
if (field) {
|
||||||
int duration_ms = atoi(field->fld_value);
|
int duration_ms = atoi(field->fld_value);
|
||||||
|
@ -1617,11 +1617,11 @@ void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_termi
|
||||||
if (dc_mimeparser_lookup_field(mimeparser, "Chat-Group-Image")
|
if (dc_mimeparser_lookup_field(mimeparser, "Chat-Group-Image")
|
||||||
&& carray_count(mimeparser->parts)>=1) {
|
&& carray_count(mimeparser->parts)>=1) {
|
||||||
dc_mimepart_t* textpart = (dc_mimepart_t*)carray_get(mimeparser->parts, 0);
|
dc_mimepart_t* textpart = (dc_mimepart_t*)carray_get(mimeparser->parts, 0);
|
||||||
if (textpart->type == DC_MSG_TEXT) {
|
if (textpart->type==DC_MSG_TEXT) {
|
||||||
dc_param_set_int(textpart->param, DC_PARAM_CMD, DC_CMD_GROUPIMAGE_CHANGED);
|
dc_param_set_int(textpart->param, DC_PARAM_CMD, DC_CMD_GROUPIMAGE_CHANGED);
|
||||||
if (carray_count(mimeparser->parts)>=2) {
|
if (carray_count(mimeparser->parts)>=2) {
|
||||||
dc_mimepart_t* imgpart = (dc_mimepart_t*)carray_get(mimeparser->parts, 1);
|
dc_mimepart_t* imgpart = (dc_mimepart_t*)carray_get(mimeparser->parts, 1);
|
||||||
if (imgpart->type == DC_MSG_IMAGE) {
|
if (imgpart->type==DC_MSG_IMAGE) {
|
||||||
imgpart->is_meta = 1;
|
imgpart->is_meta = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1713,7 +1713,7 @@ struct mailimf_field* dc_mimeparser_lookup_field(dc_mimeparser_t* mimeparser, co
|
||||||
struct mailimf_optional_field* dc_mimeparser_lookup_optional_field(dc_mimeparser_t* mimeparser, const char* field_name)
|
struct mailimf_optional_field* dc_mimeparser_lookup_optional_field(dc_mimeparser_t* mimeparser, const char* field_name)
|
||||||
{
|
{
|
||||||
struct mailimf_field* field = dc_hash_find_str(&mimeparser->header, field_name);
|
struct mailimf_field* field = dc_hash_find_str(&mimeparser->header, field_name);
|
||||||
if (field && field->fld_type == MAILIMF_FIELD_OPTIONAL_FIELD) {
|
if (field && field->fld_type==MAILIMF_FIELD_OPTIONAL_FIELD) {
|
||||||
return field->fld_data.fld_optional_field;
|
return field->fld_data.fld_optional_field;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1809,16 +1809,16 @@ dc_mimepart_t* dc_mimeparser_get_last_nonmeta(dc_mimeparser_t* mimeparser)
|
||||||
*/
|
*/
|
||||||
int dc_mimeparser_is_mailinglist_message(dc_mimeparser_t* mimeparser)
|
int dc_mimeparser_is_mailinglist_message(dc_mimeparser_t* mimeparser)
|
||||||
{
|
{
|
||||||
if (mimeparser == NULL) {
|
if (mimeparser==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dc_mimeparser_lookup_field(mimeparser, "List-Id") != NULL) {
|
if (dc_mimeparser_lookup_field(mimeparser, "List-Id")!=NULL) {
|
||||||
return 1; /* mailing list identified by the presence of `List-ID` from RFC 2919 */
|
return 1; /* mailing list identified by the presence of `List-ID` from RFC 2919 */
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mailimf_optional_field* precedence = dc_mimeparser_lookup_optional_field(mimeparser, "Precedence");
|
struct mailimf_optional_field* precedence = dc_mimeparser_lookup_optional_field(mimeparser, "Precedence");
|
||||||
if (precedence != NULL) {
|
if (precedence!=NULL) {
|
||||||
if (strcasecmp(precedence->fld_value, "list")==0
|
if (strcasecmp(precedence->fld_value, "list")==0
|
||||||
|| strcasecmp(precedence->fld_value, "bulk")==0) {
|
|| strcasecmp(precedence->fld_value, "bulk")==0) {
|
||||||
return 1; /* mailing list identified by the presence of `Precedence: bulk` or `Precedence: list` from RFC 3834 */
|
return 1; /* mailing list identified by the presence of `Precedence: bulk` or `Precedence: list` from RFC 3834 */
|
||||||
|
@ -1855,21 +1855,21 @@ int dc_mimeparser_sender_equals_recipient(dc_mimeparser_t* mimeparser)
|
||||||
char* from_addr_norm = NULL;
|
char* from_addr_norm = NULL;
|
||||||
dc_hash_t* recipients = NULL;
|
dc_hash_t* recipients = NULL;
|
||||||
|
|
||||||
if (mimeparser == NULL || mimeparser->header_root == NULL) {
|
if (mimeparser==NULL || mimeparser->header_root==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get From: and check there is exactly one sender */
|
/* get From: and check there is exactly one sender */
|
||||||
if ((fld=mailimf_find_field(mimeparser->header_root, MAILIMF_FIELD_FROM)) == NULL
|
if ((fld=mailimf_find_field(mimeparser->header_root, MAILIMF_FIELD_FROM))==NULL
|
||||||
|| (fld_from=fld->fld_data.fld_from) == NULL
|
|| (fld_from=fld->fld_data.fld_from)==NULL
|
||||||
|| fld_from->frm_mb_list == NULL
|
|| fld_from->frm_mb_list==NULL
|
||||||
|| fld_from->frm_mb_list->mb_list == NULL
|
|| fld_from->frm_mb_list->mb_list==NULL
|
||||||
|| clist_count(fld_from->frm_mb_list->mb_list) != 1) {
|
|| clist_count(fld_from->frm_mb_list->mb_list)!=1) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
mb = (struct mailimf_mailbox*)clist_content(clist_begin(fld_from->frm_mb_list->mb_list));
|
mb = (struct mailimf_mailbox*)clist_content(clist_begin(fld_from->frm_mb_list->mb_list));
|
||||||
if (mb == NULL) {
|
if (mb==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1877,11 +1877,11 @@ int dc_mimeparser_sender_equals_recipient(dc_mimeparser_t* mimeparser)
|
||||||
|
|
||||||
/* get To:/Cc: and check there is exactly one recipent */
|
/* get To:/Cc: and check there is exactly one recipent */
|
||||||
recipients = mailimf_get_recipients(mimeparser->header_root);
|
recipients = mailimf_get_recipients(mimeparser->header_root);
|
||||||
if (dc_hash_cnt(recipients) != 1) {
|
if (dc_hash_cnt(recipients)!=1) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if From: == To:/Cc: */
|
/* check if From:==To:/Cc: */
|
||||||
if (dc_hash_find_str(recipients, from_addr_norm)) {
|
if (dc_hash_find_str(recipients, from_addr_norm)) {
|
||||||
sender_equals_recipient = 1;
|
sender_equals_recipient = 1;
|
||||||
}
|
}
|
||||||
|
|
102
src/dc_msg.c
102
src/dc_msg.c
|
@ -65,7 +65,7 @@ dc_msg_t* dc_msg_new()
|
||||||
*/
|
*/
|
||||||
void dc_msg_unref(dc_msg_t* msg)
|
void dc_msg_unref(dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg==NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ void dc_msg_unref(dc_msg_t* msg)
|
||||||
*/
|
*/
|
||||||
void dc_msg_empty(dc_msg_t* msg)
|
void dc_msg_empty(dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ void dc_msg_empty(dc_msg_t* msg)
|
||||||
*/
|
*/
|
||||||
uint32_t dc_msg_get_id(const dc_msg_t* msg)
|
uint32_t dc_msg_get_id(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return msg->id;
|
return msg->id;
|
||||||
|
@ -138,7 +138,7 @@ uint32_t dc_msg_get_id(const dc_msg_t* msg)
|
||||||
*/
|
*/
|
||||||
uint32_t dc_msg_get_from_id(const dc_msg_t* msg)
|
uint32_t dc_msg_get_from_id(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return msg->from_id;
|
return msg->from_id;
|
||||||
|
@ -157,7 +157,7 @@ uint32_t dc_msg_get_from_id(const dc_msg_t* msg)
|
||||||
*/
|
*/
|
||||||
uint32_t dc_msg_get_chat_id(const dc_msg_t* msg)
|
uint32_t dc_msg_get_chat_id(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return msg->chat_blocked? DC_CHAT_ID_DEADDROP : msg->chat_id;
|
return msg->chat_blocked? DC_CHAT_ID_DEADDROP : msg->chat_id;
|
||||||
|
@ -175,7 +175,7 @@ uint32_t dc_msg_get_chat_id(const dc_msg_t* msg)
|
||||||
*/
|
*/
|
||||||
int dc_msg_get_type(const dc_msg_t* msg)
|
int dc_msg_get_type(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return DC_MSG_UNDEFINED;
|
return DC_MSG_UNDEFINED;
|
||||||
}
|
}
|
||||||
return msg->type;
|
return msg->type;
|
||||||
|
@ -211,7 +211,7 @@ int dc_msg_get_type(const dc_msg_t* msg)
|
||||||
*/
|
*/
|
||||||
int dc_msg_get_state(const dc_msg_t* msg)
|
int dc_msg_get_state(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return DC_STATE_UNDEFINED;
|
return DC_STATE_UNDEFINED;
|
||||||
}
|
}
|
||||||
return msg->state;
|
return msg->state;
|
||||||
|
@ -230,7 +230,7 @@ int dc_msg_get_state(const dc_msg_t* msg)
|
||||||
*/
|
*/
|
||||||
time_t dc_msg_get_timestamp(const dc_msg_t* msg)
|
time_t dc_msg_get_timestamp(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ char* dc_msg_get_text(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
char* ret = NULL;
|
char* ret = NULL;
|
||||||
|
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return dc_strdup(NULL);
|
return dc_strdup(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ char* dc_msg_get_file(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
char* ret = NULL;
|
char* ret = NULL;
|
||||||
|
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,12 +314,12 @@ char* dc_msg_get_filename(const dc_msg_t* msg)
|
||||||
char* ret = NULL;
|
char* ret = NULL;
|
||||||
char* pathNfilename = NULL;
|
char* pathNfilename = NULL;
|
||||||
|
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
|
pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
|
||||||
if (pathNfilename == NULL) {
|
if (pathNfilename==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,19 +345,19 @@ char* dc_msg_get_filemime(const dc_msg_t* msg)
|
||||||
char* ret = NULL;
|
char* ret = NULL;
|
||||||
char* file = NULL;
|
char* file = NULL;
|
||||||
|
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = dc_param_get(msg->param, DC_PARAM_MIMETYPE, NULL);
|
ret = dc_param_get(msg->param, DC_PARAM_MIMETYPE, NULL);
|
||||||
if (ret == NULL) {
|
if (ret==NULL) {
|
||||||
file = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
|
file = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
|
||||||
if (file == NULL) {
|
if (file==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
dc_msg_guess_msgtype_from_suffix(file, NULL, &ret);
|
dc_msg_guess_msgtype_from_suffix(file, NULL, &ret);
|
||||||
|
|
||||||
if (ret == NULL) {
|
if (ret==NULL) {
|
||||||
ret = dc_strdup("application/octet-stream");
|
ret = dc_strdup("application/octet-stream");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -383,12 +383,12 @@ uint64_t dc_msg_get_filebytes(const dc_msg_t* msg)
|
||||||
uint64_t ret = 0;
|
uint64_t ret = 0;
|
||||||
char* file = NULL;
|
char* file = NULL;
|
||||||
|
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
file = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
|
file = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
|
||||||
if (file == NULL) {
|
if (file==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,11 +423,11 @@ dc_lot_t* dc_msg_get_mediainfo(const dc_msg_t* msg)
|
||||||
char* pathNfilename = NULL;
|
char* pathNfilename = NULL;
|
||||||
dc_contact_t* contact = NULL;
|
dc_contact_t* contact = NULL;
|
||||||
|
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC || msg->context == NULL) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC || msg->context==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg->type == DC_MSG_VOICE)
|
if (msg->type==DC_MSG_VOICE)
|
||||||
{
|
{
|
||||||
if ((contact = dc_get_contact(msg->context, msg->from_id))==NULL) {
|
if ((contact = dc_get_contact(msg->context, msg->from_id))==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -446,11 +446,11 @@ dc_lot_t* dc_msg_get_mediainfo(const dc_msg_t* msg)
|
||||||
free(ret->text2); ret->text2 = NULL;
|
free(ret->text2); ret->text2 = NULL;
|
||||||
|
|
||||||
pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
|
pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
|
||||||
if (pathNfilename == NULL) {
|
if (pathNfilename==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
dc_msg_get_authorNtitle_from_filename(pathNfilename, &ret->text1, &ret->text2);
|
dc_msg_get_authorNtitle_from_filename(pathNfilename, &ret->text1, &ret->text2);
|
||||||
if (ret->text1 == NULL && ret->text2 != NULL) {
|
if (ret->text1==NULL && ret->text2!=NULL) {
|
||||||
ret->text1 = dc_stock_str(msg->context, DC_STR_AUDIO);
|
ret->text1 = dc_stock_str(msg->context, DC_STR_AUDIO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -478,7 +478,7 @@ cleanup:
|
||||||
*/
|
*/
|
||||||
int dc_msg_get_width(const dc_msg_t* msg)
|
int dc_msg_get_width(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return dc_param_get_int(msg->param, DC_PARAM_WIDTH, 0);
|
return dc_param_get_int(msg->param, DC_PARAM_WIDTH, 0);
|
||||||
|
@ -501,7 +501,7 @@ int dc_msg_get_width(const dc_msg_t* msg)
|
||||||
*/
|
*/
|
||||||
int dc_msg_get_height(const dc_msg_t* msg)
|
int dc_msg_get_height(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return dc_param_get_int(msg->param, DC_PARAM_HEIGHT, 0);
|
return dc_param_get_int(msg->param, DC_PARAM_HEIGHT, 0);
|
||||||
|
@ -521,7 +521,7 @@ int dc_msg_get_height(const dc_msg_t* msg)
|
||||||
*/
|
*/
|
||||||
int dc_msg_get_duration(const dc_msg_t* msg)
|
int dc_msg_get_duration(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return dc_param_get_int(msg->param, DC_PARAM_DURATION, 0);
|
return dc_param_get_int(msg->param, DC_PARAM_DURATION, 0);
|
||||||
|
@ -540,7 +540,7 @@ int dc_msg_get_showpadlock(const dc_msg_t* msg)
|
||||||
/* a padlock guarantees that the message is e2ee _and_ answers will be as well */
|
/* a padlock guarantees that the message is e2ee _and_ answers will be as well */
|
||||||
int show_encryption_state = 0;
|
int show_encryption_state = 0;
|
||||||
|
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC || msg->context == NULL) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC || msg->context==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,7 +554,7 @@ int dc_msg_get_showpadlock(const dc_msg_t* msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_encryption_state) {
|
if (show_encryption_state) {
|
||||||
if (dc_param_get_int(msg->param, DC_PARAM_GUARANTEE_E2EE, 0) != 0) {
|
if (dc_param_get_int(msg->param, DC_PARAM_GUARANTEE_E2EE, 0)!=0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -591,18 +591,18 @@ dc_lot_t* dc_msg_get_summary(const dc_msg_t* msg, const dc_chat_t* chat)
|
||||||
dc_contact_t* contact = NULL;
|
dc_contact_t* contact = NULL;
|
||||||
dc_chat_t* chat_to_delete = NULL;
|
dc_chat_t* chat_to_delete = NULL;
|
||||||
|
|
||||||
if (msg==NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chat == NULL) {
|
if (chat==NULL) {
|
||||||
if ((chat_to_delete=dc_get_chat(msg->context, msg->chat_id)) == NULL) {
|
if ((chat_to_delete=dc_get_chat(msg->context, msg->chat_id))==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
chat = chat_to_delete;
|
chat = chat_to_delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg->from_id != DC_CONTACT_ID_SELF && DC_CHAT_TYPE_IS_MULTI(chat->type)) {
|
if (msg->from_id!=DC_CONTACT_ID_SELF && DC_CHAT_TYPE_IS_MULTI(chat->type)) {
|
||||||
contact = dc_get_contact(chat->context, msg->from_id);
|
contact = dc_get_contact(chat->context, msg->from_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -627,7 +627,7 @@ cleanup:
|
||||||
*/
|
*/
|
||||||
char* dc_msg_get_summarytext(const dc_msg_t* msg, int approx_characters)
|
char* dc_msg_get_summarytext(const dc_msg_t* msg, int approx_characters)
|
||||||
{
|
{
|
||||||
if (msg==NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return dc_strdup(NULL);
|
return dc_strdup(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -647,7 +647,7 @@ char* dc_msg_get_summarytext(const dc_msg_t* msg, int approx_characters)
|
||||||
*/
|
*/
|
||||||
int dc_msg_is_sent(const dc_msg_t* msg)
|
int dc_msg_is_sent(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return (msg->state >= DC_STATE_OUT_DELIVERED)? 1 : 0;
|
return (msg->state >= DC_STATE_OUT_DELIVERED)? 1 : 0;
|
||||||
|
@ -668,7 +668,7 @@ int dc_msg_is_sent(const dc_msg_t* msg)
|
||||||
*/
|
*/
|
||||||
int dc_msg_is_starred(const dc_msg_t* msg)
|
int dc_msg_is_starred(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return msg->starred? 1 : 0;
|
return msg->starred? 1 : 0;
|
||||||
|
@ -693,7 +693,7 @@ int dc_msg_is_starred(const dc_msg_t* msg)
|
||||||
*/
|
*/
|
||||||
int dc_msg_is_forwarded(const dc_msg_t* msg)
|
int dc_msg_is_forwarded(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return dc_param_get_int(msg->param, DC_PARAM_FORWARDED, 0)? 1 : 0;
|
return dc_param_get_int(msg->param, DC_PARAM_FORWARDED, 0)? 1 : 0;
|
||||||
|
@ -718,15 +718,15 @@ int dc_msg_is_forwarded(const dc_msg_t* msg)
|
||||||
*/
|
*/
|
||||||
int dc_msg_is_info(const dc_msg_t* msg)
|
int dc_msg_is_info(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmd = dc_param_get_int(msg->param, DC_PARAM_CMD, 0);
|
int cmd = dc_param_get_int(msg->param, DC_PARAM_CMD, 0);
|
||||||
|
|
||||||
if (msg->from_id == DC_CONTACT_ID_DEVICE
|
if (msg->from_id==DC_CONTACT_ID_DEVICE
|
||||||
|| msg->to_id == DC_CONTACT_ID_DEVICE
|
|| msg->to_id==DC_CONTACT_ID_DEVICE
|
||||||
|| (cmd && cmd != DC_CMD_AUTOCRYPT_SETUP_MESSAGE)) {
|
|| (cmd && cmd!=DC_CMD_AUTOCRYPT_SETUP_MESSAGE)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -750,7 +750,7 @@ int dc_msg_is_info(const dc_msg_t* msg)
|
||||||
*/
|
*/
|
||||||
int dc_msg_is_setupmessage(const dc_msg_t* msg)
|
int dc_msg_is_setupmessage(const dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC || msg->type != DC_MSG_FILE) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC || msg->type!=DC_MSG_FILE) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -789,7 +789,7 @@ char* dc_msg_get_setupcodebegin(const dc_msg_t* msg)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dc_read_file(filename, (void**)&buf, &buf_bytes, msg->context) || buf == NULL || buf_bytes <= 0) {
|
if (!dc_read_file(filename, (void**)&buf, &buf_bytes, msg->context) || buf==NULL || buf_bytes <= 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -838,7 +838,7 @@ static int dc_msg_set_from_stmt(dc_msg_t* msg, sqlite3_stmt* row, int row_offset
|
||||||
msg->hidden = sqlite3_column_int (row, row_offset++);
|
msg->hidden = sqlite3_column_int (row, row_offset++);
|
||||||
msg->chat_blocked = sqlite3_column_int (row, row_offset++);
|
msg->chat_blocked = sqlite3_column_int (row, row_offset++);
|
||||||
|
|
||||||
if (msg->chat_blocked == 2) {
|
if (msg->chat_blocked==2) {
|
||||||
dc_truncate_n_unwrap_str(msg->text, 256 /* 256 characters is about a half screen on a 5" smartphone display */,
|
dc_truncate_n_unwrap_str(msg->text, 256 /* 256 characters is about a half screen on a 5" smartphone display */,
|
||||||
0/*unwrap*/);
|
0/*unwrap*/);
|
||||||
}
|
}
|
||||||
|
@ -858,7 +858,7 @@ int dc_msg_load_from_db(dc_msg_t* msg, dc_context_t* context, uint32_t id)
|
||||||
int success = 0;
|
int success = 0;
|
||||||
sqlite3_stmt* stmt = NULL;
|
sqlite3_stmt* stmt = NULL;
|
||||||
|
|
||||||
if (msg==NULL || msg->magic != DC_MSG_MAGIC || context==NULL || context->sql==NULL) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC || context==NULL || context->sql==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -868,7 +868,7 @@ int dc_msg_load_from_db(dc_msg_t* msg, dc_context_t* context, uint32_t id)
|
||||||
" WHERE m.id=?;");
|
" WHERE m.id=?;");
|
||||||
sqlite3_bind_int(stmt, 1, id);
|
sqlite3_bind_int(stmt, 1, id);
|
||||||
|
|
||||||
if (sqlite3_step(stmt) != SQLITE_ROW) {
|
if (sqlite3_step(stmt)!=SQLITE_ROW) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -902,18 +902,18 @@ void dc_msg_guess_msgtype_from_suffix(const char* pathNfilename, int* ret_msgtyp
|
||||||
int dummy_msgtype = 0;
|
int dummy_msgtype = 0;
|
||||||
char* dummy_buf = NULL;
|
char* dummy_buf = NULL;
|
||||||
|
|
||||||
if (pathNfilename == NULL) {
|
if (pathNfilename==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret_msgtype == NULL) { ret_msgtype = &dummy_msgtype; }
|
if (ret_msgtype==NULL) { ret_msgtype = &dummy_msgtype; }
|
||||||
if (ret_mime == NULL) { ret_mime = &dummy_buf; }
|
if (ret_mime==NULL) { ret_mime = &dummy_buf; }
|
||||||
|
|
||||||
*ret_msgtype = DC_MSG_UNDEFINED;
|
*ret_msgtype = DC_MSG_UNDEFINED;
|
||||||
*ret_mime = NULL;
|
*ret_mime = NULL;
|
||||||
|
|
||||||
suffix = dc_get_filesuffix_lc(pathNfilename);
|
suffix = dc_get_filesuffix_lc(pathNfilename);
|
||||||
if (suffix == NULL) {
|
if (suffix==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1023,7 +1023,7 @@ char* dc_msg_get_summarytext_by_raw(int type, const char* text, dc_param_t* para
|
||||||
free(pathNfilename);
|
free(pathNfilename);
|
||||||
free(label);
|
free(label);
|
||||||
free(value);
|
free(value);
|
||||||
if (ret == NULL) {
|
if (ret==NULL) {
|
||||||
ret = dc_strdup(NULL);
|
ret = dc_strdup(NULL);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1072,7 +1072,7 @@ int dc_msg_is_increation(const dc_msg_t* msg)
|
||||||
|
|
||||||
void dc_msg_save_param_to_disk(dc_msg_t* msg)
|
void dc_msg_save_param_to_disk(dc_msg_t* msg)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC || msg->context == NULL || msg->context->sql == NULL) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC || msg->context==NULL || msg->context->sql==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1108,7 +1108,7 @@ void dc_msg_save_param_to_disk(dc_msg_t* msg)
|
||||||
*/
|
*/
|
||||||
void dc_msg_latefiling_mediasize(dc_msg_t* msg, int width, int height, int duration)
|
void dc_msg_latefiling_mediasize(dc_msg_t* msg, int width, int height, int duration)
|
||||||
{
|
{
|
||||||
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
|
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,10 +35,10 @@ static char* find_param(char* haystack, int key, char** ret_p2)
|
||||||
/* let p1 point to the start of the */
|
/* let p1 point to the start of the */
|
||||||
p1 = haystack;
|
p1 = haystack;
|
||||||
while (1) {
|
while (1) {
|
||||||
if (p1 == NULL || *p1 == 0) {
|
if (p1==NULL || *p1==0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else if (*p1 == key && p1[1] == '=') {
|
else if (*p1==key && p1[1]=='=') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -51,7 +51,7 @@ static char* find_param(char* haystack, int key, char** ret_p2)
|
||||||
|
|
||||||
/* let p2 point to the character _after_ the value - eiter `\n` or `\0` */
|
/* let p2 point to the character _after_ the value - eiter `\n` or `\0` */
|
||||||
p2 = strchr(p1, '\n');
|
p2 = strchr(p1, '\n');
|
||||||
if (p2 == NULL) {
|
if (p2==NULL) {
|
||||||
p2 = &p1[strlen(p1)];
|
p2 = &p1[strlen(p1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ void dc_param_unref(dc_param_t* param)
|
||||||
*/
|
*/
|
||||||
void dc_param_empty(dc_param_t* param)
|
void dc_param_empty(dc_param_t* param)
|
||||||
{
|
{
|
||||||
if (param == NULL) {
|
if (param==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ void dc_param_empty(dc_param_t* param)
|
||||||
*/
|
*/
|
||||||
void dc_param_set_packed(dc_param_t* param, const char* packed)
|
void dc_param_set_packed(dc_param_t* param, const char* packed)
|
||||||
{
|
{
|
||||||
if (param == NULL) {
|
if (param==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ void dc_param_set_packed(dc_param_t* param, const char* packed)
|
||||||
*/
|
*/
|
||||||
void dc_param_set_urlencoded(dc_param_t* param, const char* urlencoded)
|
void dc_param_set_urlencoded(dc_param_t* param, const char* urlencoded)
|
||||||
{
|
{
|
||||||
if (param == NULL) {
|
if (param==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ int dc_param_exists(dc_param_t* param, int key)
|
||||||
{
|
{
|
||||||
char *p2 = NULL;
|
char *p2 = NULL;
|
||||||
|
|
||||||
if (param == NULL || key == 0) {
|
if (param==NULL || key==0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,12 +198,12 @@ char* dc_param_get(const dc_param_t* param, int key, const char* def)
|
||||||
char bak = 0;
|
char bak = 0;
|
||||||
char* ret = NULL;
|
char* ret = NULL;
|
||||||
|
|
||||||
if (param == NULL || key == 0) {
|
if (param==NULL || key==0) {
|
||||||
return def? dc_strdup(def) : NULL;
|
return def? dc_strdup(def) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
p1 = find_param(param->packed, key, &p2);
|
p1 = find_param(param->packed, key, &p2);
|
||||||
if (p1 == NULL) {
|
if (p1==NULL) {
|
||||||
return def? dc_strdup(def) : NULL;
|
return def? dc_strdup(def) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,12 +229,12 @@ char* dc_param_get(const dc_param_t* param, int key, const char* def)
|
||||||
*/
|
*/
|
||||||
int32_t dc_param_get_int(const dc_param_t* param, int key, int32_t def)
|
int32_t dc_param_get_int(const dc_param_t* param, int key, int32_t def)
|
||||||
{
|
{
|
||||||
if (param == NULL || key == 0) {
|
if (param==NULL || key==0) {
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* str = dc_param_get(param, key, NULL);
|
char* str = dc_param_get(param, key, NULL);
|
||||||
if (str == NULL) {
|
if (str==NULL) {
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
int32_t ret = atol(str);
|
int32_t ret = atol(str);
|
||||||
|
@ -258,7 +258,7 @@ void dc_param_set(dc_param_t* param, int key, const char* value)
|
||||||
char* old2 = NULL;
|
char* old2 = NULL;
|
||||||
char* new1 = NULL;
|
char* new1 = NULL;
|
||||||
|
|
||||||
if (param == NULL || key == 0) {
|
if (param==NULL || key==0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,12 +317,12 @@ void dc_param_set(dc_param_t* param, int key, const char* value)
|
||||||
*/
|
*/
|
||||||
void dc_param_set_int(dc_param_t* param, int key, int32_t value)
|
void dc_param_set_int(dc_param_t* param, int key, int32_t value)
|
||||||
{
|
{
|
||||||
if (param == NULL || key == 0) {
|
if (param==NULL || key==0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* value_str = dc_mprintf("%i", (int)value);
|
char* value_str = dc_mprintf("%i", (int)value);
|
||||||
if (value_str == NULL) {
|
if (value_str==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dc_param_set(param, key, value_str);
|
dc_param_set(param, key, value_str);
|
||||||
|
|
32
src/dc_pgp.c
32
src/dc_pgp.c
|
@ -71,7 +71,7 @@ void dc_pgp_exit(void)
|
||||||
|
|
||||||
void dc_pgp_rand_seed(dc_context_t* context, const void* buf, size_t bytes)
|
void dc_pgp_rand_seed(dc_context_t* context, const void* buf, size_t bytes)
|
||||||
{
|
{
|
||||||
if (buf == NULL || bytes <= 0) {
|
if (buf==NULL || bytes<=0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,16 +99,16 @@ int dc_split_armored_data(char* buf, const char** ret_headerline, const char** r
|
||||||
if (ret_preferencrypt) { *ret_preferencrypt = NULL; }
|
if (ret_preferencrypt) { *ret_preferencrypt = NULL; }
|
||||||
if (ret_base64) { *ret_base64 = NULL; }
|
if (ret_base64) { *ret_base64 = NULL; }
|
||||||
|
|
||||||
if (buf == NULL || ret_headerline == NULL) {
|
if (buf==NULL || ret_headerline==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_remove_cr_chars(buf);
|
dc_remove_cr_chars(buf);
|
||||||
while (*p1) {
|
while (*p1) {
|
||||||
if (*p1 == '\n') {
|
if (*p1=='\n') {
|
||||||
/* line found ... */
|
/* line found ... */
|
||||||
line[line_chars] = 0;
|
line[line_chars] = 0;
|
||||||
if (headerline == NULL) {
|
if (headerline==NULL) {
|
||||||
/* ... headerline */
|
/* ... headerline */
|
||||||
dc_trim(line);
|
dc_trim(line);
|
||||||
if (strncmp(line, "-----BEGIN ", 11)==0 && strncmp(&line[strlen(line)-5], "-----", 5)==0) {
|
if (strncmp(line, "-----BEGIN ", 11)==0 && strncmp(&line[strlen(line)-5], "-----", 5)==0) {
|
||||||
|
@ -160,7 +160,7 @@ int dc_split_armored_data(char* buf, const char** ret_headerline, const char** r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headerline == NULL || base64 == NULL) {
|
if (headerline==NULL || base64==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,13 +377,13 @@ int dc_pgp_create_keypair(dc_context_t* context, const char* addr, dc_key_t* ret
|
||||||
|
|
||||||
pgp_writer_set_memory(pubout, pubmem);
|
pgp_writer_set_memory(pubout, pubmem);
|
||||||
if (!pgp_write_xfer_key(pubout, &pubkey, 0/*armored*/)
|
if (!pgp_write_xfer_key(pubout, &pubkey, 0/*armored*/)
|
||||||
|| pubmem->buf == NULL || pubmem->length <= 0) {
|
|| pubmem->buf==NULL || pubmem->length <= 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
pgp_writer_set_memory(secout, secmem);
|
pgp_writer_set_memory(secout, secmem);
|
||||||
if (!pgp_write_xfer_key(secout, &seckey, 0/*armored*/)
|
if (!pgp_write_xfer_key(secout, &seckey, 0/*armored*/)
|
||||||
|| secmem->buf == NULL || secmem->length <= 0) {
|
|| secmem->buf==NULL || secmem->length <= 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,7 +418,7 @@ int dc_pgp_is_valid_key(dc_context_t* context, const dc_key_t* raw_key)
|
||||||
pgp_memory_t* keysmem = pgp_memory_new();
|
pgp_memory_t* keysmem = pgp_memory_new();
|
||||||
|
|
||||||
if (context==NULL || raw_key==NULL
|
if (context==NULL || raw_key==NULL
|
||||||
|| raw_key->binary == NULL || raw_key->bytes <= 0
|
|| raw_key->binary==NULL || raw_key->bytes <= 0
|
||||||
|| public_keys==NULL || private_keys==NULL || keysmem==NULL) {
|
|| public_keys==NULL || private_keys==NULL || keysmem==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -426,10 +426,10 @@ int dc_pgp_is_valid_key(dc_context_t* context, const dc_key_t* raw_key)
|
||||||
pgp_memory_add(keysmem, raw_key->binary, raw_key->bytes);
|
pgp_memory_add(keysmem, raw_key->binary, raw_key->bytes);
|
||||||
pgp_filter_keys_from_mem(&s_io, public_keys, private_keys, NULL, 0, keysmem); /* function returns 0 on any error in any packet - this does not mean, we cannot use the key. We check the details below therefore. */
|
pgp_filter_keys_from_mem(&s_io, public_keys, private_keys, NULL, 0, keysmem); /* function returns 0 on any error in any packet - this does not mean, we cannot use the key. We check the details below therefore. */
|
||||||
|
|
||||||
if (raw_key->type == DC_KEY_PUBLIC && public_keys->keyc >= 1) {
|
if (raw_key->type==DC_KEY_PUBLIC && public_keys->keyc >= 1) {
|
||||||
key_is_valid = 1;
|
key_is_valid = 1;
|
||||||
}
|
}
|
||||||
else if (raw_key->type == DC_KEY_PRIVATE && private_keys->keyc >= 1) {
|
else if (raw_key->type==DC_KEY_PRIVATE && private_keys->keyc >= 1) {
|
||||||
key_is_valid = 1;
|
key_is_valid = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,7 +449,7 @@ int dc_pgp_calc_fingerprint(const dc_key_t* raw_key, uint8_t** ret_fingerprint,
|
||||||
pgp_memory_t* keysmem = pgp_memory_new();
|
pgp_memory_t* keysmem = pgp_memory_new();
|
||||||
|
|
||||||
if (raw_key==NULL || ret_fingerprint==NULL || *ret_fingerprint!=NULL || ret_fingerprint_bytes==NULL || *ret_fingerprint_bytes!=0
|
if (raw_key==NULL || ret_fingerprint==NULL || *ret_fingerprint!=NULL || ret_fingerprint_bytes==NULL || *ret_fingerprint_bytes!=0
|
||||||
|| raw_key->binary == NULL || raw_key->bytes <= 0
|
|| raw_key->binary==NULL || raw_key->bytes <= 0
|
||||||
|| public_keys==NULL || private_keys==NULL || keysmem==NULL) {
|
|| public_keys==NULL || private_keys==NULL || keysmem==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -490,7 +490,7 @@ int dc_pgp_split_key(dc_context_t* context, const dc_key_t* private_in, dc_key_t
|
||||||
pgp_memory_t* pubmem = pgp_memory_new();
|
pgp_memory_t* pubmem = pgp_memory_new();
|
||||||
pgp_output_t* pubout = pgp_output_new();
|
pgp_output_t* pubout = pgp_output_new();
|
||||||
|
|
||||||
if (context == NULL || private_in==NULL || ret_public_key==NULL
|
if (context==NULL || private_in==NULL || ret_public_key==NULL
|
||||||
|| public_keys==NULL || private_keys==NULL || keysmem==NULL || pubmem==NULL || pubout==NULL) {
|
|| public_keys==NULL || private_keys==NULL || keysmem==NULL || pubmem==NULL || pubout==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -510,7 +510,7 @@ int dc_pgp_split_key(dc_context_t* context, const dc_key_t* private_in, dc_key_t
|
||||||
|
|
||||||
pgp_writer_set_memory(pubout, pubmem);
|
pgp_writer_set_memory(pubout, pubmem);
|
||||||
if (!pgp_write_xfer_key(pubout, &public_keys->keys[0], 0/*armored*/)
|
if (!pgp_write_xfer_key(pubout, &public_keys->keys[0], 0/*armored*/)
|
||||||
|| pubmem->buf == NULL || pubmem->length <= 0) {
|
|| pubmem->buf==NULL || pubmem->length <= 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,7 +589,7 @@ int dc_pgp_pk_encrypt( dc_context_t* context,
|
||||||
pgp_key_t* sk0 = &private_keys->keys[0];
|
pgp_key_t* sk0 = &private_keys->keys[0];
|
||||||
signedmem = pgp_sign_buf(&s_io, plain_text, plain_bytes, &sk0->key.seckey, time(NULL)/*birthtime*/, 0/*duration*/,
|
signedmem = pgp_sign_buf(&s_io, plain_text, plain_bytes, &sk0->key.seckey, time(NULL)/*birthtime*/, 0/*duration*/,
|
||||||
NULL/*hash, defaults to sha256*/, 0/*armored*/, 0/*cleartext*/);
|
NULL/*hash, defaults to sha256*/, 0/*armored*/, 0/*cleartext*/);
|
||||||
if (signedmem == NULL) {
|
if (signedmem==NULL) {
|
||||||
dc_log_warning(context, 0, "Signing failed.");
|
dc_log_warning(context, 0, "Signing failed.");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -604,7 +604,7 @@ int dc_pgp_pk_encrypt( dc_context_t* context,
|
||||||
}
|
}
|
||||||
|
|
||||||
pgp_memory_t* outmem = pgp_encrypt_buf(&s_io, signed_text, signed_bytes, public_keys, use_armor, NULL/*cipher*/, encrypt_raw_packet);
|
pgp_memory_t* outmem = pgp_encrypt_buf(&s_io, signed_text, signed_bytes, public_keys, use_armor, NULL/*cipher*/, encrypt_raw_packet);
|
||||||
if (outmem == NULL) {
|
if (outmem==NULL) {
|
||||||
dc_log_warning(context, 0, "Encryption failed.");
|
dc_log_warning(context, 0, "Encryption failed.");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -678,7 +678,7 @@ int dc_pgp_pk_decrypt( dc_context_t* context,
|
||||||
{
|
{
|
||||||
pgp_memory_t* outmem = pgp_decrypt_and_validate_buf(&s_io, vresult, ctext, ctext_bytes, private_keys, public_keys,
|
pgp_memory_t* outmem = pgp_decrypt_and_validate_buf(&s_io, vresult, ctext, ctext_bytes, private_keys, public_keys,
|
||||||
use_armor, &recipients_key_ids, &recipients_cnt);
|
use_armor, &recipients_key_ids, &recipients_cnt);
|
||||||
if (outmem == NULL) {
|
if (outmem==NULL) {
|
||||||
dc_log_warning(context, 0, "Decryption failed.");
|
dc_log_warning(context, 0, "Decryption failed.");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,9 @@ static void add_or_lookup_contact_by_addr(dc_context_t* context, const char* dis
|
||||||
{
|
{
|
||||||
/* is addr_spec equal to SELF? */
|
/* is addr_spec equal to SELF? */
|
||||||
int dummy = 0;
|
int dummy = 0;
|
||||||
if (check_self == NULL) { check_self = &dummy; }
|
if (check_self==NULL) { check_self = &dummy; }
|
||||||
|
|
||||||
if (context == NULL || context->magic != DC_CONTEXT_MAGIC || addr_spec == NULL) {
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || addr_spec==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ static void add_or_lookup_contact_by_addr(dc_context_t* context, const char* dis
|
||||||
|
|
||||||
static void dc_add_or_lookup_contacts_by_mailbox_list(dc_context_t* context, const struct mailimf_mailbox_list* mb_list, int origin, dc_array_t* ids, int* check_self)
|
static void dc_add_or_lookup_contacts_by_mailbox_list(dc_context_t* context, const struct mailimf_mailbox_list* mb_list, int origin, dc_array_t* ids, int* check_self)
|
||||||
{
|
{
|
||||||
if (context == NULL || context->magic != DC_CONTEXT_MAGIC || mb_list == NULL) {
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || mb_list==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,20 +94,20 @@ static void dc_add_or_lookup_contacts_by_mailbox_list(dc_context_t* context, con
|
||||||
|
|
||||||
static void dc_add_or_lookup_contacts_by_address_list(dc_context_t* context, const struct mailimf_address_list* adr_list, int origin, dc_array_t* ids, int* check_self)
|
static void dc_add_or_lookup_contacts_by_address_list(dc_context_t* context, const struct mailimf_address_list* adr_list, int origin, dc_array_t* ids, int* check_self)
|
||||||
{
|
{
|
||||||
if (context == NULL || context->magic != DC_CONTEXT_MAGIC || adr_list == NULL /*may be NULL eg. if bcc is given as `Bcc: \n` in the header */) {
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || adr_list==NULL /*may be NULL eg. if bcc is given as `Bcc: \n` in the header */) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (clistiter* cur = clist_begin(adr_list->ad_list); cur!=NULL ; cur=clist_next(cur)) {
|
for (clistiter* cur = clist_begin(adr_list->ad_list); cur!=NULL ; cur=clist_next(cur)) {
|
||||||
struct mailimf_address* adr = (struct mailimf_address*)clist_content(cur);
|
struct mailimf_address* adr = (struct mailimf_address*)clist_content(cur);
|
||||||
if (adr) {
|
if (adr) {
|
||||||
if (adr->ad_type == MAILIMF_ADDRESS_MAILBOX) {
|
if (adr->ad_type==MAILIMF_ADDRESS_MAILBOX) {
|
||||||
struct mailimf_mailbox* mb = adr->ad_data.ad_mailbox; /* can be NULL */
|
struct mailimf_mailbox* mb = adr->ad_data.ad_mailbox; /* can be NULL */
|
||||||
if (mb) {
|
if (mb) {
|
||||||
add_or_lookup_contact_by_addr(context, mb->mb_display_name, mb->mb_addr_spec, origin, ids, check_self);
|
add_or_lookup_contact_by_addr(context, mb->mb_display_name, mb->mb_addr_spec, origin, ids, check_self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (adr->ad_type == MAILIMF_ADDRESS_GROUP) {
|
else if (adr->ad_type==MAILIMF_ADDRESS_GROUP) {
|
||||||
struct mailimf_group* group = adr->ad_data.ad_group; /* can be NULL */
|
struct mailimf_group* group = adr->ad_data.ad_group; /* can be NULL */
|
||||||
if (group && group->grp_mb_list /*can be NULL*/) {
|
if (group && group->grp_mb_list /*can be NULL*/) {
|
||||||
dc_add_or_lookup_contacts_by_mailbox_list(context, group->grp_mb_list, origin, ids, check_self);
|
dc_add_or_lookup_contacts_by_mailbox_list(context, group->grp_mb_list, origin, ids, check_self);
|
||||||
|
@ -134,7 +134,7 @@ static int is_known_rfc724_mid(dc_context_t* context, const char* rfc724_mid)
|
||||||
" AND m.chat_id>" DC_STRINGIFY(DC_CHAT_ID_LAST_SPECIAL)
|
" AND m.chat_id>" DC_STRINGIFY(DC_CHAT_ID_LAST_SPECIAL)
|
||||||
" AND c.blocked=0;");
|
" AND c.blocked=0;");
|
||||||
sqlite3_bind_text(stmt, 1, rfc724_mid, -1, SQLITE_STATIC);
|
sqlite3_bind_text(stmt, 1, rfc724_mid, -1, SQLITE_STATIC);
|
||||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
if (sqlite3_step(stmt)==SQLITE_ROW) {
|
||||||
is_known = 1;
|
is_known = 1;
|
||||||
}
|
}
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
|
@ -164,7 +164,7 @@ static int dc_is_reply_to_known_message(dc_context_t* context, dc_mimeparser_t*
|
||||||
`In-Reply-To`/`References:` (to support non-Delta-Clients) or from `Chat-Predecessor:` (Delta clients, see comment in dc_chat.c) */
|
`In-Reply-To`/`References:` (to support non-Delta-Clients) or from `Chat-Predecessor:` (Delta clients, see comment in dc_chat.c) */
|
||||||
|
|
||||||
struct mailimf_optional_field* optional_field = NULL;
|
struct mailimf_optional_field* optional_field = NULL;
|
||||||
if ((optional_field=dc_mimeparser_lookup_optional_field2(mime_parser, "Chat-Predecessor", "X-MrPredecessor")) != NULL)
|
if ((optional_field=dc_mimeparser_lookup_optional_field2(mime_parser, "Chat-Predecessor", "X-MrPredecessor"))!=NULL)
|
||||||
{
|
{
|
||||||
if (is_known_rfc724_mid(context, optional_field->fld_value)) {
|
if (is_known_rfc724_mid(context, optional_field->fld_value)) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -173,7 +173,7 @@ static int dc_is_reply_to_known_message(dc_context_t* context, dc_mimeparser_t*
|
||||||
|
|
||||||
struct mailimf_field* field = NULL;
|
struct mailimf_field* field = NULL;
|
||||||
if ((field=dc_mimeparser_lookup_field(mime_parser, "In-Reply-To"))!=NULL
|
if ((field=dc_mimeparser_lookup_field(mime_parser, "In-Reply-To"))!=NULL
|
||||||
&& field->fld_type == MAILIMF_FIELD_IN_REPLY_TO)
|
&& field->fld_type==MAILIMF_FIELD_IN_REPLY_TO)
|
||||||
{
|
{
|
||||||
struct mailimf_in_reply_to* fld_in_reply_to = field->fld_data.fld_in_reply_to;
|
struct mailimf_in_reply_to* fld_in_reply_to = field->fld_data.fld_in_reply_to;
|
||||||
if (fld_in_reply_to) {
|
if (fld_in_reply_to) {
|
||||||
|
@ -184,7 +184,7 @@ static int dc_is_reply_to_known_message(dc_context_t* context, dc_mimeparser_t*
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((field=dc_mimeparser_lookup_field(mime_parser, "References"))!=NULL
|
if ((field=dc_mimeparser_lookup_field(mime_parser, "References"))!=NULL
|
||||||
&& field->fld_type == MAILIMF_FIELD_REFERENCES)
|
&& field->fld_type==MAILIMF_FIELD_REFERENCES)
|
||||||
{
|
{
|
||||||
struct mailimf_references* fld_references = field->fld_data.fld_references;
|
struct mailimf_references* fld_references = field->fld_data.fld_references;
|
||||||
if (fld_references) {
|
if (fld_references) {
|
||||||
|
@ -213,7 +213,7 @@ static int is_msgrmsg_rfc724_mid(dc_context_t* context, const char* rfc724_mid)
|
||||||
" AND msgrmsg!=0 "
|
" AND msgrmsg!=0 "
|
||||||
" AND chat_id>" DC_STRINGIFY(DC_CHAT_ID_LAST_SPECIAL) ";");
|
" AND chat_id>" DC_STRINGIFY(DC_CHAT_ID_LAST_SPECIAL) ";");
|
||||||
sqlite3_bind_text(stmt, 1, rfc724_mid, -1, SQLITE_STATIC);
|
sqlite3_bind_text(stmt, 1, rfc724_mid, -1, SQLITE_STATIC);
|
||||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
if (sqlite3_step(stmt)==SQLITE_ROW) {
|
||||||
is_msgrmsg = 1;
|
is_msgrmsg = 1;
|
||||||
}
|
}
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
|
@ -329,7 +329,7 @@ static dc_array_t* search_chat_ids_by_contact_ids(dc_context_t* context, const d
|
||||||
char* q3 = NULL;
|
char* q3 = NULL;
|
||||||
dc_array_t* chat_ids = dc_array_new(context, 23);
|
dc_array_t* chat_ids = dc_array_new(context, 23);
|
||||||
|
|
||||||
if (context == NULL || context->magic != DC_CONTEXT_MAGIC) {
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ static dc_array_t* search_chat_ids_by_contact_ids(dc_context_t* context, const d
|
||||||
|
|
||||||
for (i = 0; i < iCnt; i++) {
|
for (i = 0; i < iCnt; i++) {
|
||||||
uint32_t curr_id = dc_array_get_id(unsorted_contact_ids, i);
|
uint32_t curr_id = dc_array_get_id(unsorted_contact_ids, i);
|
||||||
if (curr_id != DC_CONTACT_ID_SELF && !dc_array_search_id(contact_ids, curr_id, NULL)) {
|
if (curr_id!=DC_CONTACT_ID_SELF && !dc_array_search_id(contact_ids, curr_id, NULL)) {
|
||||||
dc_array_add_id(contact_ids, curr_id);
|
dc_array_add_id(contact_ids, curr_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,8 +373,8 @@ static dc_array_t* search_chat_ids_by_contact_ids(dc_context_t* context, const d
|
||||||
uint32_t chat_id = sqlite3_column_int(stmt, 0);
|
uint32_t chat_id = sqlite3_column_int(stmt, 0);
|
||||||
uint32_t contact_id = sqlite3_column_int(stmt, 1);
|
uint32_t contact_id = sqlite3_column_int(stmt, 1);
|
||||||
|
|
||||||
if (chat_id != last_chat_id) {
|
if (chat_id!=last_chat_id) {
|
||||||
if (matches == dc_array_get_cnt(contact_ids) && mismatches == 0) {
|
if (matches==dc_array_get_cnt(contact_ids) && mismatches==0) {
|
||||||
dc_array_add_id(chat_ids, last_chat_id);
|
dc_array_add_id(chat_ids, last_chat_id);
|
||||||
}
|
}
|
||||||
last_chat_id = chat_id;
|
last_chat_id = chat_id;
|
||||||
|
@ -382,7 +382,7 @@ static dc_array_t* search_chat_ids_by_contact_ids(dc_context_t* context, const d
|
||||||
mismatches = 0;
|
mismatches = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contact_id == dc_array_get_id(contact_ids, matches)) {
|
if (contact_id==dc_array_get_id(contact_ids, matches)) {
|
||||||
matches++;
|
matches++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -390,7 +390,7 @@ static dc_array_t* search_chat_ids_by_contact_ids(dc_context_t* context, const d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matches == dc_array_get_cnt(contact_ids) && mismatches == 0) {
|
if (matches==dc_array_get_cnt(contact_ids) && mismatches==0) {
|
||||||
dc_array_add_id(chat_ids, last_chat_id);
|
dc_array_add_id(chat_ids, last_chat_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -551,7 +551,7 @@ static void create_or_lookup_adhoc_group(dc_context_t* context, dc_mimeparser_t*
|
||||||
|
|
||||||
/* create a new ad-hoc group
|
/* create a new ad-hoc group
|
||||||
- there is no need to check if this group exists; otherwise we would have catched it above */
|
- there is no need to check if this group exists; otherwise we would have catched it above */
|
||||||
if ((grpid = create_adhoc_grp_id(context, member_ids)) == NULL) {
|
if ((grpid = create_adhoc_grp_id(context, member_ids))==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,7 +710,7 @@ static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_
|
||||||
grpid = dc_strdup(optional_field->fld_value);
|
grpid = dc_strdup(optional_field->fld_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grpid == NULL)
|
if (grpid==NULL)
|
||||||
{
|
{
|
||||||
if ((field=dc_mimeparser_lookup_field(mime_parser, "Message-ID"))!=NULL && field->fld_type==MAILIMF_FIELD_MESSAGE_ID) {
|
if ((field=dc_mimeparser_lookup_field(mime_parser, "Message-ID"))!=NULL && field->fld_type==MAILIMF_FIELD_MESSAGE_ID) {
|
||||||
struct mailimf_message_id* fld_message_id = field->fld_data.fld_message_id;
|
struct mailimf_message_id* fld_message_id = field->fld_data.fld_message_id;
|
||||||
|
@ -719,7 +719,7 @@ static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grpid == NULL)
|
if (grpid==NULL)
|
||||||
{
|
{
|
||||||
if ((field=dc_mimeparser_lookup_field(mime_parser, "In-Reply-To"))!=NULL && field->fld_type==MAILIMF_FIELD_IN_REPLY_TO) {
|
if ((field=dc_mimeparser_lookup_field(mime_parser, "In-Reply-To"))!=NULL && field->fld_type==MAILIMF_FIELD_IN_REPLY_TO) {
|
||||||
struct mailimf_in_reply_to* fld_in_reply_to = field->fld_data.fld_in_reply_to;
|
struct mailimf_in_reply_to* fld_in_reply_to = field->fld_data.fld_in_reply_to;
|
||||||
|
@ -728,7 +728,7 @@ static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grpid == NULL)
|
if (grpid==NULL)
|
||||||
{
|
{
|
||||||
if ((field=dc_mimeparser_lookup_field(mime_parser, "References"))!=NULL && field->fld_type==MAILIMF_FIELD_REFERENCES) {
|
if ((field=dc_mimeparser_lookup_field(mime_parser, "References"))!=NULL && field->fld_type==MAILIMF_FIELD_REFERENCES) {
|
||||||
struct mailimf_references* fld_references = field->fld_data.fld_references;
|
struct mailimf_references* fld_references = field->fld_data.fld_references;
|
||||||
|
@ -737,7 +737,7 @@ static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grpid == NULL)
|
if (grpid==NULL)
|
||||||
{
|
{
|
||||||
create_or_lookup_adhoc_group(context, mime_parser, create_blocked, from_id, to_ids, &chat_id, &chat_id_blocked);
|
create_or_lookup_adhoc_group(context, mime_parser, create_blocked, from_id, to_ids, &chat_id, &chat_id_blocked);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -794,7 +794,7 @@ static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_
|
||||||
int group_explicitly_left = dc_is_group_explicitly_left(context, grpid);
|
int group_explicitly_left = dc_is_group_explicitly_left(context, grpid);
|
||||||
|
|
||||||
self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", "");
|
self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", "");
|
||||||
if (chat_id == 0
|
if (chat_id==0
|
||||||
&& !dc_mimeparser_is_mailinglist_message(mime_parser)
|
&& !dc_mimeparser_is_mailinglist_message(mime_parser)
|
||||||
&& grpid
|
&& grpid
|
||||||
&& grpname
|
&& grpname
|
||||||
|
@ -848,10 +848,10 @@ static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_
|
||||||
char* grpimage = NULL;
|
char* grpimage = NULL;
|
||||||
if (carray_count(mime_parser->parts)>=1) {
|
if (carray_count(mime_parser->parts)>=1) {
|
||||||
dc_mimepart_t* textpart = (dc_mimepart_t*)carray_get(mime_parser->parts, 0);
|
dc_mimepart_t* textpart = (dc_mimepart_t*)carray_get(mime_parser->parts, 0);
|
||||||
if (textpart->type == DC_MSG_TEXT) {
|
if (textpart->type==DC_MSG_TEXT) {
|
||||||
if (carray_count(mime_parser->parts)>=2) {
|
if (carray_count(mime_parser->parts)>=2) {
|
||||||
dc_mimepart_t* imgpart = (dc_mimepart_t*)carray_get(mime_parser->parts, 1);
|
dc_mimepart_t* imgpart = (dc_mimepart_t*)carray_get(mime_parser->parts, 1);
|
||||||
if (imgpart->type == DC_MSG_IMAGE) {
|
if (imgpart->type==DC_MSG_IMAGE) {
|
||||||
grpimage = dc_param_get(imgpart->param, DC_PARAM_FILE, NULL);
|
grpimage = dc_param_get(imgpart->param, DC_PARAM_FILE, NULL);
|
||||||
ok = 1;
|
ok = 1;
|
||||||
}
|
}
|
||||||
|
@ -885,7 +885,7 @@ static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_
|
||||||
sqlite3_step(stmt);
|
sqlite3_step(stmt);
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
|
|
||||||
if (skip==NULL || dc_addr_cmp(self_addr, skip) != 0) {
|
if (skip==NULL || dc_addr_cmp(self_addr, skip)!=0) {
|
||||||
dc_add_to_chat_contacts_table(context, chat_id, DC_CONTACT_ID_SELF);
|
dc_add_to_chat_contacts_table(context, chat_id, DC_CONTACT_ID_SELF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -913,7 +913,7 @@ static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_
|
||||||
|
|
||||||
/* check the number of receivers -
|
/* check the number of receivers -
|
||||||
the only critical situation is if the user hits "Reply" instead of "Reply all" in a non-messenger-client */
|
the only critical situation is if the user hits "Reply" instead of "Reply all" in a non-messenger-client */
|
||||||
if (to_ids_cnt == 1 && mime_parser->is_send_by_messenger==0) {
|
if (to_ids_cnt==1 && mime_parser->is_send_by_messenger==0) {
|
||||||
int is_contact_cnt = dc_get_chat_contact_cnt(context, chat_id);
|
int is_contact_cnt = dc_get_chat_contact_cnt(context, chat_id);
|
||||||
if (is_contact_cnt > 3 /* to_ids_cnt==1 may be "From: A, To: B, SELF" as SELF is not counted in to_ids_cnt. So everything up to 3 is no error. */) {
|
if (is_contact_cnt > 3 /* to_ids_cnt==1 may be "From: A, To: B, SELF" as SELF is not counted in to_ids_cnt. So everything up to 3 is no error. */) {
|
||||||
chat_id = 0;
|
chat_id = 0;
|
||||||
|
@ -978,7 +978,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
dc_log_info(context, 0, "Receiving message %s/%lu...", server_folder? server_folder:"?", server_uid);
|
dc_log_info(context, 0, "Receiving message %s/%lu...", server_folder? server_folder:"?", server_uid);
|
||||||
|
|
||||||
to_ids = dc_array_new(context, 16);
|
to_ids = dc_array_new(context, 16);
|
||||||
if (to_ids==NULL || created_db_entries==NULL || rr_event_to_send==NULL || mime_parser == NULL) {
|
if (to_ids==NULL || created_db_entries==NULL || rr_event_to_send==NULL || mime_parser==NULL) {
|
||||||
dc_log_info(context, 0, "Bad param.");
|
dc_log_info(context, 0, "Bad param.");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -987,8 +987,8 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
mailimf_fields* msg_fields {
|
mailimf_fields* msg_fields {
|
||||||
clist* fld_list; // list of mailimf_field
|
clist* fld_list; // list of mailimf_field
|
||||||
}
|
}
|
||||||
mailimf_body* msg_body { // != NULL
|
mailimf_body* msg_body { //!=NULL
|
||||||
const char * bd_text; // != NULL
|
const char * bd_text; //!=NULL
|
||||||
size_t bd_size;
|
size_t bd_size;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1094,9 +1094,9 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rfc724_mid == NULL) {
|
if (rfc724_mid==NULL) {
|
||||||
rfc724_mid = dc_create_incoming_rfc724_mid(sort_timestamp, from_id, to_ids);
|
rfc724_mid = dc_create_incoming_rfc724_mid(sort_timestamp, from_id, to_ids);
|
||||||
if (rfc724_mid == NULL) {
|
if (rfc724_mid==NULL) {
|
||||||
dc_log_info(context, 0, "Cannot create Message-ID.");
|
dc_log_info(context, 0, "Cannot create Message-ID.");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -1129,7 +1129,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
to_id = DC_CONTACT_ID_SELF;
|
to_id = DC_CONTACT_ID_SELF;
|
||||||
|
|
||||||
// handshake messages must be processed before chats are created (eg. contacs may be marked as verified)
|
// handshake messages must be processed before chats are created (eg. contacs may be marked as verified)
|
||||||
assert( chat_id == 0);
|
assert( chat_id==0);
|
||||||
if (dc_mimeparser_lookup_field(mime_parser, "Secure-Join")) {
|
if (dc_mimeparser_lookup_field(mime_parser, "Secure-Join")) {
|
||||||
dc_sqlite3_commit(context->sql);
|
dc_sqlite3_commit(context->sql);
|
||||||
int handshake = dc_handle_securejoin_handshake(context, mime_parser, from_id);
|
int handshake = dc_handle_securejoin_handshake(context, mime_parser, from_id);
|
||||||
|
@ -1148,7 +1148,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
|
|
||||||
/* get the chat_id - a chat_id here is no indicator that the chat is displayed in the normal list, it might also be
|
/* get the chat_id - a chat_id here is no indicator that the chat is displayed in the normal list, it might also be
|
||||||
blocked and displayed in the deaddrop as a result */
|
blocked and displayed in the deaddrop as a result */
|
||||||
if (chat_id == 0)
|
if (chat_id==0)
|
||||||
{
|
{
|
||||||
/* try to create a group
|
/* try to create a group
|
||||||
(groups appear automatically only if the _sender_ is known, see core issue #54) */
|
(groups appear automatically only if the _sender_ is known, see core issue #54) */
|
||||||
|
@ -1160,7 +1160,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chat_id == 0)
|
if (chat_id==0)
|
||||||
{
|
{
|
||||||
/* check if the message belongs to a mailing list */
|
/* check if the message belongs to a mailing list */
|
||||||
if (dc_mimeparser_is_mailinglist_message(mime_parser)) {
|
if (dc_mimeparser_is_mailinglist_message(mime_parser)) {
|
||||||
|
@ -1169,7 +1169,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chat_id == 0)
|
if (chat_id==0)
|
||||||
{
|
{
|
||||||
/* try to create a normal chat */
|
/* try to create a normal chat */
|
||||||
int create_blocked = (incoming_origin>=DC_ORIGIN_MIN_START_NEW_NCHAT/*always false, for now*/ || from_id==to_id)? DC_CHAT_NOT_BLOCKED : DC_CHAT_DEADDROP_BLOCKED;
|
int create_blocked = (incoming_origin>=DC_ORIGIN_MIN_START_NEW_NCHAT/*always false, for now*/ || from_id==to_id)? DC_CHAT_NOT_BLOCKED : DC_CHAT_DEADDROP_BLOCKED;
|
||||||
|
@ -1194,7 +1194,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chat_id == 0)
|
if (chat_id==0)
|
||||||
{
|
{
|
||||||
/* maybe from_id is null or sth. else is suspicious, move message to trash */
|
/* maybe from_id is null or sth. else is suspicious, move message to trash */
|
||||||
chat_id = DC_CHAT_ID_TRASH;
|
chat_id = DC_CHAT_ID_TRASH;
|
||||||
|
@ -1203,7 +1203,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
/* degrade state for unknown senders and non-delta messages
|
/* degrade state for unknown senders and non-delta messages
|
||||||
(the latter may be removed if we run into spam problems, currently this is fine)
|
(the latter may be removed if we run into spam problems, currently this is fine)
|
||||||
(noticed messages do count as being unread; therefore, the deaddrop will not popup in the chatlist) */
|
(noticed messages do count as being unread; therefore, the deaddrop will not popup in the chatlist) */
|
||||||
if (chat_id_blocked && state == DC_STATE_IN_FRESH) {
|
if (chat_id_blocked && state==DC_STATE_IN_FRESH) {
|
||||||
if (incoming_origin<DC_ORIGIN_MIN_VERIFIED && mime_parser->is_send_by_messenger==0) {
|
if (incoming_origin<DC_ORIGIN_MIN_VERIFIED && mime_parser->is_send_by_messenger==0) {
|
||||||
state = DC_STATE_IN_NOTICED;
|
state = DC_STATE_IN_NOTICED;
|
||||||
}
|
}
|
||||||
|
@ -1216,7 +1216,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
if (dc_array_get_cnt(to_ids) >= 1) {
|
if (dc_array_get_cnt(to_ids) >= 1) {
|
||||||
to_id = dc_array_get_id(to_ids, 0);
|
to_id = dc_array_get_id(to_ids, 0);
|
||||||
|
|
||||||
if (chat_id == 0)
|
if (chat_id==0)
|
||||||
{
|
{
|
||||||
create_or_lookup_group(context, mime_parser, DC_CHAT_NOT_BLOCKED, from_id, to_ids, &chat_id, &chat_id_blocked);
|
create_or_lookup_group(context, mime_parser, DC_CHAT_NOT_BLOCKED, from_id, to_ids, &chat_id, &chat_id_blocked);
|
||||||
if (chat_id && chat_id_blocked) {
|
if (chat_id && chat_id_blocked) {
|
||||||
|
@ -1225,7 +1225,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chat_id == 0)
|
if (chat_id==0)
|
||||||
{
|
{
|
||||||
int create_blocked = (mime_parser->is_send_by_messenger && !dc_is_contact_blocked(context, to_id))? DC_CHAT_NOT_BLOCKED : DC_CHAT_DEADDROP_BLOCKED;
|
int create_blocked = (mime_parser->is_send_by_messenger && !dc_is_contact_blocked(context, to_id))? DC_CHAT_NOT_BLOCKED : DC_CHAT_DEADDROP_BLOCKED;
|
||||||
dc_create_or_lookup_nchat_by_contact_id(context, to_id, create_blocked, &chat_id, &chat_id_blocked);
|
dc_create_or_lookup_nchat_by_contact_id(context, to_id, create_blocked, &chat_id, &chat_id_blocked);
|
||||||
|
@ -1236,9 +1236,9 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chat_id == 0) {
|
if (chat_id==0) {
|
||||||
if (dc_array_get_cnt(to_ids) == 0 && to_self) {
|
if (dc_array_get_cnt(to_ids)==0 && to_self) {
|
||||||
/* from_id == to_id == DC_CONTACT_ID_SELF - this is a self-sent messages, maybe an Autocrypt Setup Message */
|
/* from_id==to_id==DC_CONTACT_ID_SELF - this is a self-sent messages, maybe an Autocrypt Setup Message */
|
||||||
dc_create_or_lookup_nchat_by_contact_id(context, DC_CONTACT_ID_SELF, DC_CHAT_NOT_BLOCKED, &chat_id, &chat_id_blocked);
|
dc_create_or_lookup_nchat_by_contact_id(context, DC_CONTACT_ID_SELF, DC_CHAT_NOT_BLOCKED, &chat_id, &chat_id_blocked);
|
||||||
if (chat_id && chat_id_blocked) {
|
if (chat_id && chat_id_blocked) {
|
||||||
dc_unblock_chat(context, chat_id);
|
dc_unblock_chat(context, chat_id);
|
||||||
|
@ -1247,7 +1247,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chat_id == 0) {
|
if (chat_id==0) {
|
||||||
chat_id = DC_CHAT_ID_TRASH;
|
chat_id = DC_CHAT_ID_TRASH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1290,7 +1290,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (part->type == DC_MSG_TEXT) {
|
if (part->type==DC_MSG_TEXT) {
|
||||||
txt_raw = dc_mprintf("%s\n\n%s", mime_parser->subject? mime_parser->subject : "", part->msg_raw);
|
txt_raw = dc_mprintf("%s\n\n%s", mime_parser->subject? mime_parser->subject : "", part->msg_raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1316,7 +1316,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
sqlite3_bind_text (stmt, 15, part->param->packed, -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt, 15, part->param->packed, -1, SQLITE_STATIC);
|
||||||
sqlite3_bind_int (stmt, 16, part->bytes);
|
sqlite3_bind_int (stmt, 16, part->bytes);
|
||||||
sqlite3_bind_int (stmt, 17, hidden);
|
sqlite3_bind_int (stmt, 17, hidden);
|
||||||
if (sqlite3_step(stmt) != SQLITE_DONE) {
|
if (sqlite3_step(stmt)!=SQLITE_DONE) {
|
||||||
dc_log_info(context, 0, "Cannot write DB.");
|
dc_log_info(context, 0, "Cannot write DB.");
|
||||||
goto cleanup; /* i/o error - there is nothing more we can do - in other cases, we try to write at least an empty record */
|
goto cleanup; /* i/o error - there is nothing more we can do - in other cases, we try to write at least an empty record */
|
||||||
}
|
}
|
||||||
|
@ -1324,7 +1324,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
free(txt_raw);
|
free(txt_raw);
|
||||||
txt_raw = NULL;
|
txt_raw = NULL;
|
||||||
|
|
||||||
if (first_dblocal_id == 0) {
|
if (first_dblocal_id==0) {
|
||||||
first_dblocal_id = dc_sqlite3_get_rowid(context->sql, "msgs", "rfc724_mid", rfc724_mid); // rfc724_mid is unique only for the first insert
|
first_dblocal_id = dc_sqlite3_get_rowid(context->sql, "msgs", "rfc724_mid", rfc724_mid); // rfc724_mid is unique only for the first insert
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1335,7 +1335,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
dc_log_info(context, 0, "Message has %i parts and is assigned to chat #%i.", icnt, chat_id);
|
dc_log_info(context, 0, "Message has %i parts and is assigned to chat #%i.", icnt, chat_id);
|
||||||
|
|
||||||
/* check event to send */
|
/* check event to send */
|
||||||
if (chat_id == DC_CHAT_ID_TRASH)
|
if (chat_id==DC_CHAT_ID_TRASH)
|
||||||
{
|
{
|
||||||
create_event_to_send = 0;
|
create_event_to_send = 0;
|
||||||
}
|
}
|
||||||
|
@ -1381,7 +1381,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(report_type->pa_value, "disposition-notification") == 0
|
if (strcmp(report_type->pa_value, "disposition-notification")==0
|
||||||
&& clist_count(report_root->mm_data.mm_multipart.mm_mp_list) >= 2 /* the first part is for humans, the second for machines */)
|
&& clist_count(report_root->mm_data.mm_multipart.mm_mp_list) >= 2 /* the first part is for humans, the second for machines */)
|
||||||
{
|
{
|
||||||
if (mdns_enabled /*to get a clear functionality, do not show incoming MDNs if the options is disabled*/)
|
if (mdns_enabled /*to get a clear functionality, do not show incoming MDNs if the options is disabled*/)
|
||||||
|
|
|
@ -307,7 +307,7 @@ void dc_saxparser_init(dc_saxparser_t* saxparser, void* userdata)
|
||||||
|
|
||||||
void dc_saxparser_set_tag_handler(dc_saxparser_t* saxparser, dc_saxparser_starttag_cb_t starttag_cb, dc_saxparser_endtag_cb_t endtag_cb)
|
void dc_saxparser_set_tag_handler(dc_saxparser_t* saxparser, dc_saxparser_starttag_cb_t starttag_cb, dc_saxparser_endtag_cb_t endtag_cb)
|
||||||
{
|
{
|
||||||
if (saxparser == NULL) {
|
if (saxparser==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,7 +318,7 @@ void dc_saxparser_set_tag_handler(dc_saxparser_t* saxparser, dc_saxparser_startt
|
||||||
|
|
||||||
void dc_saxparser_set_text_handler (dc_saxparser_t* saxparser, dc_saxparser_text_cb_t text_cb)
|
void dc_saxparser_set_text_handler (dc_saxparser_t* saxparser, dc_saxparser_text_cb_t text_cb)
|
||||||
{
|
{
|
||||||
if (saxparser == NULL) {
|
if (saxparser==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ void dc_saxparser_parse(dc_saxparser_t* saxparser, const char* buf_start__)
|
||||||
|
|
||||||
attr[0] = NULL; /* null-terminate list, this also terminates "free_values" */
|
attr[0] = NULL; /* null-terminate list, this also terminates "free_values" */
|
||||||
|
|
||||||
if (saxparser == NULL) {
|
if (saxparser==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,21 +348,21 @@ void dc_saxparser_parse(dc_saxparser_t* saxparser, const char* buf_start__)
|
||||||
p = buf_start;
|
p = buf_start;
|
||||||
while (*p)
|
while (*p)
|
||||||
{
|
{
|
||||||
if (*p == '<')
|
if (*p=='<')
|
||||||
{
|
{
|
||||||
call_text_cb(saxparser, last_text_start, p - last_text_start, '&'); /* flush pending text */
|
call_text_cb(saxparser, last_text_start, p - last_text_start, '&'); /* flush pending text */
|
||||||
|
|
||||||
p++;
|
p++;
|
||||||
if (strncmp(p, "!--", 3) == 0)
|
if (strncmp(p, "!--", 3)==0)
|
||||||
{
|
{
|
||||||
/* skip <!-- ... --> comment
|
/* skip <!-- ... --> comment
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
|
|
||||||
p = strstr(p, "-->");
|
p = strstr(p, "-->");
|
||||||
if (p == NULL) { goto cleanup; }
|
if (p==NULL) { goto cleanup; }
|
||||||
p += 3;
|
p += 3;
|
||||||
}
|
}
|
||||||
else if (strncmp(p, "![CDATA[", 8) == 0)
|
else if (strncmp(p, "![CDATA[", 8)==0)
|
||||||
{
|
{
|
||||||
/* process <![CDATA[ ... ]]> text
|
/* process <![CDATA[ ... ]]> text
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
|
@ -377,18 +377,18 @@ void dc_saxparser_parse(dc_saxparser_t* saxparser, const char* buf_start__)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strncmp(p, "!DOCTYPE", 8) == 0)
|
else if (strncmp(p, "!DOCTYPE", 8)==0)
|
||||||
{
|
{
|
||||||
/* skip <!DOCTYPE ...> or <!DOCTYPE name [ ... ]>
|
/* skip <!DOCTYPE ...> or <!DOCTYPE name [ ... ]>
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
|
|
||||||
while (*p && *p != '[' && *p != '>' ) p++; /* search for [ or >, whatever comes first */
|
while (*p && *p != '[' && *p != '>' ) p++; /* search for [ or >, whatever comes first */
|
||||||
if (*p == 0) {
|
if (*p==0) {
|
||||||
goto cleanup; /* unclosed doctype */
|
goto cleanup; /* unclosed doctype */
|
||||||
}
|
}
|
||||||
else if (*p == '[') {
|
else if (*p=='[') {
|
||||||
p = strstr(p, "]>"); /* search end of inline doctype */
|
p = strstr(p, "]>"); /* search end of inline doctype */
|
||||||
if (p == NULL) {
|
if (p==NULL) {
|
||||||
goto cleanup; /* unclosed inline doctype */
|
goto cleanup; /* unclosed inline doctype */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -399,19 +399,19 @@ void dc_saxparser_parse(dc_saxparser_t* saxparser, const char* buf_start__)
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (*p == '?')
|
else if (*p=='?')
|
||||||
{
|
{
|
||||||
/* skip <? ... ?> processing instruction
|
/* skip <? ... ?> processing instruction
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
|
|
||||||
p = strstr(p, "?>");
|
p = strstr(p, "?>");
|
||||||
if (p == NULL) { goto cleanup; } /* unclosed processing instruction */
|
if (p==NULL) { goto cleanup; } /* unclosed processing instruction */
|
||||||
p += 2;
|
p += 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
p += strspn(p, XML_WS); /* skip whitespace between `<` and tagname */
|
p += strspn(p, XML_WS); /* skip whitespace between `<` and tagname */
|
||||||
if (*p == '/')
|
if (*p=='/')
|
||||||
{
|
{
|
||||||
/* process </tag> end tag
|
/* process </tag> end tag
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
|
@ -459,11 +459,11 @@ void dc_saxparser_parse(dc_saxparser_t* saxparser, const char* buf_start__)
|
||||||
/* attribute found */
|
/* attribute found */
|
||||||
char* after_attr_name = p;
|
char* after_attr_name = p;
|
||||||
p += strspn(p, XML_WS); /* skip whitespace between attribute name and possible `=` */
|
p += strspn(p, XML_WS); /* skip whitespace between attribute name and possible `=` */
|
||||||
if (*p == '=')
|
if (*p=='=')
|
||||||
{
|
{
|
||||||
p += strspn(p, XML_WS "="); /* skip spaces and equal signs */
|
p += strspn(p, XML_WS "="); /* skip spaces and equal signs */
|
||||||
char quote = *p;
|
char quote = *p;
|
||||||
if (quote == '"' || quote == '\'')
|
if (quote=='"' || quote=='\'')
|
||||||
{
|
{
|
||||||
/* quoted attribute value */
|
/* quoted attribute value */
|
||||||
p++;
|
p++;
|
||||||
|
@ -500,7 +500,7 @@ void dc_saxparser_parse(dc_saxparser_t* saxparser, const char* buf_start__)
|
||||||
{
|
{
|
||||||
char* beg_attr_name_new = beg_attr_name;
|
char* beg_attr_name_new = beg_attr_name;
|
||||||
int free_bits = (beg_attr_value_new != beg_attr_value)? FREE_VALUE : 0;
|
int free_bits = (beg_attr_value_new != beg_attr_value)? FREE_VALUE : 0;
|
||||||
if (after_attr_name == p) {
|
if (after_attr_name==p) {
|
||||||
/* take care not to overwrite the current pointer (happens eg. for `<tag attrWithoutValue>` */
|
/* take care not to overwrite the current pointer (happens eg. for `<tag attrWithoutValue>` */
|
||||||
bak = *after_attr_name;
|
bak = *after_attr_name;
|
||||||
*after_attr_name = '\0';
|
*after_attr_name = '\0';
|
||||||
|
@ -532,7 +532,7 @@ void dc_saxparser_parse(dc_saxparser_t* saxparser, const char* buf_start__)
|
||||||
|
|
||||||
/* self-closing tag */
|
/* self-closing tag */
|
||||||
p += strspn(p, XML_WS); /* skip whitespace before possible `/` */
|
p += strspn(p, XML_WS); /* skip whitespace before possible `/` */
|
||||||
if (*p == '/')
|
if (*p=='/')
|
||||||
{
|
{
|
||||||
p++;
|
p++;
|
||||||
*after_tag_name = 0;
|
*after_tag_name = 0;
|
||||||
|
@ -543,7 +543,7 @@ void dc_saxparser_parse(dc_saxparser_t* saxparser, const char* buf_start__)
|
||||||
} /* end of processing start-tag */
|
} /* end of processing start-tag */
|
||||||
|
|
||||||
p = strchr(p, '>');
|
p = strchr(p, '>');
|
||||||
if (p == NULL) { goto cleanup; } /* unclosed start-tag or end-tag */
|
if (p==NULL) { goto cleanup; } /* unclosed start-tag or end-tag */
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
} /* end of processing start-tag or end-tag */
|
} /* end of processing start-tag or end-tag */
|
||||||
|
|
|
@ -50,7 +50,7 @@ static int is_empty_line(const char* buf)
|
||||||
|
|
||||||
static int is_plain_quote(const char* buf)
|
static int is_plain_quote(const char* buf)
|
||||||
{
|
{
|
||||||
if (buf[0] == '>') {
|
if (buf[0]=='>') {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -71,7 +71,7 @@ static int is_quoted_headline(const char* buf)
|
||||||
forget to insert a line break between the answer and the quoted headline ...)) */
|
forget to insert a line break between the answer and the quoted headline ...)) */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf_len > 0 && buf[buf_len-1] == ':') {
|
if (buf_len > 0 && buf[buf_len-1]==':') {
|
||||||
return 1; /* the buffer is a quoting headline in the meaning described above) */
|
return 1; /* the buffer is a quoting headline in the meaning described above) */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ dc_simplify_t* dc_simplify_new()
|
||||||
|
|
||||||
void dc_simplify_unref(dc_simplify_t* simplify)
|
void dc_simplify_unref(dc_simplify_t* simplify)
|
||||||
{
|
{
|
||||||
if (simplify == NULL) {
|
if (simplify==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char
|
||||||
char* line2 = (char*)carray_get(lines, l_first+2);
|
char* line2 = (char*)carray_get(lines, l_first+2);
|
||||||
if (strcmp(line0, "---------- Forwarded message ----------")==0 /* do not chage this! sent exactly in this form in dc_chat.c! */
|
if (strcmp(line0, "---------- Forwarded message ----------")==0 /* do not chage this! sent exactly in this form in dc_chat.c! */
|
||||||
&& strncmp(line1, "From: ", 6)==0
|
&& strncmp(line1, "From: ", 6)==0
|
||||||
&& line2[0] == 0)
|
&& line2[0]==0)
|
||||||
{
|
{
|
||||||
simplify->is_forwarded = 1; /* nothing is cutted, the forward state should displayed explicitly in the ui */
|
simplify->is_forwarded = 1; /* nothing is cutted, the forward state should displayed explicitly in the ui */
|
||||||
l_first += 3;
|
l_first += 3;
|
||||||
|
@ -234,7 +234,7 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char
|
||||||
l_lastQuotedLine = l;
|
l_lastQuotedLine = l;
|
||||||
}
|
}
|
||||||
else if (!is_empty_line(line)) {
|
else if (!is_empty_line(line)) {
|
||||||
if (is_quoted_headline(line) && !hasQuotedHeadline && l_lastQuotedLine == -1) {
|
if (is_quoted_headline(line) && !hasQuotedHeadline && l_lastQuotedLine==-1) {
|
||||||
hasQuotedHeadline = 1; /* continue, the line may be a headline */
|
hasQuotedHeadline = 1; /* continue, the line may be a headline */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -308,7 +308,7 @@ char* dc_simplify_simplify(dc_simplify_t* simplify, const char* in_unterminated,
|
||||||
char* out = NULL;
|
char* out = NULL;
|
||||||
char* temp = NULL;
|
char* temp = NULL;
|
||||||
|
|
||||||
if (simplify == NULL || in_unterminated == NULL || in_bytes <= 0) {
|
if (simplify==NULL || in_unterminated==NULL || in_bytes <= 0) {
|
||||||
return dc_strdup("");
|
return dc_strdup("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ char* dc_simplify_simplify(dc_simplify_t* simplify, const char* in_unterminated,
|
||||||
simplify->is_cut_at_end = 0;
|
simplify->is_cut_at_end = 0;
|
||||||
|
|
||||||
out = strndup((char*)in_unterminated, in_bytes); /* strndup() makes sure, the string is null-terminated */
|
out = strndup((char*)in_unterminated, in_bytes); /* strndup() makes sure, the string is null-terminated */
|
||||||
if (out == NULL) {
|
if (out==NULL) {
|
||||||
return dc_strdup("");
|
return dc_strdup("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ void dc_sqlite3_log_error(dc_sqlite3_t* sql, const char* msg_format, ...)
|
||||||
const char* notSetUp = "SQLite object not set up.";
|
const char* notSetUp = "SQLite object not set up.";
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, msg_format);
|
va_start(va, msg_format);
|
||||||
msg = sqlite3_vmprintf(msg_format, va); if (msg == NULL) { dc_log_error(sql->context, 0, "Bad log format string \"%s\".", msg_format); }
|
msg = sqlite3_vmprintf(msg_format, va); if (msg==NULL) { dc_log_error(sql->context, 0, "Bad log format string \"%s\".", msg_format); }
|
||||||
dc_log_error(sql->context, 0, "%s SQLite says: %s", msg, sql->cobj? sqlite3_errmsg(sql->cobj) : notSetUp);
|
dc_log_error(sql->context, 0, "%s SQLite says: %s", msg, sql->cobj? sqlite3_errmsg(sql->cobj) : notSetUp);
|
||||||
sqlite3_free(msg);
|
sqlite3_free(msg);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
@ -69,7 +69,7 @@ sqlite3_stmt* dc_sqlite3_prepare(dc_sqlite3_t* sql, const char* querystr)
|
||||||
{
|
{
|
||||||
sqlite3_stmt* stmt = NULL;
|
sqlite3_stmt* stmt = NULL;
|
||||||
|
|
||||||
if (sql == NULL || querystr == NULL || sql->cobj == NULL) {
|
if (sql==NULL || querystr==NULL || sql->cobj==NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ int dc_sqlite3_execute(dc_sqlite3_t* sql, const char* querystr)
|
||||||
int sqlState = 0;
|
int sqlState = 0;
|
||||||
|
|
||||||
stmt = dc_sqlite3_prepare(sql, querystr);
|
stmt = dc_sqlite3_prepare(sql, querystr);
|
||||||
if (stmt == NULL) {
|
if (stmt==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ dc_sqlite3_t* dc_sqlite3_new(dc_context_t* context)
|
||||||
|
|
||||||
void dc_sqlite3_unref(dc_sqlite3_t* sql)
|
void dc_sqlite3_unref(dc_sqlite3_t* sql)
|
||||||
{
|
{
|
||||||
if (sql == NULL) {
|
if (sql==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,11 +163,11 @@ void dc_sqlite3_unref(dc_sqlite3_t* sql)
|
||||||
|
|
||||||
int dc_sqlite3_open(dc_sqlite3_t* sql, const char* dbfile, int flags)
|
int dc_sqlite3_open(dc_sqlite3_t* sql, const char* dbfile, int flags)
|
||||||
{
|
{
|
||||||
if (sql == NULL || dbfile == NULL) {
|
if (sql==NULL || dbfile==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sqlite3_threadsafe() == 0) {
|
if (sqlite3_threadsafe()==0) {
|
||||||
dc_log_error(sql->context, 0, "Sqlite3 compiled thread-unsafe; this is not supported.");
|
dc_log_error(sql->context, 0, "Sqlite3 compiled thread-unsafe; this is not supported.");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -433,7 +433,7 @@ int dc_sqlite3_open(dc_sqlite3_t* sql, const char* dbfile, int flags)
|
||||||
dc_sqlite3_execute(sql, "ALTER TABLE acpeerstates ADD COLUMN verified_key_fingerprint TEXT DEFAULT '';"); /* do not add `COLLATE NOCASE` case-insensivity is not needed as we force uppercase on store - otoh case-sensivity may be neeed for other/upcoming fingerprint formats */
|
dc_sqlite3_execute(sql, "ALTER TABLE acpeerstates ADD COLUMN verified_key_fingerprint TEXT DEFAULT '';"); /* do not add `COLLATE NOCASE` case-insensivity is not needed as we force uppercase on store - otoh case-sensivity may be neeed for other/upcoming fingerprint formats */
|
||||||
dc_sqlite3_execute(sql, "CREATE INDEX acpeerstates_index5 ON acpeerstates (verified_key_fingerprint);");
|
dc_sqlite3_execute(sql, "CREATE INDEX acpeerstates_index5 ON acpeerstates (verified_key_fingerprint);");
|
||||||
|
|
||||||
if (dbversion_before_update == 34)
|
if (dbversion_before_update==34)
|
||||||
{
|
{
|
||||||
// migrate database from the use of verified-flags to verified_key,
|
// migrate database from the use of verified-flags to verified_key,
|
||||||
// _only_ version 34 (0.17.0) has the fields public_key_verified and gossip_key_verified
|
// _only_ version 34 (0.17.0) has the fields public_key_verified and gossip_key_verified
|
||||||
|
@ -461,7 +461,7 @@ int dc_sqlite3_open(dc_sqlite3_t* sql, const char* dbfile, int flags)
|
||||||
if (recalc_fingerprints)
|
if (recalc_fingerprints)
|
||||||
{
|
{
|
||||||
sqlite3_stmt* stmt = dc_sqlite3_prepare(sql, "SELECT addr FROM acpeerstates;");
|
sqlite3_stmt* stmt = dc_sqlite3_prepare(sql, "SELECT addr FROM acpeerstates;");
|
||||||
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
while (sqlite3_step(stmt)==SQLITE_ROW) {
|
||||||
dc_apeerstate_t* peerstate = dc_apeerstate_new(sql->context);
|
dc_apeerstate_t* peerstate = dc_apeerstate_new(sql->context);
|
||||||
if (dc_apeerstate_load_by_addr(peerstate, sql, (const char*)sqlite3_column_text(stmt, 0))
|
if (dc_apeerstate_load_by_addr(peerstate, sql, (const char*)sqlite3_column_text(stmt, 0))
|
||||||
&& dc_apeerstate_recalc_fingerprint(peerstate)) {
|
&& dc_apeerstate_recalc_fingerprint(peerstate)) {
|
||||||
|
@ -484,7 +484,7 @@ cleanup:
|
||||||
|
|
||||||
void dc_sqlite3_close(dc_sqlite3_t* sql)
|
void dc_sqlite3_close(dc_sqlite3_t* sql)
|
||||||
{
|
{
|
||||||
if (sql == NULL) {
|
if (sql==NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,7 +500,7 @@ void dc_sqlite3_close(dc_sqlite3_t* sql)
|
||||||
|
|
||||||
int dc_sqlite3_is_open(const dc_sqlite3_t* sql)
|
int dc_sqlite3_is_open(const dc_sqlite3_t* sql)
|
||||||
{
|
{
|
||||||
if (sql == NULL || sql->cobj == NULL) {
|
if (sql==NULL || sql->cobj==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -514,17 +514,17 @@ int dc_sqlite3_table_exists(dc_sqlite3_t* sql, const char* name)
|
||||||
sqlite3_stmt* stmt = NULL;
|
sqlite3_stmt* stmt = NULL;
|
||||||
int sqlState = 0;
|
int sqlState = 0;
|
||||||
|
|
||||||
if ((querystr=sqlite3_mprintf("PRAGMA table_info(%s)", name)) == NULL) { /* this statement cannot be used with binded variables */
|
if ((querystr=sqlite3_mprintf("PRAGMA table_info(%s)", name))==NULL) { /* this statement cannot be used with binded variables */
|
||||||
dc_log_error(sql->context, 0, "dc_sqlite3_table_exists_(): Out of memory.");
|
dc_log_error(sql->context, 0, "dc_sqlite3_table_exists_(): Out of memory.");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((stmt=dc_sqlite3_prepare(sql, querystr)) == NULL) {
|
if ((stmt=dc_sqlite3_prepare(sql, querystr))==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlState = sqlite3_step(stmt);
|
sqlState = sqlite3_step(stmt);
|
||||||
if (sqlState == SQLITE_ROW) {
|
if (sqlState==SQLITE_ROW) {
|
||||||
ret = 1; /* the table exists. Other states are SQLITE_DONE or SQLITE_ERROR in both cases we return 0. */
|
ret = 1; /* the table exists. Other states are SQLITE_DONE or SQLITE_ERROR in both cases we return 0. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -555,7 +555,7 @@ int dc_sqlite3_set_config(dc_sqlite3_t* sql, const char* key, const char* value)
|
||||||
int state = 0;
|
int state = 0;
|
||||||
sqlite3_stmt* stmt = NULL;
|
sqlite3_stmt* stmt = NULL;
|
||||||
|
|
||||||
if (key == NULL) {
|
if (key==NULL) {
|
||||||
dc_log_error(sql->context, 0, "dc_sqlite3_set_config(): Bad parameter.");
|
dc_log_error(sql->context, 0, "dc_sqlite3_set_config(): Bad parameter.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -574,14 +574,14 @@ int dc_sqlite3_set_config(dc_sqlite3_t* sql, const char* key, const char* value)
|
||||||
state = sqlite3_step(stmt);
|
state = sqlite3_step(stmt);
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
|
|
||||||
if (state == SQLITE_DONE) {
|
if (state==SQLITE_DONE) {
|
||||||
stmt = dc_sqlite3_prepare(sql, "INSERT INTO config (keyname, value) VALUES (?, ?);");
|
stmt = dc_sqlite3_prepare(sql, "INSERT INTO config (keyname, value) VALUES (?, ?);");
|
||||||
sqlite3_bind_text (stmt, 1, key, -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt, 1, key, -1, SQLITE_STATIC);
|
||||||
sqlite3_bind_text (stmt, 2, value, -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt, 2, value, -1, SQLITE_STATIC);
|
||||||
state = sqlite3_step(stmt);
|
state = sqlite3_step(stmt);
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
}
|
}
|
||||||
else if (state == SQLITE_ROW) {
|
else if (state==SQLITE_ROW) {
|
||||||
stmt = dc_sqlite3_prepare(sql, "UPDATE config SET value=? WHERE keyname=?;");
|
stmt = dc_sqlite3_prepare(sql, "UPDATE config SET value=? WHERE keyname=?;");
|
||||||
sqlite3_bind_text (stmt, 1, value, -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt, 1, value, -1, SQLITE_STATIC);
|
||||||
sqlite3_bind_text (stmt, 2, key, -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt, 2, key, -1, SQLITE_STATIC);
|
||||||
|
@ -615,13 +615,13 @@ char* dc_sqlite3_get_config(dc_sqlite3_t* sql, const char* key, const char* def)
|
||||||
{
|
{
|
||||||
sqlite3_stmt* stmt = NULL;
|
sqlite3_stmt* stmt = NULL;
|
||||||
|
|
||||||
if (!dc_sqlite3_is_open(sql) || key == NULL) {
|
if (!dc_sqlite3_is_open(sql) || key==NULL) {
|
||||||
return dc_strdup_keep_null(def);
|
return dc_strdup_keep_null(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt = dc_sqlite3_prepare(sql, SELECT_v_FROM_config_k_STATEMENT);
|
stmt = dc_sqlite3_prepare(sql, SELECT_v_FROM_config_k_STATEMENT);
|
||||||
sqlite3_bind_text(stmt, 1, key, -1, SQLITE_STATIC);
|
sqlite3_bind_text(stmt, 1, key, -1, SQLITE_STATIC);
|
||||||
if (sqlite3_step(stmt) == SQLITE_ROW)
|
if (sqlite3_step(stmt)==SQLITE_ROW)
|
||||||
{
|
{
|
||||||
const unsigned char* ptr = sqlite3_column_text(stmt, 0); /* Do not pass the pointers returned from sqlite3_column_text(), etc. into sqlite3_free(). */
|
const unsigned char* ptr = sqlite3_column_text(stmt, 0); /* Do not pass the pointers returned from sqlite3_column_text(), etc. into sqlite3_free(). */
|
||||||
if (ptr)
|
if (ptr)
|
||||||
|
@ -642,7 +642,7 @@ char* dc_sqlite3_get_config(dc_sqlite3_t* sql, const char* key, const char* def)
|
||||||
int32_t dc_sqlite3_get_config_int(dc_sqlite3_t* sql, const char* key, int32_t def)
|
int32_t dc_sqlite3_get_config_int(dc_sqlite3_t* sql, const char* key, int32_t def)
|
||||||
{
|
{
|
||||||
char* str = dc_sqlite3_get_config(sql, key, NULL);
|
char* str = dc_sqlite3_get_config(sql, key, NULL);
|
||||||
if (str == NULL) {
|
if (str==NULL) {
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
int32_t ret = atol(str);
|
int32_t ret = atol(str);
|
||||||
|
@ -654,7 +654,7 @@ int32_t dc_sqlite3_get_config_int(dc_sqlite3_t* sql, const char* key, int32_t de
|
||||||
int dc_sqlite3_set_config_int(dc_sqlite3_t* sql, const char* key, int32_t value)
|
int dc_sqlite3_set_config_int(dc_sqlite3_t* sql, const char* key, int32_t value)
|
||||||
{
|
{
|
||||||
char* value_str = dc_mprintf("%i", (int)value);
|
char* value_str = dc_mprintf("%i", (int)value);
|
||||||
if (value_str == NULL) {
|
if (value_str==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int ret = dc_sqlite3_set_config(sql, key, value_str);
|
int ret = dc_sqlite3_set_config(sql, key, value_str);
|
||||||
|
|
|
@ -141,7 +141,7 @@ void dc_strbuilder_catf(dc_strbuilder_t* strbuilder, const char* format, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = malloc(char_cnt_without_zero+2 /* +1 would be enough, however, protect against off-by-one-errors */);
|
buf = malloc(char_cnt_without_zero+2 /* +1 would be enough, however, protect against off-by-one-errors */);
|
||||||
if (buf == NULL) {
|
if (buf==NULL) {
|
||||||
va_end(argp_copy);
|
va_end(argp_copy);
|
||||||
dc_strbuilder_cat(strbuilder, "ErrMem");
|
dc_strbuilder_cat(strbuilder, "ErrMem");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -64,21 +64,21 @@ char* dc_urlencode(const char *to_encode)
|
||||||
{
|
{
|
||||||
const char *pstr = to_encode;
|
const char *pstr = to_encode;
|
||||||
|
|
||||||
if (to_encode == NULL) {
|
if (to_encode==NULL) {
|
||||||
return dc_strdup("");
|
return dc_strdup("");
|
||||||
}
|
}
|
||||||
|
|
||||||
char *buf = malloc(strlen(to_encode) * 3 + 1), *pbuf = buf;
|
char *buf = malloc(strlen(to_encode) * 3 + 1), *pbuf = buf;
|
||||||
if (buf == NULL) {
|
if (buf==NULL) {
|
||||||
exit(46);
|
exit(46);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*pstr)
|
while (*pstr)
|
||||||
{
|
{
|
||||||
if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') {
|
if (isalnum(*pstr) || *pstr=='-' || *pstr=='_' || *pstr=='.' || *pstr=='~') {
|
||||||
*pbuf++ = *pstr;
|
*pbuf++ = *pstr;
|
||||||
}
|
}
|
||||||
else if (*pstr == ' ') {
|
else if (*pstr==' ') {
|
||||||
*pbuf++ = '+';
|
*pbuf++ = '+';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -109,24 +109,24 @@ char* dc_urldecode(const char* to_decode)
|
||||||
{
|
{
|
||||||
const char *pstr = to_decode;
|
const char *pstr = to_decode;
|
||||||
|
|
||||||
if (to_decode == NULL) {
|
if (to_decode==NULL) {
|
||||||
return dc_strdup("");
|
return dc_strdup("");
|
||||||
}
|
}
|
||||||
|
|
||||||
char *buf = malloc(strlen(to_decode) + 1), *pbuf = buf;
|
char *buf = malloc(strlen(to_decode) + 1), *pbuf = buf;
|
||||||
if (buf == NULL) {
|
if (buf==NULL) {
|
||||||
exit(50);
|
exit(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*pstr)
|
while (*pstr)
|
||||||
{
|
{
|
||||||
if (*pstr == '%') {
|
if (*pstr=='%') {
|
||||||
if (pstr[1] && pstr[2]) {
|
if (pstr[1] && pstr[2]) {
|
||||||
*pbuf++ = hex_2_int(pstr[1]) << 4 | hex_2_int(pstr[2]);
|
*pbuf++ = hex_2_int(pstr[1]) << 4 | hex_2_int(pstr[2]);
|
||||||
pstr += 2;
|
pstr += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (*pstr == '+') {
|
else if (*pstr=='+') {
|
||||||
*pbuf++ = ' ';
|
*pbuf++ = ' ';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -203,15 +203,15 @@ static int quote_word(const char* display_charset, MMAPString* mmapstr, const ch
|
||||||
char hex[4];
|
char hex[4];
|
||||||
int col = 0;
|
int col = 0;
|
||||||
|
|
||||||
if (mmap_string_append(mmapstr, "=?") == NULL) {
|
if (mmap_string_append(mmapstr, "=?")==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mmap_string_append(mmapstr, display_charset) == NULL) {
|
if (mmap_string_append(mmapstr, display_charset)==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mmap_string_append(mmapstr, "?Q?") == NULL) {
|
if (mmap_string_append(mmapstr, "?Q?")==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,25 +231,25 @@ static int quote_word(const char* display_charset, MMAPString* mmapstr, const ch
|
||||||
/* adds a concatened encoded word */
|
/* adds a concatened encoded word */
|
||||||
int old_pos;
|
int old_pos;
|
||||||
|
|
||||||
if (mmap_string_append(mmapstr, "?=") == NULL) {
|
if (mmap_string_append(mmapstr, "?=")==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mmap_string_append(mmapstr, " ") == NULL) {
|
if (mmap_string_append(mmapstr, " ")==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
old_pos = mmapstr->len;
|
old_pos = mmapstr->len;
|
||||||
|
|
||||||
if (mmap_string_append(mmapstr, "=?") == NULL) {
|
if (mmap_string_append(mmapstr, "=?")==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mmap_string_append(mmapstr, display_charset) == NULL) {
|
if (mmap_string_append(mmapstr, display_charset)==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mmap_string_append(mmapstr, "?Q?") == NULL) {
|
if (mmap_string_append(mmapstr, "?Q?")==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,20 +292,20 @@ static int quote_word(const char* display_charset, MMAPString* mmapstr, const ch
|
||||||
if (do_quote_char)
|
if (do_quote_char)
|
||||||
{
|
{
|
||||||
snprintf(hex, 4, "=%2.2X", (unsigned char) * cur);
|
snprintf(hex, 4, "=%2.2X", (unsigned char) * cur);
|
||||||
if (mmap_string_append(mmapstr, hex) == NULL) {
|
if (mmap_string_append(mmapstr, hex)==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
col += 3;
|
col += 3;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (* cur == ' ') {
|
if (* cur==' ') {
|
||||||
if (mmap_string_append_c(mmapstr, '_') == NULL) {
|
if (mmap_string_append_c(mmapstr, '_')==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (mmap_string_append_c(mmapstr, * cur) == NULL) {
|
if (mmap_string_append_c(mmapstr, * cur)==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -315,7 +315,7 @@ static int quote_word(const char* display_charset, MMAPString* mmapstr, const ch
|
||||||
cur++;
|
cur++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mmap_string_append(mmapstr, "?=") == NULL) {
|
if (mmap_string_append(mmapstr, "?=")==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,7 +364,7 @@ char* dc_encode_header_words(const char* to_encode)
|
||||||
const char* cur = to_encode;
|
const char* cur = to_encode;
|
||||||
MMAPString* mmapstr = mmap_string_new("");
|
MMAPString* mmapstr = mmap_string_new("");
|
||||||
|
|
||||||
if (to_encode == NULL || mmapstr == NULL) {
|
if (to_encode==NULL || mmapstr==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,28 +402,28 @@ char* dc_encode_header_words(const char* to_encode)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((* end == ' ') || (* end == '\t')) {
|
if ((* end==' ') || (* end=='\t')) {
|
||||||
if (mmap_string_append_c(mmapstr, * end) == 0) {
|
if (mmap_string_append_c(mmapstr, * end)==0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
end ++;
|
end ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (* end != '\0') {
|
if (* end != '\0') {
|
||||||
if (mmap_string_append_len(mmapstr, end, cur - end) == NULL) {
|
if (mmap_string_append_len(mmapstr, end, cur - end)==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (mmap_string_append_len(mmapstr, begin, cur - begin) == NULL) {
|
if (mmap_string_append_len(mmapstr, begin, cur - begin)==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((* cur == ' ') || (* cur == '\t')) {
|
if ((* cur==' ') || (* cur=='\t')) {
|
||||||
if (mmap_string_append_c(mmapstr, * cur) == 0) {
|
if (mmap_string_append_c(mmapstr, * cur)==0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
cur ++;
|
cur ++;
|
||||||
|
@ -453,14 +453,14 @@ char* dc_decode_header_words(const char* in)
|
||||||
/* decode strings as. `=?UTF-8?Q?Bj=c3=b6rn_Petersen?=`)
|
/* decode strings as. `=?UTF-8?Q?Bj=c3=b6rn_Petersen?=`)
|
||||||
if `in` is NULL, `out` is NULL as well; also returns NULL on errors */
|
if `in` is NULL, `out` is NULL as well; also returns NULL on errors */
|
||||||
|
|
||||||
if (in == NULL) {
|
if (in==NULL) {
|
||||||
return NULL; /* no string given */
|
return NULL; /* no string given */
|
||||||
}
|
}
|
||||||
|
|
||||||
char* out = NULL;
|
char* out = NULL;
|
||||||
size_t cur_token = 0;
|
size_t cur_token = 0;
|
||||||
int r = mailmime_encoded_phrase_parse(DEF_INCOMING_CHARSET, in, strlen(in), &cur_token, DEF_DISPLAY_CHARSET, &out);
|
int r = mailmime_encoded_phrase_parse(DEF_INCOMING_CHARSET, in, strlen(in), &cur_token, DEF_DISPLAY_CHARSET, &out);
|
||||||
if (r != MAILIMF_NO_ERROR || out == NULL) {
|
if (r != MAILIMF_NO_ERROR || out==NULL) {
|
||||||
out = dc_strdup(in); /* error, make a copy of the original string (as we free it later) */
|
out = dc_strdup(in); /* error, make a copy of the original string (as we free it later) */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,7 +543,7 @@ char* dc_encode_modified_utf7(const char* to_encode, int change_spaces)
|
||||||
bitstogo = 0;
|
bitstogo = 0;
|
||||||
utf8total= 0;
|
utf8total= 0;
|
||||||
}
|
}
|
||||||
if (change_spaces && c == ' ') {
|
if (change_spaces && c==' ') {
|
||||||
*dst++ = '_';
|
*dst++ = '_';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -551,7 +551,7 @@ char* dc_encode_modified_utf7(const char* to_encode, int change_spaces)
|
||||||
}
|
}
|
||||||
|
|
||||||
// encode '&' as '&-'
|
// encode '&' as '&-'
|
||||||
if (c == '&') {
|
if (c=='&') {
|
||||||
*dst++ = '-';
|
*dst++ = '-';
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -653,7 +653,7 @@ char* dc_decode_modified_utf7(const char *to_decode, int change_spaces)
|
||||||
char* dst = NULL;
|
char* dst = NULL;
|
||||||
char* res = NULL;
|
char* res = NULL;
|
||||||
|
|
||||||
if (to_decode == NULL) {
|
if (to_decode==NULL) {
|
||||||
return dc_strdup("");
|
return dc_strdup("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -673,16 +673,16 @@ char* dc_decode_modified_utf7(const char *to_decode, int change_spaces)
|
||||||
{
|
{
|
||||||
c = *src++;
|
c = *src++;
|
||||||
// deal with literal characters and &-
|
// deal with literal characters and &-
|
||||||
if (c != '&' || *src == '-') {
|
if (c != '&' || *src=='-') {
|
||||||
// encode literally
|
// encode literally
|
||||||
if (change_spaces && c == '_') {
|
if (change_spaces && c=='_') {
|
||||||
*dst++ = ' ';
|
*dst++ = ' ';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*dst++ = c;
|
*dst++ = c;
|
||||||
}
|
}
|
||||||
// skip over the '-' if this is an &- sequence
|
// skip over the '-' if this is an &- sequence
|
||||||
if (c == '&') ++src;
|
if (c=='&') ++src;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX
|
// convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX
|
||||||
|
@ -739,7 +739,7 @@ char* dc_decode_modified_utf7(const char *to_decode, int change_spaces)
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip over trailing '-' in modified UTF-7 encoding
|
// skip over trailing '-' in modified UTF-7 encoding
|
||||||
if (*src == '-') {
|
if (*src=='-') {
|
||||||
++src;
|
++src;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -795,12 +795,12 @@ char* dc_encode_ext_header(const char* to_encode)
|
||||||
#define PREFIX "utf-8''"
|
#define PREFIX "utf-8''"
|
||||||
const char *pstr = to_encode;
|
const char *pstr = to_encode;
|
||||||
|
|
||||||
if (to_encode == NULL) {
|
if (to_encode==NULL) {
|
||||||
return dc_strdup(PREFIX);
|
return dc_strdup(PREFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *buf = malloc(strlen(PREFIX) + strlen(to_encode) * 3 + 1);
|
char *buf = malloc(strlen(PREFIX) + strlen(to_encode) * 3 + 1);
|
||||||
if (buf == NULL) {
|
if (buf==NULL) {
|
||||||
exit(46);
|
exit(46);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,7 +810,7 @@ char* dc_encode_ext_header(const char* to_encode)
|
||||||
|
|
||||||
while (*pstr)
|
while (*pstr)
|
||||||
{
|
{
|
||||||
if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') {
|
if (isalnum(*pstr) || *pstr=='-' || *pstr=='_' || *pstr=='.' || *pstr=='~') {
|
||||||
*pbuf++ = *pstr;
|
*pbuf++ = *pstr;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -841,13 +841,13 @@ char* dc_decode_ext_header(const char* to_decode)
|
||||||
char* charset = NULL;
|
char* charset = NULL;
|
||||||
const char* p2 = NULL;
|
const char* p2 = NULL;
|
||||||
|
|
||||||
if (to_decode == NULL) {
|
if (to_decode==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get char set
|
// get char set
|
||||||
if ((p2=strchr(to_decode, '\'')) == NULL
|
if ((p2=strchr(to_decode, '\''))==NULL
|
||||||
|| (p2 == to_decode) /*no empty charset allowed*/) {
|
|| (p2==to_decode) /*no empty charset allowed*/) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -855,7 +855,7 @@ char* dc_decode_ext_header(const char* to_decode)
|
||||||
p2++;
|
p2++;
|
||||||
|
|
||||||
// skip language
|
// skip language
|
||||||
if ((p2=strchr(p2, '\'')) == NULL) {
|
if ((p2=strchr(p2, '\''))==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -867,7 +867,7 @@ char* dc_decode_ext_header(const char* to_decode)
|
||||||
if (charset!=NULL && strcmp(charset, "utf-8")!=0 && strcmp(charset, "UTF-8")!=0) {
|
if (charset!=NULL && strcmp(charset, "utf-8")!=0 && strcmp(charset, "UTF-8")!=0) {
|
||||||
char* converted = NULL;
|
char* converted = NULL;
|
||||||
int r = charconv("utf-8", charset, decoded, strlen(decoded), &converted);
|
int r = charconv("utf-8", charset, decoded, strlen(decoded), &converted);
|
||||||
if (r == MAIL_CHARCONV_NO_ERROR && converted != NULL) {
|
if (r==MAIL_CHARCONV_NO_ERROR && converted != NULL) {
|
||||||
free(decoded);
|
free(decoded);
|
||||||
decoded = converted;
|
decoded = converted;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ void dc_token_save(dc_context_t* context, dc_tokennamespc_t namespc, uint32_t fo
|
||||||
{
|
{
|
||||||
sqlite3_stmt* stmt = NULL;
|
sqlite3_stmt* stmt = NULL;
|
||||||
|
|
||||||
if (context == NULL || context->magic != DC_CONTEXT_MAGIC || token == NULL) { // foreign_id may be 0
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || token==NULL) { // foreign_id may be 0
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ char* dc_token_lookup(dc_context_t* context, dc_tokennamespc_t namespc, uint32_t
|
||||||
char* token = NULL;
|
char* token = NULL;
|
||||||
sqlite3_stmt* stmt = NULL;
|
sqlite3_stmt* stmt = NULL;
|
||||||
|
|
||||||
if (context == NULL || context->magic != DC_CONTEXT_MAGIC) {
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ int dc_token_exists(dc_context_t* context, dc_tokennamespc_t namespc, const char
|
||||||
int exists = 0;
|
int exists = 0;
|
||||||
sqlite3_stmt* stmt = NULL;
|
sqlite3_stmt* stmt = NULL;
|
||||||
|
|
||||||
if (context == NULL || context->magic != DC_CONTEXT_MAGIC || token == NULL) {
|
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || token==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,12 +53,12 @@ char* dc_strdup(const char* s) /* strdup(NULL) is undefined, save_strdup(NULL) r
|
||||||
{
|
{
|
||||||
char* ret = NULL;
|
char* ret = NULL;
|
||||||
if (s) {
|
if (s) {
|
||||||
if ((ret=strdup(s)) == NULL) {
|
if ((ret=strdup(s))==NULL) {
|
||||||
exit(16); /* cannot allocate (little) memory, unrecoverable error */
|
exit(16); /* cannot allocate (little) memory, unrecoverable error */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ((ret=(char*)calloc(1, 1)) == NULL) {
|
if ((ret=(char*)calloc(1, 1))==NULL) {
|
||||||
exit(17); /* cannot allocate little memory, unrecoverable error */
|
exit(17); /* cannot allocate little memory, unrecoverable error */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ void dc_ltrim(char* buf)
|
||||||
cur++; len--;
|
cur++; len--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((const unsigned char*)buf != cur) {
|
if ((const unsigned char*)buf!=cur) {
|
||||||
memmove(buf, cur, len + 1);
|
memmove(buf, cur, len + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ void dc_rtrim(char* buf)
|
||||||
len = strlen(buf);
|
len = strlen(buf);
|
||||||
cur = (unsigned char*)buf + len - 1;
|
cur = (unsigned char*)buf + len - 1;
|
||||||
|
|
||||||
while (cur != (unsigned char*)buf && isspace(*cur)) {
|
while (cur!=(unsigned char*)buf && isspace(*cur)) {
|
||||||
--cur, --len;
|
--cur, --len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ int dc_str_replace(char** haystack, const char* needle, const char* replacement)
|
||||||
int needle_len = 0;
|
int needle_len = 0;
|
||||||
int replacement_len = 0;
|
int replacement_len = 0;
|
||||||
|
|
||||||
if (haystack==NULL || *haystack==NULL || needle == NULL || needle[0]==0) {
|
if (haystack==NULL || *haystack==NULL || needle==NULL || needle[0]==0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ int dc_str_replace(char** haystack, const char* needle, const char* replacement)
|
||||||
int dc_str_contains(const char* haystack, const const char* needle)
|
int dc_str_contains(const char* haystack, const const char* needle)
|
||||||
{
|
{
|
||||||
/* case-insensitive search of needle in haystack, return 1 if found, 0 if not */
|
/* case-insensitive search of needle in haystack, return 1 if found, 0 if not */
|
||||||
if (haystack==NULL || needle == NULL) {
|
if (haystack==NULL || needle==NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ char* dc_binary_to_uc_hex(const uint8_t* buf, size_t bytes)
|
||||||
char* hex = NULL;
|
char* hex = NULL;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (buf == NULL || bytes <= 0) {
|
if (buf==NULL || bytes<=0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ char* dc_mprintf(const char* format, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = malloc(char_cnt_without_zero+2 /* +1 would be enough, however, protect against off-by-one-errors */);
|
buf = malloc(char_cnt_without_zero+2 /* +1 would be enough, however, protect against off-by-one-errors */);
|
||||||
if (buf == NULL) {
|
if (buf==NULL) {
|
||||||
va_end(argp_copy);
|
va_end(argp_copy);
|
||||||
return dc_strdup("ErrMem");
|
return dc_strdup("ErrMem");
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ char* dc_mprintf(const char* format, ...)
|
||||||
sqlite_str = sqlite3_vmprintf(format, argp);
|
sqlite_str = sqlite3_vmprintf(format, argp);
|
||||||
va_end(argp);
|
va_end(argp);
|
||||||
|
|
||||||
if (sqlite_str == NULL) {
|
if (sqlite_str==NULL) {
|
||||||
return dc_strdup("ErrFmt"); /* error - the result must be free()'d */
|
return dc_strdup("ErrFmt"); /* error - the result must be free()'d */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ void dc_remove_cr_chars(char* buf)
|
||||||
{
|
{
|
||||||
const char* p1 = buf; /* search for first `\r` */
|
const char* p1 = buf; /* search for first `\r` */
|
||||||
while (*p1) {
|
while (*p1) {
|
||||||
if (*p1 == '\r') {
|
if (*p1=='\r') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
p1++;
|
p1++;
|
||||||
|
@ -332,7 +332,7 @@ void dc_remove_cr_chars(char* buf)
|
||||||
|
|
||||||
char* p2 = (char*)p1; /* p1 is `\r` or null-byte; start removing `\r` */
|
char* p2 = (char*)p1; /* p1 is `\r` or null-byte; start removing `\r` */
|
||||||
while (*p1) {
|
while (*p1) {
|
||||||
if (*p1 != '\r') {
|
if (*p1!='\r') {
|
||||||
*p2 = *p1;
|
*p2 = *p1;
|
||||||
p2++;
|
p2++;
|
||||||
}
|
}
|
||||||
|
@ -491,7 +491,7 @@ void dc_truncate_str(char* buf, int approx_chars)
|
||||||
*p = 0;
|
*p = 0;
|
||||||
|
|
||||||
if (strchr(buf, ' ')!=NULL) {
|
if (strchr(buf, ' ')!=NULL) {
|
||||||
while (p[-1] != ' ' && p[-1] != '\n') { /* rewind to the previous space, avoid half utf-8 characters */
|
while (p[-1]!=' ' && p[-1]!='\n') { /* rewind to the previous space, avoid half utf-8 characters */
|
||||||
p--;
|
p--;
|
||||||
*p = 0;
|
*p = 0;
|
||||||
}
|
}
|
||||||
|
@ -511,7 +511,7 @@ carray* dc_split_into_lines(const char* buf_terminated)
|
||||||
unsigned int l_indx = 0;
|
unsigned int l_indx = 0;
|
||||||
|
|
||||||
while (*p1) {
|
while (*p1) {
|
||||||
if (*p1 == '\n') {
|
if (*p1=='\n') {
|
||||||
carray_add(lines, (void*)strndup(line_start, line_chars), &l_indx);
|
carray_add(lines, (void*)strndup(line_start, line_chars), &l_indx);
|
||||||
p1++;
|
p1++;
|
||||||
line_start = p1;
|
line_start = p1;
|
||||||
|
@ -545,7 +545,7 @@ char* dc_insert_breaks(const char* in, int break_every, const char* break_chars)
|
||||||
/* insert a space every n characters, the return must be free()'d.
|
/* insert a space every n characters, the return must be free()'d.
|
||||||
this is useful to allow lines being wrapped according to RFC 5322 (adds linebreaks before spaces) */
|
this is useful to allow lines being wrapped according to RFC 5322 (adds linebreaks before spaces) */
|
||||||
|
|
||||||
if (in == NULL || break_every <= 0 || break_chars == NULL) {
|
if (in==NULL || break_every<=0 || break_chars==NULL) {
|
||||||
return dc_strdup(in);
|
return dc_strdup(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -556,7 +556,7 @@ char* dc_insert_breaks(const char* in, int break_every, const char* break_chars)
|
||||||
out_len += (out_len/break_every+1)*break_chars_len + 1/*nullbyte*/;
|
out_len += (out_len/break_every+1)*break_chars_len + 1/*nullbyte*/;
|
||||||
|
|
||||||
char* out = malloc(out_len);
|
char* out = malloc(out_len);
|
||||||
if (out == NULL) { return NULL; }
|
if (out==NULL) { return NULL; }
|
||||||
|
|
||||||
const char* i = in;
|
const char* i = in;
|
||||||
char* o = out;
|
char* o = out;
|
||||||
|
@ -608,11 +608,11 @@ static int tmcomp(struct tm * atmp, struct tm * btmp) /* from mailcore2 */
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
if ((result = (atmp->tm_year - btmp->tm_year)) == 0 &&
|
if ((result = (atmp->tm_year - btmp->tm_year))==0 &&
|
||||||
(result = (atmp->tm_mon - btmp->tm_mon)) == 0 &&
|
(result = (atmp->tm_mon - btmp->tm_mon))==0 &&
|
||||||
(result = (atmp->tm_mday - btmp->tm_mday)) == 0 &&
|
(result = (atmp->tm_mday - btmp->tm_mday))==0 &&
|
||||||
(result = (atmp->tm_hour - btmp->tm_hour)) == 0 &&
|
(result = (atmp->tm_hour - btmp->tm_hour))==0 &&
|
||||||
(result = (atmp->tm_min - btmp->tm_min)) == 0)
|
(result = (atmp->tm_min - btmp->tm_min))==0)
|
||||||
result = atmp->tm_sec - btmp->tm_sec;
|
result = atmp->tm_sec - btmp->tm_sec;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -646,7 +646,7 @@ static time_t mkgmtime(struct tm * tmp) /* from mailcore2 */
|
||||||
for ( ; ;) {
|
for ( ; ;) {
|
||||||
gmtime_r(&t, &mytm);
|
gmtime_r(&t, &mytm);
|
||||||
dir = tmcomp(&mytm, &yourtm);
|
dir = tmcomp(&mytm, &yourtm);
|
||||||
if (dir != 0) {
|
if (dir!=0) {
|
||||||
if (bits-- < 0) {
|
if (bits-- < 0) {
|
||||||
return DC_INVALID_TIMESTAMP;
|
return DC_INVALID_TIMESTAMP;
|
||||||
}
|
}
|
||||||
|
@ -890,7 +890,7 @@ char* dc_create_outgoing_rfc724_mid(const char* grpid, const char* from_addr)
|
||||||
char* ret = NULL;
|
char* ret = NULL;
|
||||||
const char* at_hostname = strchr(from_addr, '@');
|
const char* at_hostname = strchr(from_addr, '@');
|
||||||
|
|
||||||
if (at_hostname == NULL) {
|
if (at_hostname==NULL) {
|
||||||
at_hostname = "@nohost";
|
at_hostname = "@nohost";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -917,7 +917,7 @@ char* dc_create_incoming_rfc724_mid(time_t message_timestamp, uint32_t contact_i
|
||||||
- when fetching the same message again, this function should generate the same Message-ID
|
- when fetching the same message again, this function should generate the same Message-ID
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (message_timestamp == DC_INVALID_TIMESTAMP || contact_ids_to == NULL || dc_array_get_cnt(contact_ids_to)==0) {
|
if (message_timestamp==DC_INVALID_TIMESTAMP || contact_ids_to==NULL || dc_array_get_cnt(contact_ids_to)==0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -947,14 +947,14 @@ char* dc_extract_grpid_from_rfc724_mid(const char* mid)
|
||||||
char* p1 = NULL;
|
char* p1 = NULL;
|
||||||
int grpid_len = 0;
|
int grpid_len = 0;
|
||||||
|
|
||||||
if (mid == NULL || strlen(mid)<8 || mid[0]!='G' || mid[1]!='r' || mid[2]!='.') {
|
if (mid==NULL || strlen(mid)<8 || mid[0]!='G' || mid[1]!='r' || mid[2]!='.') {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
grpid = dc_strdup(&mid[3]);
|
grpid = dc_strdup(&mid[3]);
|
||||||
|
|
||||||
p1 = strchr(grpid, '.');
|
p1 = strchr(grpid, '.');
|
||||||
if (p1 == NULL) {
|
if (p1==NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
*p1 = 0;
|
*p1 = 0;
|
||||||
|
@ -968,7 +968,7 @@ char* dc_extract_grpid_from_rfc724_mid(const char* mid)
|
||||||
success = 1;
|
success = 1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (success == 0) { free(grpid); grpid = NULL; }
|
if (success==0) { free(grpid); grpid = NULL; }
|
||||||
return success? grpid : NULL;
|
return success? grpid : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -997,7 +997,7 @@ char* dc_extract_grpid_from_rfc724_mid_list(const clist* list)
|
||||||
int dc_file_exist(const char* pathNfilename)
|
int dc_file_exist(const char* pathNfilename)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (stat(pathNfilename, &st) == 0) {
|
if (stat(pathNfilename, &st)==0) {
|
||||||
return 1; /* the size, however, may be 0 */
|
return 1; /* the size, however, may be 0 */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1009,7 +1009,7 @@ int dc_file_exist(const char* pathNfilename)
|
||||||
uint64_t dc_get_filebytes(const char* pathNfilename)
|
uint64_t dc_get_filebytes(const char* pathNfilename)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (stat(pathNfilename, &st) == 0) {
|
if (stat(pathNfilename, &st)==0) {
|
||||||
return (uint64_t)st.st_size;
|
return (uint64_t)st.st_size;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1075,7 +1075,7 @@ int dc_copy_file(const char* src, const char* dest, dc_context_t* log/*may be NU
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((bytes_read=read(fd_src, buf, DC_COPY_BUF_SIZE)) > 0) {
|
while ((bytes_read=read(fd_src, buf, DC_COPY_BUF_SIZE)) > 0) {
|
||||||
if (write(fd_dest, buf, bytes_read) != bytes_read) {
|
if (write(fd_dest, buf, bytes_read)!=bytes_read) {
|
||||||
dc_log_error(log, 0, "Cannot write %i bytes to \"%s\".", bytes_read, dest);
|
dc_log_error(log, 0, "Cannot write %i bytes to \"%s\".", bytes_read, dest);
|
||||||
}
|
}
|
||||||
anything_copied = 1;
|
anything_copied = 1;
|
||||||
|
@ -1103,8 +1103,8 @@ cleanup:
|
||||||
int dc_create_folder(const char* pathNfilename, dc_context_t* log)
|
int dc_create_folder(const char* pathNfilename, dc_context_t* log)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (stat(pathNfilename, &st) == -1) {
|
if (stat(pathNfilename, &st)==-1) {
|
||||||
if (mkdir(pathNfilename, 0755) != 0) {
|
if (mkdir(pathNfilename, 0755)!=0) {
|
||||||
dc_log_warning(log, 0, "Cannot create directory \"%s\".", pathNfilename);
|
dc_log_warning(log, 0, "Cannot create directory \"%s\".", pathNfilename);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1187,7 +1187,7 @@ char* dc_get_fine_pathNfilename(const char* folder, const char* desired_filename
|
||||||
else {
|
else {
|
||||||
ret = dc_mprintf("%s/%s%s", folder, basename, dotNSuffix);
|
ret = dc_mprintf("%s/%s%s", folder, basename, dotNSuffix);
|
||||||
}
|
}
|
||||||
if (stat(ret, &st) == -1) {
|
if (stat(ret, &st)==-1) {
|
||||||
goto cleanup; /* fine filename found */
|
goto cleanup; /* fine filename found */
|
||||||
}
|
}
|
||||||
free(ret); /* try over with the next index */
|
free(ret); /* try over with the next index */
|
||||||
|
@ -1208,7 +1208,7 @@ int dc_write_file(const char* pathNfilename, const void* buf, size_t buf_bytes,
|
||||||
|
|
||||||
FILE* f = fopen(pathNfilename, "wb");
|
FILE* f = fopen(pathNfilename, "wb");
|
||||||
if (f) {
|
if (f) {
|
||||||
if (fwrite(buf, 1, buf_bytes, f) == buf_bytes) {
|
if (fwrite(buf, 1, buf_bytes, f)==buf_bytes) {
|
||||||
success = 1;
|
success = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1240,7 +1240,7 @@ int dc_read_file(const char* pathNfilename, void** buf, size_t* buf_bytes, dc_co
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
*buf_bytes = ftell(f);
|
*buf_bytes = ftell(f);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
if (*buf_bytes <= 0) { goto cleanup; }
|
if (*buf_bytes<=0) { goto cleanup; }
|
||||||
|
|
||||||
*buf = malloc( (*buf_bytes) + 1 /*be pragmatic and terminate all files by a null - fine for texts and does not hurt for the rest */);
|
*buf = malloc( (*buf_bytes) + 1 /*be pragmatic and terminate all files by a null - fine for texts and does not hurt for the rest */);
|
||||||
if (*buf==NULL) { goto cleanup; }
|
if (*buf==NULL) { goto cleanup; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue