mirror of
https://github.com/chatmail/core.git
synced 2026-05-17 05:46:30 +03:00
dc_receive_imf: return ChatId from add_parts()
This commit is contained in:
@@ -120,7 +120,6 @@ pub(crate) async fn dc_receive_imf_inner(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the function returns the number of created messages in the database
|
// the function returns the number of created messages in the database
|
||||||
let mut chat_id = ChatId::new(0);
|
|
||||||
let mut hidden = false;
|
let mut hidden = false;
|
||||||
|
|
||||||
let mut needs_delete_job = false;
|
let mut needs_delete_job = false;
|
||||||
@@ -164,7 +163,7 @@ pub(crate) async fn dc_receive_imf_inner(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Add parts
|
// Add parts
|
||||||
add_parts(
|
let chat_id = add_parts(
|
||||||
context,
|
context,
|
||||||
&mut mime_parser,
|
&mut mime_parser,
|
||||||
imf_raw,
|
imf_raw,
|
||||||
@@ -177,7 +176,6 @@ pub(crate) async fn dc_receive_imf_inner(
|
|||||||
&mut sent_timestamp,
|
&mut sent_timestamp,
|
||||||
from_id,
|
from_id,
|
||||||
&mut hidden,
|
&mut hidden,
|
||||||
&mut chat_id,
|
|
||||||
seen,
|
seen,
|
||||||
&mut needs_delete_job,
|
&mut needs_delete_job,
|
||||||
&mut insert_msg_id,
|
&mut insert_msg_id,
|
||||||
@@ -362,7 +360,6 @@ async fn add_parts(
|
|||||||
sent_timestamp: &mut i64,
|
sent_timestamp: &mut i64,
|
||||||
from_id: u32,
|
from_id: u32,
|
||||||
hidden: &mut bool,
|
hidden: &mut bool,
|
||||||
chat_id: &mut ChatId,
|
|
||||||
seen: bool,
|
seen: bool,
|
||||||
needs_delete_job: &mut bool,
|
needs_delete_job: &mut bool,
|
||||||
insert_msg_id: &mut MsgId,
|
insert_msg_id: &mut MsgId,
|
||||||
@@ -370,8 +367,9 @@ async fn add_parts(
|
|||||||
create_event_to_send: &mut Option<CreateEvent>,
|
create_event_to_send: &mut Option<CreateEvent>,
|
||||||
fetching_existing_messages: bool,
|
fetching_existing_messages: bool,
|
||||||
prevent_rename: bool,
|
prevent_rename: bool,
|
||||||
) -> Result<()> {
|
) -> Result<ChatId> {
|
||||||
let mut state: MessageState;
|
let mut state: MessageState;
|
||||||
|
let mut chat_id = ChatId::new(0);
|
||||||
let mut chat_id_blocked = Blocked::Not;
|
let mut chat_id_blocked = Blocked::Not;
|
||||||
let mut mime_in_reply_to = String::new();
|
let mut mime_in_reply_to = String::new();
|
||||||
let mut mime_references = String::new();
|
let mut mime_references = String::new();
|
||||||
@@ -400,7 +398,7 @@ async fn add_parts(
|
|||||||
match show_emails {
|
match show_emails {
|
||||||
ShowEmails::Off => {
|
ShowEmails::Off => {
|
||||||
info!(context, "Classical email not shown (TRASH)");
|
info!(context, "Classical email not shown (TRASH)");
|
||||||
*chat_id = DC_CHAT_ID_TRASH;
|
chat_id = DC_CHAT_ID_TRASH;
|
||||||
allow_creation = false;
|
allow_creation = false;
|
||||||
}
|
}
|
||||||
ShowEmails::AcceptedContacts => allow_creation = false,
|
ShowEmails::AcceptedContacts => allow_creation = false,
|
||||||
@@ -425,7 +423,7 @@ async fn add_parts(
|
|||||||
// handshake may mark contacts as verified and must be processed before chats are created
|
// handshake may mark contacts as verified and must be processed before chats are created
|
||||||
if mime_parser.get(HeaderDef::SecureJoin).is_some() {
|
if mime_parser.get(HeaderDef::SecureJoin).is_some() {
|
||||||
is_dc_message = MessengerMessage::Yes; // avoid discarding by show_emails setting
|
is_dc_message = MessengerMessage::Yes; // avoid discarding by show_emails setting
|
||||||
*chat_id = ChatId::new(0);
|
chat_id = ChatId::new(0);
|
||||||
allow_creation = true;
|
allow_creation = true;
|
||||||
match handle_securejoin_handshake(context, mime_parser, from_id).await {
|
match handle_securejoin_handshake(context, mime_parser, from_id).await {
|
||||||
Ok(securejoin::HandshakeMessage::Done) => {
|
Ok(securejoin::HandshakeMessage::Done) => {
|
||||||
@@ -443,7 +441,7 @@ async fn add_parts(
|
|||||||
Err(err) => {
|
Err(err) => {
|
||||||
*hidden = true;
|
*hidden = true;
|
||||||
warn!(context, "Error in Secure-Join message handling: {}", err);
|
warn!(context, "Error in Secure-Join message handling: {}", err);
|
||||||
return Ok(());
|
return Ok(chat_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -453,7 +451,7 @@ async fn add_parts(
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
if chat_id.is_unset() && mime_parser.failure_report.is_some() {
|
if chat_id.is_unset() && mime_parser.failure_report.is_some() {
|
||||||
*chat_id = DC_CHAT_ID_TRASH;
|
chat_id = DC_CHAT_ID_TRASH;
|
||||||
info!(context, "Message belongs to an NDN (TRASH)",);
|
info!(context, "Message belongs to an NDN (TRASH)",);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,7 +460,7 @@ async fn add_parts(
|
|||||||
|
|
||||||
let (new_chat_id, new_chat_id_blocked) =
|
let (new_chat_id, new_chat_id_blocked) =
|
||||||
lookup_chat_by_reply(context, &mime_parser, &parent, from_id, to_ids).await?;
|
lookup_chat_by_reply(context, &mime_parser, &parent, from_id, to_ids).await?;
|
||||||
*chat_id = new_chat_id;
|
chat_id = new_chat_id;
|
||||||
chat_id_blocked = new_chat_id_blocked;
|
chat_id_blocked = new_chat_id_blocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -490,7 +488,7 @@ async fn add_parts(
|
|||||||
to_ids,
|
to_ids,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
*chat_id = new_chat_id;
|
chat_id = new_chat_id;
|
||||||
chat_id_blocked = new_chat_id_blocked;
|
chat_id_blocked = new_chat_id_blocked;
|
||||||
if !chat_id.is_unset()
|
if !chat_id.is_unset()
|
||||||
&& chat_id_blocked != Blocked::Not
|
&& chat_id_blocked != Blocked::Not
|
||||||
@@ -503,9 +501,9 @@ async fn add_parts(
|
|||||||
|
|
||||||
// In lookup_chat_by_reply() and create_or_lookup_group(), it can happen that the message is put into a chat
|
// In lookup_chat_by_reply() and create_or_lookup_group(), it can happen that the message is put into a chat
|
||||||
// but the From-address is not a member of this chat.
|
// but the From-address is not a member of this chat.
|
||||||
if !chat_id.is_unset() && !chat::is_contact_in_chat(context, *chat_id, from_id as u32).await
|
if !chat_id.is_unset() && !chat::is_contact_in_chat(context, chat_id, from_id as u32).await
|
||||||
{
|
{
|
||||||
let chat = Chat::load_from_db(context, *chat_id).await?;
|
let chat = Chat::load_from_db(context, chat_id).await?;
|
||||||
if chat.is_protected() {
|
if chat.is_protected() {
|
||||||
let s = stock_str::unknown_sender_for_chat(context).await;
|
let s = stock_str::unknown_sender_for_chat(context).await;
|
||||||
mime_parser.repl_msg_by_error(s);
|
mime_parser.repl_msg_by_error(s);
|
||||||
@@ -531,7 +529,7 @@ async fn add_parts(
|
|||||||
mime_parser,
|
mime_parser,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
*chat_id = new_chat_id;
|
chat_id = new_chat_id;
|
||||||
chat_id_blocked = new_chat_id_blocked;
|
chat_id_blocked = new_chat_id_blocked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -544,7 +542,7 @@ async fn add_parts(
|
|||||||
mime_parser,
|
mime_parser,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
*chat_id = new_chat_id;
|
chat_id = new_chat_id;
|
||||||
chat_id_blocked = new_chat_id_blocked;
|
chat_id_blocked = new_chat_id_blocked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -573,14 +571,14 @@ async fn add_parts(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(chat) = test_normal_chat {
|
if let Some(chat) = test_normal_chat {
|
||||||
*chat_id = chat.id;
|
chat_id = chat.id;
|
||||||
chat_id_blocked = chat.blocked;
|
chat_id_blocked = chat.blocked;
|
||||||
} else if allow_creation {
|
} else if allow_creation {
|
||||||
if let Ok(chat) = ChatIdBlocked::get_for_contact(context, from_id, create_blocked)
|
if let Ok(chat) = ChatIdBlocked::get_for_contact(context, from_id, create_blocked)
|
||||||
.await
|
.await
|
||||||
.log_err(context, "Failed to get (new) chat for contact")
|
.log_err(context, "Failed to get (new) chat for contact")
|
||||||
{
|
{
|
||||||
*chat_id = chat.id;
|
chat_id = chat.id;
|
||||||
chat_id_blocked = chat.blocked;
|
chat_id_blocked = chat.blocked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -604,7 +602,7 @@ async fn add_parts(
|
|||||||
}
|
}
|
||||||
if chat_id.is_unset() {
|
if chat_id.is_unset() {
|
||||||
// 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;
|
||||||
info!(context, "No chat id for incoming msg (TRASH)")
|
info!(context, "No chat id for incoming msg (TRASH)")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -629,7 +627,7 @@ async fn add_parts(
|
|||||||
&& (is_dc_message == MessengerMessage::No)
|
&& (is_dc_message == MessengerMessage::No)
|
||||||
&& context.is_spam_folder(server_folder).await?;
|
&& context.is_spam_folder(server_folder).await?;
|
||||||
if is_spam {
|
if is_spam {
|
||||||
*chat_id = DC_CHAT_ID_TRASH;
|
chat_id = DC_CHAT_ID_TRASH;
|
||||||
info!(context, "Message is probably spam (TRASH)");
|
info!(context, "Message is probably spam (TRASH)");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -643,7 +641,7 @@ async fn add_parts(
|
|||||||
// handshake may mark contacts as verified and must be processed before chats are created
|
// handshake may mark contacts as verified and must be processed before chats are created
|
||||||
if mime_parser.get(HeaderDef::SecureJoin).is_some() {
|
if mime_parser.get(HeaderDef::SecureJoin).is_some() {
|
||||||
is_dc_message = MessengerMessage::Yes; // avoid discarding by show_emails setting
|
is_dc_message = MessengerMessage::Yes; // avoid discarding by show_emails setting
|
||||||
*chat_id = ChatId::new(0);
|
chat_id = ChatId::new(0);
|
||||||
allow_creation = true;
|
allow_creation = true;
|
||||||
match observe_securejoin_on_other_device(context, mime_parser, to_id).await {
|
match observe_securejoin_on_other_device(context, mime_parser, to_id).await {
|
||||||
Ok(securejoin::HandshakeMessage::Done)
|
Ok(securejoin::HandshakeMessage::Done)
|
||||||
@@ -656,7 +654,7 @@ async fn add_parts(
|
|||||||
Err(err) => {
|
Err(err) => {
|
||||||
*hidden = true;
|
*hidden = true;
|
||||||
warn!(context, "Error in Secure-Join watching: {}", err);
|
warn!(context, "Error in Secure-Join watching: {}", err);
|
||||||
return Ok(());
|
return Ok(chat_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -682,7 +680,7 @@ async fn add_parts(
|
|||||||
if is_draft {
|
if is_draft {
|
||||||
// Most mailboxes have a "Drafts" folder where constantly new emails appear but we don't actually want to show them
|
// Most mailboxes have a "Drafts" folder where constantly new emails appear but we don't actually want to show them
|
||||||
info!(context, "Email is probably just a draft (TRASH)");
|
info!(context, "Email is probably just a draft (TRASH)");
|
||||||
*chat_id = DC_CHAT_ID_TRASH;
|
chat_id = DC_CHAT_ID_TRASH;
|
||||||
allow_creation = false;
|
allow_creation = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -691,7 +689,7 @@ async fn add_parts(
|
|||||||
|
|
||||||
let (new_chat_id, new_chat_id_blocked) =
|
let (new_chat_id, new_chat_id_blocked) =
|
||||||
lookup_chat_by_reply(context, &mime_parser, &parent, from_id, to_ids).await?;
|
lookup_chat_by_reply(context, &mime_parser, &parent, from_id, to_ids).await?;
|
||||||
*chat_id = new_chat_id;
|
chat_id = new_chat_id;
|
||||||
chat_id_blocked = new_chat_id_blocked;
|
chat_id_blocked = new_chat_id_blocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -706,7 +704,7 @@ async fn add_parts(
|
|||||||
to_ids,
|
to_ids,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
*chat_id = new_chat_id;
|
chat_id = new_chat_id;
|
||||||
chat_id_blocked = new_chat_id_blocked;
|
chat_id_blocked = new_chat_id_blocked;
|
||||||
// automatically unblock chat when the user sends a message
|
// automatically unblock chat when the user sends a message
|
||||||
if !chat_id.is_unset() && chat_id_blocked != Blocked::Not {
|
if !chat_id.is_unset() && chat_id_blocked != Blocked::Not {
|
||||||
@@ -723,7 +721,7 @@ async fn add_parts(
|
|||||||
if let Ok(chat) =
|
if let Ok(chat) =
|
||||||
ChatIdBlocked::get_for_contact(context, to_id, create_blocked).await
|
ChatIdBlocked::get_for_contact(context, to_id, create_blocked).await
|
||||||
{
|
{
|
||||||
*chat_id = chat.id;
|
chat_id = chat.id;
|
||||||
chat_id_blocked = chat.blocked;
|
chat_id_blocked = chat.blocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -748,7 +746,7 @@ async fn add_parts(
|
|||||||
.await
|
.await
|
||||||
.log_err(context, "Failed to get (new) chat for contact")
|
.log_err(context, "Failed to get (new) chat for contact")
|
||||||
{
|
{
|
||||||
*chat_id = chat.id;
|
chat_id = chat.id;
|
||||||
chat_id_blocked = chat.blocked;
|
chat_id_blocked = chat.blocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -758,13 +756,13 @@ async fn add_parts(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if chat_id.is_unset() {
|
if chat_id.is_unset() {
|
||||||
*chat_id = DC_CHAT_ID_TRASH;
|
chat_id = DC_CHAT_ID_TRASH;
|
||||||
info!(context, "No chat id for outgoing message (TRASH)")
|
info!(context, "No chat id for outgoing message (TRASH)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if fetching_existing_messages && mime_parser.decrypting_failed {
|
if fetching_existing_messages && mime_parser.decrypting_failed {
|
||||||
*chat_id = DC_CHAT_ID_TRASH;
|
chat_id = DC_CHAT_ID_TRASH;
|
||||||
// We are only gathering old messages on first start. We do not want to add loads of non-decryptable messages to the chats.
|
// We are only gathering old messages on first start. We do not want to add loads of non-decryptable messages to the chats.
|
||||||
info!(context, "Existing non-decipherable message. (TRASH)");
|
info!(context, "Existing non-decipherable message. (TRASH)");
|
||||||
}
|
}
|
||||||
@@ -800,9 +798,9 @@ async fn add_parts(
|
|||||||
&& (is_dc_message != MessengerMessage::Yes
|
&& (is_dc_message != MessengerMessage::Yes
|
||||||
|| parent.is_none()
|
|| parent.is_none()
|
||||||
|| parent.unwrap().ephemeral_timer != ephemeral_timer)
|
|| parent.unwrap().ephemeral_timer != ephemeral_timer)
|
||||||
&& (*chat_id).get_ephemeral_timer(context).await? != ephemeral_timer
|
&& chat_id.get_ephemeral_timer(context).await? != ephemeral_timer
|
||||||
{
|
{
|
||||||
if let Err(err) = (*chat_id)
|
if let Err(err) = chat_id
|
||||||
.inner_set_ephemeral_timer(context, ephemeral_timer)
|
.inner_set_ephemeral_timer(context, ephemeral_timer)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -813,7 +811,7 @@ async fn add_parts(
|
|||||||
} else if mime_parser.is_system_message != SystemMessage::EphemeralTimerChanged {
|
} else if mime_parser.is_system_message != SystemMessage::EphemeralTimerChanged {
|
||||||
chat::add_info_msg(
|
chat::add_info_msg(
|
||||||
context,
|
context,
|
||||||
*chat_id,
|
chat_id,
|
||||||
stock_ephemeral_timer_changed(context, ephemeral_timer, from_id).await,
|
stock_ephemeral_timer_changed(context, ephemeral_timer, from_id).await,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
@@ -837,7 +835,7 @@ async fn add_parts(
|
|||||||
|
|
||||||
// if a chat is protected, check additional properties
|
// if a chat is protected, check additional properties
|
||||||
if !chat_id.is_special() {
|
if !chat_id.is_special() {
|
||||||
let chat = Chat::load_from_db(context, *chat_id).await?;
|
let chat = Chat::load_from_db(context, chat_id).await?;
|
||||||
let new_status = match mime_parser.is_system_message {
|
let new_status = match mime_parser.is_system_message {
|
||||||
SystemMessage::ChatProtectionEnabled => Some(ProtectionStatus::Protected),
|
SystemMessage::ChatProtectionEnabled => Some(ProtectionStatus::Protected),
|
||||||
SystemMessage::ChatProtectionDisabled => Some(ProtectionStatus::Unprotected),
|
SystemMessage::ChatProtectionDisabled => Some(ProtectionStatus::Unprotected),
|
||||||
@@ -856,11 +854,11 @@ async fn add_parts(
|
|||||||
if let Err(e) = chat_id.inner_set_protection(context, new_status).await {
|
if let Err(e) = chat_id.inner_set_protection(context, new_status).await {
|
||||||
chat::add_info_msg(
|
chat::add_info_msg(
|
||||||
context,
|
context,
|
||||||
*chat_id,
|
chat_id,
|
||||||
format!("Cannot set protection: {}", e),
|
format!("Cannot set protection: {}", e),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
return Ok(()); // do not return an error as this would result in retrying the message
|
return Ok(chat_id); // do not return an error as this would result in retrying the message
|
||||||
}
|
}
|
||||||
set_better_msg(
|
set_better_msg(
|
||||||
mime_parser,
|
mime_parser,
|
||||||
@@ -877,7 +875,7 @@ async fn add_parts(
|
|||||||
// however, we cannot do this earlier as we need from_id to be set
|
// however, we cannot do this earlier as we need from_id to be set
|
||||||
let in_fresh = state == MessageState::InFresh;
|
let in_fresh = state == MessageState::InFresh;
|
||||||
let rcvd_timestamp = time();
|
let rcvd_timestamp = time();
|
||||||
let sort_timestamp = calc_sort_timestamp(context, *sent_timestamp, *chat_id, in_fresh).await?;
|
let sort_timestamp = calc_sort_timestamp(context, *sent_timestamp, chat_id, in_fresh).await?;
|
||||||
|
|
||||||
// Ensure replies to messages are sorted after the parent message.
|
// Ensure replies to messages are sorted after the parent message.
|
||||||
//
|
//
|
||||||
@@ -935,7 +933,7 @@ async fn add_parts(
|
|||||||
|
|
||||||
let sent_timestamp = *sent_timestamp;
|
let sent_timestamp = *sent_timestamp;
|
||||||
let is_hidden = *hidden;
|
let is_hidden = *hidden;
|
||||||
let chat_id = *chat_id;
|
let chat_id = chat_id;
|
||||||
|
|
||||||
// TODO: can this clone be avoided?
|
// TODO: can this clone be avoided?
|
||||||
let rfc724_mid = rfc724_mid.to_string();
|
let rfc724_mid = rfc724_mid.to_string();
|
||||||
@@ -1105,7 +1103,7 @@ INSERT INTO msgs
|
|||||||
.ok_or_log_msg(context, "Could not update LastSubject of chat");
|
.ok_or_log_msg(context, "Could not update LastSubject of chat");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(chat_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save_locations(
|
async fn save_locations(
|
||||||
|
|||||||
Reference in New Issue
Block a user