mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Fix todo: Make get_primary_self_addr() always lowercase the result
This commit is contained in:
@@ -339,9 +339,9 @@ impl Context {
|
|||||||
pub(crate) async fn is_self_addr(&self, addr: &str) -> Result<bool> {
|
pub(crate) async fn is_self_addr(&self, addr: &str) -> Result<bool> {
|
||||||
let addr = addr_normalize(addr).to_lowercase();
|
let addr = addr_normalize(addr).to_lowercase();
|
||||||
|
|
||||||
// The addresses we get here are already normalized and lowercase TODO is this true?
|
// The addresses we get here are already normalized and lowercase
|
||||||
Ok(
|
Ok(
|
||||||
self.get_config(Config::ConfiguredAddr).await?.as_deref() == Some(&addr)
|
self.get_primary_self_addr().await.ok().as_deref() == Some(&addr)
|
||||||
|| self.get_secondary_self_addrs().await?.contains(&addr),
|
|| self.get_secondary_self_addrs().await?.contains(&addr),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -353,6 +353,11 @@ impl Context {
|
|||||||
|
|
||||||
// add old primary address (if exists) to secondary addresses
|
// add old primary address (if exists) to secondary addresses
|
||||||
let mut secondary_addrs = self.get_all_self_addrs().await?;
|
let mut secondary_addrs = self.get_all_self_addrs().await?;
|
||||||
|
|
||||||
|
for a in secondary_addrs.iter_mut() {
|
||||||
|
*a = addr_normalize(a).to_lowercase();
|
||||||
|
}
|
||||||
|
|
||||||
// never store a primary address also as a secondary
|
// never store a primary address also as a secondary
|
||||||
secondary_addrs.retain(|a| a != &primary_new);
|
secondary_addrs.retain(|a| a != &primary_new);
|
||||||
self.set_config(
|
self.set_config(
|
||||||
@@ -378,6 +383,8 @@ impl Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns all secondary self addresses.
|
/// Returns all secondary self addresses.
|
||||||
|
///
|
||||||
|
/// The addresses are already normalized and lowercased in the database.
|
||||||
pub(crate) async fn get_secondary_self_addrs(&self) -> Result<Vec<String>> {
|
pub(crate) async fn get_secondary_self_addrs(&self) -> Result<Vec<String>> {
|
||||||
let secondary_addrs = self
|
let secondary_addrs = self
|
||||||
.get_config(Config::SecondaryAddrs)
|
.get_config(Config::SecondaryAddrs)
|
||||||
@@ -390,10 +397,16 @@ impl Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the primary self address.
|
/// Returns the primary self address.
|
||||||
|
///
|
||||||
|
/// Normalizes and lowercases the address since the ConfiguredAddr
|
||||||
|
/// may not be lowercased (to start lowercasing it now, we would
|
||||||
|
/// need a db migration - which we can do at some point in the future)
|
||||||
pub async fn get_primary_self_addr(&self) -> Result<String> {
|
pub async fn get_primary_self_addr(&self) -> Result<String> {
|
||||||
self.get_config(Config::ConfiguredAddr)
|
let ret = self
|
||||||
|
.get_config(Config::ConfiguredAddr)
|
||||||
.await?
|
.await?
|
||||||
.context("No self addr configured")
|
.context("No self addr configured")?;
|
||||||
|
Ok(addr_normalize(&ret).to_lowercase())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user