mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-06 03:50:08 +02:00
respect show_emails settings in receive_imf()
This commit is contained in:
parent
6887499efc
commit
b50cd54121
1 changed files with 54 additions and 14 deletions
|
@ -476,7 +476,8 @@ cleanup:
|
|||
******************************************************************************/
|
||||
|
||||
|
||||
static void create_or_lookup_adhoc_group(dc_context_t* context, dc_mimeparser_t* mime_parser, int create_blocked,
|
||||
static void create_or_lookup_adhoc_group(dc_context_t* context, dc_mimeparser_t* mime_parser,
|
||||
int allow_creation, int create_blocked,
|
||||
int32_t from_id, const dc_array_t* to_ids,/*does not contain SELF*/
|
||||
uint32_t* ret_chat_id, int* ret_chat_id_blocked)
|
||||
{
|
||||
|
@ -523,6 +524,10 @@ static void create_or_lookup_adhoc_group(dc_context_t* context, dc_mimeparser_t*
|
|||
}
|
||||
}
|
||||
|
||||
if (!allow_creation) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* we do not check if the message is a reply to another group, this may result in
|
||||
chats with unclear member list. instead we create a new group in the following lines ... */
|
||||
|
||||
|
@ -674,7 +679,8 @@ which tries to create or find out the chat_id by:
|
|||
|
||||
So when the function returns, the caller has the group id matching the current
|
||||
state of the group. */
|
||||
static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_parser, int create_blocked,
|
||||
static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_parser,
|
||||
int allow_creation, int create_blocked,
|
||||
int32_t from_id, const dc_array_t* to_ids,
|
||||
uint32_t* ret_chat_id, int* ret_chat_id_blocked)
|
||||
{
|
||||
|
@ -734,7 +740,9 @@ static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_
|
|||
|
||||
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,
|
||||
allow_creation, create_blocked,
|
||||
from_id, to_ids, &chat_id, &chat_id_blocked);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
@ -825,6 +833,10 @@ static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_
|
|||
}
|
||||
}
|
||||
|
||||
if (!allow_creation) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
chat_id = create_group_record(context, grpid, grpname, create_blocked, create_verified);
|
||||
chat_id_blocked = create_blocked;
|
||||
chat_id_verified = create_verified;
|
||||
|
@ -838,7 +850,9 @@ static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_
|
|||
chat_id = DC_CHAT_ID_TRASH; /* we got a message for a chat we've deleted - do not show this even as a normal chat */
|
||||
}
|
||||
else {
|
||||
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,
|
||||
allow_creation, create_blocked,
|
||||
from_id, to_ids, &chat_id, &chat_id_blocked);
|
||||
}
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -936,7 +950,8 @@ static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_
|
|||
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. */) {
|
||||
chat_id = 0;
|
||||
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,
|
||||
allow_creation, create_blocked, from_id, to_ids, &chat_id, &chat_id_blocked);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
@ -975,6 +990,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
|||
int chat_id_blocked = 0;
|
||||
int state = DC_STATE_UNDEFINED;
|
||||
int hidden = 0;
|
||||
int msgrmsg = 0;
|
||||
int add_delete_job = 0;
|
||||
uint32_t insert_msg_id = 0;
|
||||
|
||||
|
@ -1142,6 +1158,11 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
|||
}
|
||||
}
|
||||
|
||||
msgrmsg = mime_parser->is_send_by_messenger; /* 1 or 0 for yes/no */
|
||||
if (msgrmsg==0 && dc_is_reply_to_messenger_message(context, mime_parser)) {
|
||||
msgrmsg = 2; /* 2=no, but is reply to messenger message */
|
||||
}
|
||||
|
||||
/* check if the message introduces a new chat:
|
||||
- outgoing messages introduce a chat with the first to: address if they are sent by a messenger
|
||||
- incoming messages introduce a chat only for known contacts if they are sent by a messenger
|
||||
|
@ -1154,6 +1175,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
|||
// handshake messages must be processed before chats are created (eg. contacs may be marked as verified)
|
||||
assert( chat_id==0);
|
||||
if (dc_mimeparser_lookup_field(mime_parser, "Secure-Join")) {
|
||||
msgrmsg = 1; // avoid discarding by show_emails setting
|
||||
dc_sqlite3_commit(context->sql);
|
||||
int handshake = dc_handle_securejoin_handshake(context, mime_parser, from_id);
|
||||
if (handshake & DC_HANDSHAKE_STOP_NORMAL_PROCESSING) {
|
||||
|
@ -1164,6 +1186,25 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
|||
dc_sqlite3_begin_transaction(context->sql);
|
||||
}
|
||||
|
||||
/* incoming non-chat messages may be discarded;
|
||||
maybe this can be optimized later,
|
||||
by checking the state before the message body is downloaded */
|
||||
int allow_creation = 1;
|
||||
if (msgrmsg==0) {
|
||||
/* this message is a classic email -
|
||||
not a chat-message nor a reply to one */
|
||||
int show_emails = dc_sqlite3_get_config_int(context->sql,
|
||||
"show_emails", DC_SHOW_EMAILS_DEFAULT);
|
||||
|
||||
if (show_emails==DC_SHOW_EMAILS_OFF) {
|
||||
chat_id = DC_CHAT_ID_TRASH;
|
||||
allow_creation = 0;
|
||||
}
|
||||
else if (show_emails==DC_SHOW_EMAILS_ACCEPTED_CONTACTS) {
|
||||
allow_creation = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* test if there is a normal chat with the sender - if so, this allows us to create groups in the next step */
|
||||
uint32_t test_normal_chat_id = 0;
|
||||
int test_normal_chat_id_blocked = 0;
|
||||
|
@ -1176,7 +1217,9 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
|||
/* try to create a group
|
||||
(groups appear automatically only if the _sender_ is known, see core issue #54) */
|
||||
int create_blocked = ((test_normal_chat_id&&test_normal_chat_id_blocked==DC_CHAT_NOT_BLOCKED) || incoming_origin>=DC_ORIGIN_MIN_START_NEW_NCHAT/*always false, for now*/)? DC_CHAT_NOT_BLOCKED : DC_CHAT_DEADDROP_BLOCKED;
|
||||
create_or_lookup_group(context, mime_parser, create_blocked, from_id, to_ids, &chat_id, &chat_id_blocked);
|
||||
create_or_lookup_group(context, mime_parser,
|
||||
allow_creation, create_blocked,
|
||||
from_id, to_ids, &chat_id, &chat_id_blocked);
|
||||
if (chat_id && chat_id_blocked && !create_blocked) {
|
||||
dc_unblock_chat(context, chat_id);
|
||||
chat_id_blocked = 0;
|
||||
|
@ -1200,8 +1243,10 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
|||
chat_id = test_normal_chat_id;
|
||||
chat_id_blocked = test_normal_chat_id_blocked;
|
||||
}
|
||||
else {
|
||||
dc_create_or_lookup_nchat_by_contact_id(context, from_id, create_blocked, &chat_id, &chat_id_blocked);
|
||||
else if(allow_creation) {
|
||||
dc_create_or_lookup_nchat_by_contact_id(context, from_id,
|
||||
create_blocked,
|
||||
&chat_id, &chat_id_blocked);
|
||||
}
|
||||
|
||||
if (chat_id && chat_id_blocked) {
|
||||
|
@ -1245,7 +1290,7 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
|||
|
||||
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, 1, DC_CHAT_NOT_BLOCKED, from_id, to_ids, &chat_id, &chat_id_blocked);
|
||||
if (chat_id && chat_id_blocked) {
|
||||
dc_unblock_chat(context, chat_id);
|
||||
chat_id_blocked = 0;
|
||||
|
@ -1319,11 +1364,6 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
|||
}
|
||||
}
|
||||
|
||||
int msgrmsg = mime_parser->is_send_by_messenger; /* 1 or 0 for yes/no */
|
||||
if (msgrmsg==0 && dc_is_reply_to_messenger_message(context, mime_parser)) {
|
||||
msgrmsg = 2; /* 2=no, but is reply to messenger message */
|
||||
}
|
||||
|
||||
/* fine, so far. now, split the message into simple parts usable as "short messages"
|
||||
and add them to the database (mails sent by other messenger clients should result
|
||||
into only one message; mails sent by other clients may result in several messages (eg. one per attachment)) */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue