Skip to content

Commit 36f868e

Browse files
committed
fix: always set bcc_self on backup import/export
Regardless of whether chatmail relay is used or not, bcc_self should be enabled when second device is added. It should also be enabled again even if the user has turned it off manually.
1 parent dc4ea18 commit 36f868e

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

deltachat-rpc-client/tests/test_multidevice.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,41 @@
44
from deltachat_rpc_client.const import MessageState
55

66

7+
def test_bcc_self_delete_server_after_defaults(acfactory):
8+
"""Test default values for bcc_self and delete_server_after."""
9+
ac = acfactory.get_online_account()
10+
11+
# Initially after getting online
12+
# the setting bcc_self is set to 0 because there is only one device
13+
# and delete_server_after is "1", meaning immediate deletion.
14+
assert ac.get_config("bcc_self") == "0"
15+
assert ac.get_config("delete_server_after") == "1"
16+
17+
# Setup a second device.
18+
ac_clone = ac.clone()
19+
ac_clone.bring_online()
20+
21+
# Second device setup
22+
# enables bcc_self and changes default delete_server_after.
23+
assert ac.get_config("bcc_self") == "1"
24+
assert ac.get_config("delete_server_after") == "0"
25+
26+
assert ac_clone.get_config("bcc_self") == "1"
27+
assert ac_clone.get_config("delete_server_after") == "0"
28+
29+
# Manually disabling bcc_self
30+
# also restores the default for delete_server_after.
31+
ac.set_config("bcc_self", "0")
32+
assert ac.get_config("bcc_self") == "0"
33+
assert ac.get_config("delete_server_after") == "1"
34+
35+
# Cloning the account again enables bcc_self
36+
# even though it was manually disabled.
37+
ac_clone = ac.clone()
38+
assert ac.get_config("bcc_self") == "1"
39+
assert ac.get_config("delete_server_after") == "0"
40+
41+
742
def test_one_account_send_bcc_setting(acfactory, log, direct_imap):
843
ac1, ac2 = acfactory.get_online_accounts(2)
944
ac1_clone = ac1.clone()

src/imex.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,15 @@ async fn import_backup_stream_inner<R: tokio::io::AsyncRead + Unpin>(
377377
res = check_backup_version(context).await;
378378
}
379379
if res.is_ok() {
380-
res = adjust_bcc_self(context).await;
380+
// All recent backups have `bcc_self` set to "1" before export.
381+
//
382+
// Setting `bcc_self` to "1" on export was introduced on 2024-12-17
383+
// in commit 21664125d798021be75f47d5b0d5006d338b4531
384+
//
385+
// We additionally try to set `bcc_self` to "1" after import here
386+
// for compatibility with older backups,
387+
// but eventually this code can be removed.
388+
res = context.set_config(Config::BccSelf, Some("1")).await;
381389
}
382390
fs::remove_file(unpacked_database)
383391
.await
@@ -751,7 +759,7 @@ async fn export_database(
751759
.to_str()
752760
.with_context(|| format!("path {} is not valid unicode", dest.display()))?;
753761

754-
adjust_bcc_self(context).await?;
762+
context.set_config(Config::BccSelf, Some("1")).await?;
755763
context
756764
.sql
757765
.set_raw_config_int("backup_time", timestamp)
@@ -785,18 +793,6 @@ async fn export_database(
785793
.await
786794
}
787795

788-
/// Sets `Config::BccSelf` (and `DeleteServerAfter` to "never" in effect) if needed so that new
789-
/// messages are present on the server after a backup restoration or available for all devices in
790-
/// multi-device case. NB: Calling this after a backup import isn't reliable as we can crash in
791-
/// between, but this is a problem only for old backups, new backups already have `BccSelf` set if
792-
/// necessary.
793-
async fn adjust_bcc_self(context: &Context) -> Result<()> {
794-
if context.is_chatmail().await? && !context.config_exists(Config::BccSelf).await? {
795-
context.set_config(Config::BccSelf, Some("1")).await?;
796-
}
797-
Ok(())
798-
}
799-
800796
async fn check_backup_version(context: &Context) -> Result<()> {
801797
let version = (context.sql.get_raw_config_int("backup_version").await?).unwrap_or(2);
802798
ensure!(

0 commit comments

Comments
 (0)