Only reset status to "" if a text/plain part without signature is received

Otherwise sending a message without plaintext part
resets the signature. It is particularly dangerous
in multidevice case, because it's easy to accidentally
reset the signature on your other device with a non-text message.
This commit is contained in:
link2xt
2022-10-24 23:04:03 +00:00
parent 4aae48b0a1
commit 3c774b02e5
3 changed files with 25 additions and 21 deletions

View File

@@ -31,6 +31,7 @@
- Show a warning if quota list is empty #4261 - Show a warning if quota list is empty #4261
- Update "accounts.toml" atomically - Update "accounts.toml" atomically
- Don't let blocking be bypassed using groups #4316 - Don't let blocking be bypassed using groups #4316
- Do not reset status on other devices when sending signed reaction messages #3692
## [1.112.7] - 2023-04-17 ## [1.112.7] - 2023-04-17

View File

@@ -90,6 +90,9 @@ pub(crate) struct MimeMessage {
pub(crate) delivery_report: Option<DeliveryReport>, pub(crate) delivery_report: Option<DeliveryReport>,
/// Standard USENET signature, if any. /// Standard USENET signature, if any.
///
/// `None` means no text part was received, empty string means a text part without a footer is
/// received.
pub(crate) footer: Option<String>, pub(crate) footer: Option<String>,
// if this flag is set, the parts/text/etc. are just close to the original mime-message; // if this flag is set, the parts/text/etc. are just close to the original mime-message;
@@ -1059,6 +1062,7 @@ impl MimeMessage {
} }
}; };
let is_plaintext = mime_type == mime::TEXT_PLAIN;
let mut dehtml_failed = false; let mut dehtml_failed = false;
let SimplifiedText { let SimplifiedText {
@@ -1139,7 +1143,9 @@ impl MimeMessage {
self.is_forwarded = true; self.is_forwarded = true;
} }
self.footer = footer; if self.footer.is_none() && is_plaintext {
self.footer = Some(footer.unwrap_or_default());
}
} }
_ => {} _ => {}
} }

View File

@@ -309,13 +309,9 @@ pub(crate) async fn receive_imf_inner(
} }
} }
// Always update the status, even if there is no footer, to allow removing the status.
//
// Ignore MDNs though, as they never contain the signature even if user has set it.
// Ignore footers from mailinglists as they are often created or modified by the mailinglist software. // Ignore footers from mailinglists as they are often created or modified by the mailinglist software.
if mime_parser.mdn_reports.is_empty() if let Some(footer) = &mime_parser.footer {
&& !mime_parser.is_mailinglist_message() if !mime_parser.is_mailinglist_message()
&& is_partial_download.is_none()
&& from_id != ContactId::UNDEFINED && from_id != ContactId::UNDEFINED
&& context && context
.update_contacts_timestamp(from_id, Param::StatusTimestamp, sent_timestamp) .update_contacts_timestamp(from_id, Param::StatusTimestamp, sent_timestamp)
@@ -324,7 +320,7 @@ pub(crate) async fn receive_imf_inner(
if let Err(err) = contact::set_status( if let Err(err) = contact::set_status(
context, context,
from_id, from_id,
mime_parser.footer.clone().unwrap_or_default(), footer.to_string(),
mime_parser.was_encrypted(), mime_parser.was_encrypted(),
mime_parser.has_chat_version(), mime_parser.has_chat_version(),
) )
@@ -333,6 +329,7 @@ pub(crate) async fn receive_imf_inner(
warn!(context, "Cannot update contact status: {err:#}."); warn!(context, "Cannot update contact status: {err:#}.");
} }
} }
}
// Get user-configured server deletion // Get user-configured server deletion
let delete_server_after = context.get_config_delete_server_after().await?; let delete_server_after = context.get_config_delete_server_after().await?;