diff --git a/node/test/test.js b/node/test/test.js index 2c7912584..a8f72aa9f 100644 --- a/node/test/test.js +++ b/node/test/test.js @@ -270,7 +270,7 @@ describe('Basic offline Tests', function () { 'quota_exceeding', 'scan_all_folders_debounce_secs', 'selfavatar', - 'send_sync_msgs', + 'sync_msgs', 'sentbox_watch', 'show_emails', 'socks5_enabled', diff --git a/src/config.rs b/src/config.rs index a5704dd83..8611778fa 100644 --- a/src/config.rs +++ b/src/config.rs @@ -297,10 +297,9 @@ pub enum Config { #[strum(props(default = "0"))] DownloadLimit, - /// Send sync messages, requires `BccSelf` to be set as well. - /// In a future versions, this switch may be removed. + /// Enable sending and executing (applying) sync messages. Sending requires `BccSelf` to be set. #[strum(props(default = "0"))] - SendSyncMsgs, + SyncMsgs, /// Space-separated list of all the authserv-ids which we believe /// may be the one of our email server. @@ -491,7 +490,7 @@ impl Context { | Config::Configured | Config::Bot | Config::NotifyAboutWrongPw - | Config::SendSyncMsgs + | Config::SyncMsgs | Config::SignUnencrypted | Config::DisableIdle => { ensure!( diff --git a/src/context.rs b/src/context.rs index 88229004c..3fd97a2ad 100644 --- a/src/context.rs +++ b/src/context.rs @@ -584,7 +584,7 @@ impl Context { let e2ee_enabled = self.get_config_int(Config::E2eeEnabled).await?; let mdns_enabled = self.get_config_int(Config::MdnsEnabled).await?; let bcc_self = self.get_config_int(Config::BccSelf).await?; - let send_sync_msgs = self.get_config_int(Config::SendSyncMsgs).await?; + let sync_msgs = self.get_config_int(Config::SyncMsgs).await?; let disable_idle = self.get_config_bool(Config::DisableIdle).await?; let prv_key_cnt = self.sql.count("SELECT COUNT(*) FROM keypairs;", ()).await?; @@ -697,7 +697,7 @@ impl Context { self.get_config_int(Config::KeyGenType).await?.to_string(), ); res.insert("bcc_self", bcc_self.to_string()); - res.insert("send_sync_msgs", send_sync_msgs.to_string()); + res.insert("sync_msgs", sync_msgs.to_string()); res.insert("disable_idle", disable_idle.to_string()); res.insert("private_key_count", prv_key_cnt.to_string()); res.insert("public_key_count", pub_key_cnt.to_string()); diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 21207a86a..cda1b00cd 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -1208,6 +1208,9 @@ impl MimeMessage { } msg_type } else if filename == "multi-device-sync.json" { + if !context.get_config_bool(Config::SyncMsgs).await? { + return Ok(()); + } let serialized = String::from_utf8_lossy(decoded_data) .parse() .unwrap_or_default(); diff --git a/src/sync.rs b/src/sync.rs index 5b732df8e..61972bcb3 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -43,13 +43,6 @@ pub(crate) struct SyncItems { } impl Context { - /// Checks if sync messages shall be sent. - /// Receiving sync messages is currently always enabled; - /// the messages are force-encrypted anyway. - async fn is_sync_sending_enabled(&self) -> Result { - self.get_config_bool(Config::SendSyncMsgs).await - } - /// Adds an item to the list of items that should be synchronized to other devices. pub(crate) async fn add_sync_item(&self, data: SyncData) -> Result<()> { self.add_sync_item_with_timestamp(data, time()).await @@ -58,7 +51,7 @@ impl Context { /// Adds item and timestamp to the list of items that should be synchronized to other devices. /// If device synchronization is disabled, the function does nothing. async fn add_sync_item_with_timestamp(&self, data: SyncData, timestamp: i64) -> Result<()> { - if !self.is_sync_sending_enabled().await? { + if !self.get_config_bool(Config::SyncMsgs).await? { return Ok(()); } @@ -75,7 +68,7 @@ impl Context { /// If device synchronization is disabled, /// no tokens exist or the chat is unpromoted, the function does nothing. pub(crate) async fn sync_qr_code_tokens(&self, chat_id: Option) -> Result<()> { - if !self.is_sync_sending_enabled().await? { + if !self.get_config_bool(Config::SyncMsgs).await? { return Ok(()); } @@ -267,20 +260,20 @@ mod tests { use crate::token::Namespace; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] - async fn test_is_sync_sending_enabled() -> Result<()> { + async fn test_config_sync_msgs() -> Result<()> { let t = TestContext::new_alice().await; - assert!(!t.is_sync_sending_enabled().await?); - t.set_config_bool(Config::SendSyncMsgs, true).await?; - assert!(t.is_sync_sending_enabled().await?); - t.set_config_bool(Config::SendSyncMsgs, false).await?; - assert!(!t.is_sync_sending_enabled().await?); + assert!(!t.get_config_bool(Config::SyncMsgs).await?); + t.set_config_bool(Config::SyncMsgs, true).await?; + assert!(t.get_config_bool(Config::SyncMsgs).await?); + t.set_config_bool(Config::SyncMsgs, false).await?; + assert!(!t.get_config_bool(Config::SyncMsgs).await?); Ok(()) } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_build_sync_json() -> Result<()> { let t = TestContext::new_alice().await; - t.set_config_bool(Config::SendSyncMsgs, true).await?; + t.set_config_bool(Config::SyncMsgs, true).await?; assert!(t.build_sync_json().await?.is_none()); @@ -325,7 +318,7 @@ mod tests { #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_build_sync_json_sync_msgs_off() -> Result<()> { let t = TestContext::new_alice().await; - t.set_config_bool(Config::SendSyncMsgs, false).await?; + t.set_config_bool(Config::SyncMsgs, false).await?; t.add_sync_item(SyncData::AddQrToken(QrTokenData { invitenumber: "testinvite".to_string(), auth: "testauth".to_string(), @@ -453,7 +446,7 @@ mod tests { #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_send_sync_msg() -> Result<()> { let alice = TestContext::new_alice().await; - alice.set_config_bool(Config::SendSyncMsgs, true).await?; + alice.set_config_bool(Config::SyncMsgs, true).await?; alice .add_sync_item(SyncData::AddQrToken(QrTokenData { invitenumber: "in".to_string(), @@ -480,6 +473,7 @@ mod tests { // also here, self-talk should stay hidden let sent_msg = alice.pop_sent_msg().await; let alice2 = TestContext::new_alice().await; + alice2.set_config_bool(Config::SyncMsgs, true).await?; alice2.recv_msg(&sent_msg).await; assert!(token::exists(&alice2, token::Namespace::Auth, "testtoken").await); assert_eq!(Chatlist::try_load(&alice2, 0, None, None).await?.len(), 0);