mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 17:06:35 +03:00
fix: synchronize primary transport immediately after changing it
This commit is contained in:
@@ -188,6 +188,10 @@ def test_transport_synchronization(acfactory, log) -> None:
|
|||||||
log.section("ac1 changes the primary transport")
|
log.section("ac1 changes the primary transport")
|
||||||
ac1.set_config("configured_addr", transport3["addr"])
|
ac1.set_config("configured_addr", transport3["addr"])
|
||||||
|
|
||||||
|
ac1_clone.wait_for_event(EventType.TRANSPORTS_MODIFIED)
|
||||||
|
[transport1, transport3] = ac1_clone.list_transports()
|
||||||
|
assert ac1_clone.get_config("configured_addr") == addr3
|
||||||
|
|
||||||
log.section("ac1 removes the first transport")
|
log.section("ac1 removes the first transport")
|
||||||
ac1.delete_transport(transport1["addr"])
|
ac1.delete_transport(transport1["addr"])
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use crate::mimefactory::RECOMMENDED_FILE_SIZE;
|
|||||||
use crate::provider::Provider;
|
use crate::provider::Provider;
|
||||||
use crate::sync::{self, Sync::*, SyncData};
|
use crate::sync::{self, Sync::*, SyncData};
|
||||||
use crate::tools::get_abs_path;
|
use crate::tools::get_abs_path;
|
||||||
use crate::transport::{ConfiguredLoginParam, add_pseudo_transport};
|
use crate::transport::{ConfiguredLoginParam, add_pseudo_transport, send_sync_transports};
|
||||||
use crate::{constants, stats};
|
use crate::{constants, stats};
|
||||||
|
|
||||||
/// The available configuration keys.
|
/// The available configuration keys.
|
||||||
@@ -818,37 +818,39 @@ impl Context {
|
|||||||
self.sql
|
self.sql
|
||||||
.set_raw_config(Config::ConfiguredAddr.as_ref(), Some(addr))
|
.set_raw_config(Config::ConfiguredAddr.as_ref(), Some(addr))
|
||||||
.await?;
|
.await?;
|
||||||
|
} else {
|
||||||
|
self.sql
|
||||||
|
.transaction(|transaction| {
|
||||||
|
if transaction.query_row(
|
||||||
|
"SELECT COUNT(*) FROM transports WHERE addr=?",
|
||||||
|
(addr,),
|
||||||
|
|row| {
|
||||||
|
let res: i64 = row.get(0)?;
|
||||||
|
Ok(res)
|
||||||
|
},
|
||||||
|
)? == 0
|
||||||
|
{
|
||||||
|
bail!("Address does not belong to any transport.");
|
||||||
|
}
|
||||||
|
transaction.execute(
|
||||||
|
"UPDATE config SET value=? WHERE keyname='configured_addr'",
|
||||||
|
(addr,),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
// Clean up SMTP and IMAP APPEND queue.
|
||||||
|
//
|
||||||
|
// The messages in the queue have a different
|
||||||
|
// From address so we cannot send them over
|
||||||
|
// the new SMTP transport.
|
||||||
|
transaction.execute("DELETE FROM smtp", ())?;
|
||||||
|
transaction.execute("DELETE FROM imap_send", ())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
send_sync_transports(self).await?;
|
||||||
|
self.sql.uncache_raw_config("configured_addr").await;
|
||||||
}
|
}
|
||||||
self.sql
|
|
||||||
.transaction(|transaction| {
|
|
||||||
if transaction.query_row(
|
|
||||||
"SELECT COUNT(*) FROM transports WHERE addr=?",
|
|
||||||
(addr,),
|
|
||||||
|row| {
|
|
||||||
let res: i64 = row.get(0)?;
|
|
||||||
Ok(res)
|
|
||||||
},
|
|
||||||
)? == 0
|
|
||||||
{
|
|
||||||
bail!("Address does not belong to any transport.");
|
|
||||||
}
|
|
||||||
transaction.execute(
|
|
||||||
"UPDATE config SET value=? WHERE keyname='configured_addr'",
|
|
||||||
(addr,),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Clean up SMTP and IMAP APPEND queue.
|
|
||||||
//
|
|
||||||
// The messages in the queue have a different
|
|
||||||
// From address so we cannot send them over
|
|
||||||
// the new SMTP transport.
|
|
||||||
transaction.execute("DELETE FROM smtp", ())?;
|
|
||||||
transaction.execute("DELETE FROM imap_send", ())?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
self.sql.uncache_raw_config("configured_addr").await;
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
self.sql.set_raw_config(key.as_ref(), value).await?;
|
self.sql.set_raw_config(key.as_ref(), value).await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user