Skip to content

Commit 58cd133

Browse files
committed
fix: synchronize primary transport immediately after changing it
1 parent 3d234e7 commit 58cd133

File tree

2 files changed

+37
-31
lines changed

2 files changed

+37
-31
lines changed

deltachat-rpc-client/tests/test_multitransport.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ def test_transport_synchronization(acfactory, log) -> None:
188188
log.section("ac1 changes the primary transport")
189189
ac1.set_config("configured_addr", transport3["addr"])
190190

191+
ac1_clone.wait_for_event(EventType.TRANSPORTS_MODIFIED)
192+
[transport1, transport3] = ac1_clone.list_transports()
193+
assert ac1_clone.get_config("configured_addr") == addr3
194+
191195
log.section("ac1 removes the first transport")
192196
ac1.delete_transport(transport1["addr"])
193197

src/config.rs

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::mimefactory::RECOMMENDED_FILE_SIZE;
2020
use crate::provider::Provider;
2121
use crate::sync::{self, Sync::*, SyncData};
2222
use crate::tools::get_abs_path;
23-
use crate::transport::{ConfiguredLoginParam, add_pseudo_transport};
23+
use crate::transport::{ConfiguredLoginParam, add_pseudo_transport, send_sync_transports};
2424
use crate::{constants, stats};
2525

2626
/// The available configuration keys.
@@ -818,37 +818,39 @@ impl Context {
818818
self.sql
819819
.set_raw_config(Config::ConfiguredAddr.as_ref(), Some(addr))
820820
.await?;
821+
} else {
822+
self.sql
823+
.transaction(|transaction| {
824+
if transaction.query_row(
825+
"SELECT COUNT(*) FROM transports WHERE addr=?",
826+
(addr,),
827+
|row| {
828+
let res: i64 = row.get(0)?;
829+
Ok(res)
830+
},
831+
)? == 0
832+
{
833+
bail!("Address does not belong to any transport.");
834+
}
835+
transaction.execute(
836+
"UPDATE config SET value=? WHERE keyname='configured_addr'",
837+
(addr,),
838+
)?;
839+
840+
// Clean up SMTP and IMAP APPEND queue.
841+
//
842+
// The messages in the queue have a different
843+
// From address so we cannot send them over
844+
// the new SMTP transport.
845+
transaction.execute("DELETE FROM smtp", ())?;
846+
transaction.execute("DELETE FROM imap_send", ())?;
847+
848+
Ok(())
849+
})
850+
.await?;
851+
send_sync_transports(self).await?;
852+
self.sql.uncache_raw_config("configured_addr").await;
821853
}
822-
self.sql
823-
.transaction(|transaction| {
824-
if transaction.query_row(
825-
"SELECT COUNT(*) FROM transports WHERE addr=?",
826-
(addr,),
827-
|row| {
828-
let res: i64 = row.get(0)?;
829-
Ok(res)
830-
},
831-
)? == 0
832-
{
833-
bail!("Address does not belong to any transport.");
834-
}
835-
transaction.execute(
836-
"UPDATE config SET value=? WHERE keyname='configured_addr'",
837-
(addr,),
838-
)?;
839-
840-
// Clean up SMTP and IMAP APPEND queue.
841-
//
842-
// The messages in the queue have a different
843-
// From address so we cannot send them over
844-
// the new SMTP transport.
845-
transaction.execute("DELETE FROM smtp", ())?;
846-
transaction.execute("DELETE FROM imap_send", ())?;
847-
848-
Ok(())
849-
})
850-
.await?;
851-
self.sql.uncache_raw_config("configured_addr").await;
852854
}
853855
_ => {
854856
self.sql.set_raw_config(key.as_ref(), value).await?;

0 commit comments

Comments
 (0)