mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 18:06:35 +03:00
introduce get_primary_addr() shortcutting access the configured address for an account.
This commit is contained in:
16
src/chat.rs
16
src/chat.rs
@@ -1254,11 +1254,7 @@ impl Chat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let from = context
|
let from = context.get_primary_addr().await?;
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.context("Cannot prepare message for sending, address is not configured.")?;
|
|
||||||
|
|
||||||
let new_rfc724_mid = {
|
let new_rfc724_mid = {
|
||||||
let grpid = match self.typ {
|
let grpid = match self.typ {
|
||||||
Chattype::Group => Some(self.grpid.as_str()),
|
Chattype::Group => Some(self.grpid.as_str()),
|
||||||
@@ -2047,10 +2043,7 @@ async fn create_send_msg_job(context: &Context, msg_id: MsgId) -> Result<Option<
|
|||||||
|
|
||||||
let mut recipients = mimefactory.recipients();
|
let mut recipients = mimefactory.recipients();
|
||||||
|
|
||||||
let from = context
|
let from = context.get_primary_addr().await.unwrap_or_default();
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.unwrap_or_default();
|
|
||||||
let lowercase_from = from.to_lowercase();
|
let lowercase_from = from.to_lowercase();
|
||||||
|
|
||||||
// Send BCC to self if it is enabled and we are not going to
|
// Send BCC to self if it is enabled and we are not going to
|
||||||
@@ -2723,10 +2716,7 @@ pub(crate) async fn add_contact_to_chat_ex(
|
|||||||
context.sync_qr_code_tokens(Some(chat_id)).await?;
|
context.sync_qr_code_tokens(Some(chat_id)).await?;
|
||||||
context.send_sync_msg().await?;
|
context.send_sync_msg().await?;
|
||||||
}
|
}
|
||||||
let self_addr = context
|
let self_addr = context.get_primary_addr().await.unwrap_or_default();
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.unwrap_or_default();
|
|
||||||
if addr_cmp(contact.get_addr(), &self_addr) {
|
if addr_cmp(contact.get_addr(), &self_addr) {
|
||||||
// ourself is added using ContactId::SELF, do not add this address explicitly.
|
// ourself is added using ContactId::SELF, do not add this address explicitly.
|
||||||
// if SELF is not in the group, members cannot be added at all.
|
// if SELF is not in the group, members cannot be added at all.
|
||||||
|
|||||||
@@ -227,6 +227,14 @@ impl Context {
|
|||||||
Ok(self.get_config_int(key).await? != 0)
|
Ok(self.get_config_int(key).await? != 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the primary configured address for this account.
|
||||||
|
pub(crate) async fn get_primary_addr(&self) -> Result<String> {
|
||||||
|
use anyhow::Context;
|
||||||
|
self.get_config(Config::ConfiguredAddr)
|
||||||
|
.await?
|
||||||
|
.context("no address configured")
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) async fn should_watch_mvbox(&self) -> Result<bool> {
|
pub(crate) async fn should_watch_mvbox(&self) -> Result<bool> {
|
||||||
Ok(self.get_config_bool(Config::MvboxMove).await?
|
Ok(self.get_config_bool(Config::MvboxMove).await?
|
||||||
|| self.get_config_bool(Config::OnlyFetchMvbox).await?)
|
|| self.get_config_bool(Config::OnlyFetchMvbox).await?)
|
||||||
|
|||||||
@@ -296,10 +296,7 @@ impl Contact {
|
|||||||
.await?;
|
.await?;
|
||||||
if contact_id == ContactId::SELF {
|
if contact_id == ContactId::SELF {
|
||||||
contact.name = stock_str::self_msg(context).await;
|
contact.name = stock_str::self_msg(context).await;
|
||||||
contact.addr = context
|
contact.addr = context.get_primary_addr().await.unwrap_or_default();
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.unwrap_or_default();
|
|
||||||
contact.status = context
|
contact.status = context
|
||||||
.get_config(Config::Selfstatus)
|
.get_config(Config::Selfstatus)
|
||||||
.await?
|
.await?
|
||||||
@@ -398,10 +395,8 @@ impl Contact {
|
|||||||
|
|
||||||
let addr_normalized = addr_normalize(addr);
|
let addr_normalized = addr_normalize(addr);
|
||||||
|
|
||||||
if let Some(addr_self) = context.get_config(Config::ConfiguredAddr).await? {
|
if context.is_self_addr(addr_normalized).await? {
|
||||||
if addr_cmp(addr_normalized, &addr_self) {
|
return Ok(Some(ContactId::SELF));
|
||||||
return Ok(Some(ContactId::SELF));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let id = context
|
let id = context
|
||||||
.sql
|
.sql
|
||||||
@@ -452,11 +447,10 @@ impl Contact {
|
|||||||
ensure!(origin != Origin::Unknown, "Missing valid origin");
|
ensure!(origin != Origin::Unknown, "Missing valid origin");
|
||||||
|
|
||||||
let addr = addr_normalize(addr).to_string();
|
let addr = addr_normalize(addr).to_string();
|
||||||
let addr_self = context
|
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
|
// during configuration process some chats are added and addr
|
||||||
|
// might not be configured yet
|
||||||
|
let addr_self = context.get_primary_addr().await.unwrap_or_default();
|
||||||
if addr_cmp(&addr, &addr_self) {
|
if addr_cmp(&addr, &addr_self) {
|
||||||
return Ok((ContactId::SELF, sth_modified));
|
return Ok((ContactId::SELF, sth_modified));
|
||||||
}
|
}
|
||||||
@@ -692,11 +686,7 @@ impl Contact {
|
|||||||
listflags: u32,
|
listflags: u32,
|
||||||
query: Option<impl AsRef<str>>,
|
query: Option<impl AsRef<str>>,
|
||||||
) -> Result<Vec<ContactId>> {
|
) -> Result<Vec<ContactId>> {
|
||||||
let self_addr = context
|
let self_addr = context.get_primary_addr().await.unwrap_or_default();
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
let mut add_self = false;
|
let mut add_self = false;
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
let flag_verified_only = (listflags & DC_GCL_VERIFIED_ONLY) != 0;
|
let flag_verified_only = (listflags & DC_GCL_VERIFIED_ONLY) != 0;
|
||||||
|
|||||||
@@ -1451,10 +1451,7 @@ async fn create_or_lookup_group(
|
|||||||
ProtectionStatus::Unprotected
|
ProtectionStatus::Unprotected
|
||||||
};
|
};
|
||||||
|
|
||||||
let self_addr = context
|
let self_addr = context.get_primary_addr().await?;
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.context("no address configured")?;
|
|
||||||
if chat_id.is_none()
|
if chat_id.is_none()
|
||||||
&& !mime_parser.is_mailinglist_message()
|
&& !mime_parser.is_mailinglist_message()
|
||||||
&& !grpid.is_empty()
|
&& !grpid.is_empty()
|
||||||
@@ -1550,11 +1547,7 @@ async fn apply_group_changes(
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let self_addr = context
|
let self_addr = context.get_primary_addr().await?;
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.context("no address configured")?;
|
|
||||||
|
|
||||||
let mut recreate_member_list = false;
|
let mut recreate_member_list = false;
|
||||||
let mut send_event_chat_modified = false;
|
let mut send_event_chat_modified = false;
|
||||||
|
|
||||||
@@ -1998,12 +1991,7 @@ async fn create_adhoc_group(
|
|||||||
/// are hidden in BCC. This group ID is sent by DC in the messages sent to this chat,
|
/// are hidden in BCC. This group ID is sent by DC in the messages sent to this chat,
|
||||||
/// so having the same ID prevents group split.
|
/// so having the same ID prevents group split.
|
||||||
async fn create_adhoc_grp_id(context: &Context, member_ids: &[ContactId]) -> Result<String> {
|
async fn create_adhoc_grp_id(context: &Context, member_ids: &[ContactId]) -> Result<String> {
|
||||||
let member_cs = context
|
let member_cs = context.get_primary_addr().await?.to_lowercase();
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.unwrap_or_else(|| "no-self".to_string())
|
|
||||||
.to_lowercase();
|
|
||||||
|
|
||||||
let query = format!(
|
let query = format!(
|
||||||
"SELECT addr FROM contacts WHERE id IN({}) AND id!=?",
|
"SELECT addr FROM contacts WHERE id IN({}) AND id!=?",
|
||||||
sql::repeat_vars(member_ids.len())?
|
sql::repeat_vars(member_ids.len())?
|
||||||
|
|||||||
18
src/e2ee.rs
18
src/e2ee.rs
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use anyhow::{bail, format_err, Context as _, Result};
|
use anyhow::{format_err, Context as _, Result};
|
||||||
use mailparse::ParsedMail;
|
use mailparse::ParsedMail;
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
|
|
||||||
@@ -28,13 +28,7 @@ impl EncryptHelper {
|
|||||||
let prefer_encrypt =
|
let prefer_encrypt =
|
||||||
EncryptPreference::from_i32(context.get_config_int(Config::E2eeEnabled).await?)
|
EncryptPreference::from_i32(context.get_config_int(Config::E2eeEnabled).await?)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let addr = match context.get_config(Config::ConfiguredAddr).await? {
|
let addr = context.get_primary_addr().await?;
|
||||||
None => {
|
|
||||||
bail!("addr not configured!");
|
|
||||||
}
|
|
||||||
Some(addr) => addr,
|
|
||||||
};
|
|
||||||
|
|
||||||
let public_key = SignedPublicKey::load_self(context).await?;
|
let public_key = SignedPublicKey::load_self(context).await?;
|
||||||
|
|
||||||
Ok(EncryptHelper {
|
Ok(EncryptHelper {
|
||||||
@@ -387,13 +381,7 @@ fn contains_report(mail: &ParsedMail<'_>) -> bool {
|
|||||||
/// [Config::ConfiguredAddr] is configured, this address is returned.
|
/// [Config::ConfiguredAddr] is configured, this address is returned.
|
||||||
// TODO, remove this once deltachat::key::Key no longer exists.
|
// TODO, remove this once deltachat::key::Key no longer exists.
|
||||||
pub async fn ensure_secret_key_exists(context: &Context) -> Result<String> {
|
pub async fn ensure_secret_key_exists(context: &Context) -> Result<String> {
|
||||||
let self_addr = context
|
let self_addr = context.get_primary_addr().await?;
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.context(concat!(
|
|
||||||
"Failed to get self address, ",
|
|
||||||
"cannot ensure secret key if not configured."
|
|
||||||
))?;
|
|
||||||
SignedPublicKey::load_self(context).await?;
|
SignedPublicKey::load_self(context).await?;
|
||||||
Ok(self_addr)
|
Ok(self_addr)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1117,11 +1117,7 @@ impl Imap {
|
|||||||
.session
|
.session
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.context("IMAP No Connection established")?;
|
.context("IMAP No Connection established")?;
|
||||||
let self_addr = context
|
let self_addr = context.get_primary_addr().await?;
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.context("not configured")?;
|
|
||||||
|
|
||||||
let search_command = format!("FROM \"{}\"", self_addr);
|
let search_command = format!("FROM \"{}\"", self_addr);
|
||||||
let uids = session
|
let uids = session
|
||||||
.uid_search(search_command)
|
.uid_search(search_command)
|
||||||
|
|||||||
@@ -351,9 +351,8 @@ async fn set_self_key(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let self_addr = context.get_config(Config::ConfiguredAddr).await?;
|
let self_addr = context.get_primary_addr().await?;
|
||||||
ensure!(self_addr.is_some(), "Missing self addr");
|
let addr = EmailAddress::new(&self_addr)?;
|
||||||
let addr = EmailAddress::new(&self_addr.unwrap_or_default())?;
|
|
||||||
let keypair = pgp::KeyPair {
|
let keypair = pgp::KeyPair {
|
||||||
addr,
|
addr,
|
||||||
public: public_key,
|
public: public_key,
|
||||||
|
|||||||
@@ -198,10 +198,7 @@ impl DcSecretKey for SignedSecretKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn generate_keypair(context: &Context) -> Result<KeyPair> {
|
async fn generate_keypair(context: &Context) -> Result<KeyPair> {
|
||||||
let addr = context
|
let addr = context.get_primary_addr().await?;
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.context("no address configured")?;
|
|
||||||
let addr = EmailAddress::new(&addr)?;
|
let addr = EmailAddress::new(&addr)?;
|
||||||
let _guard = context.generating_key_mutex.lock().await;
|
let _guard = context.generating_key_mutex.lock().await;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ use bitflags::bitflags;
|
|||||||
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
|
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
|
||||||
|
|
||||||
use crate::chat::{self, ChatId};
|
use crate::chat::{self, ChatId};
|
||||||
use crate::config::Config;
|
|
||||||
use crate::contact::ContactId;
|
use crate::contact::ContactId;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::dc_tools::time;
|
use crate::dc_tools::time;
|
||||||
@@ -424,10 +423,7 @@ pub async fn delete_all(context: &Context) -> Result<()> {
|
|||||||
pub async fn get_kml(context: &Context, chat_id: ChatId) -> Result<(String, u32)> {
|
pub async fn get_kml(context: &Context, chat_id: ChatId) -> Result<(String, u32)> {
|
||||||
let mut last_added_location_id = 0;
|
let mut last_added_location_id = 0;
|
||||||
|
|
||||||
let self_addr = context
|
let self_addr = context.get_primary_addr().await?;
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
let (locations_send_begin, locations_send_until, locations_last_sent) = context.sql.query_row(
|
let (locations_send_begin, locations_send_until, locations_last_sent) = context.sql.query_row(
|
||||||
"SELECT locations_send_begin, locations_send_until, locations_last_sent FROM chats WHERE id=?;",
|
"SELECT locations_send_begin, locations_send_until, locations_last_sent FROM chats WHERE id=?;",
|
||||||
|
|||||||
@@ -139,12 +139,12 @@ pub struct LoginParam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl LoginParam {
|
impl LoginParam {
|
||||||
/// Load entered (candidate) account settings
|
/// Load entered (candidate) account settings
|
||||||
pub async fn load_candidate_params(context: &Context) -> Result<Self> {
|
pub async fn load_candidate_params(context: &Context) -> Result<Self> {
|
||||||
LoginParam::from_database(context, "").await
|
LoginParam::from_database(context, "").await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load configured (working) account settings
|
/// Load configured (working) account settings
|
||||||
pub async fn load_configured_params(context: &Context) -> Result<Self> {
|
pub async fn load_configured_params(context: &Context) -> Result<Self> {
|
||||||
LoginParam::from_database(context, "configured_").await
|
LoginParam::from_database(context, "configured_").await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,11 +133,7 @@ impl<'a> MimeFactory<'a> {
|
|||||||
) -> Result<MimeFactory<'a>> {
|
) -> Result<MimeFactory<'a>> {
|
||||||
let chat = Chat::load_from_db(context, msg.chat_id).await?;
|
let chat = Chat::load_from_db(context, msg.chat_id).await?;
|
||||||
|
|
||||||
let from_addr = context
|
let from_addr = context.get_primary_addr().await.unwrap_or_default();
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
let config_displayname = context
|
let config_displayname = context
|
||||||
.get_config(Config::Displayname)
|
.get_config(Config::Displayname)
|
||||||
.await?
|
.await?
|
||||||
@@ -237,10 +233,7 @@ impl<'a> MimeFactory<'a> {
|
|||||||
ensure!(!msg.chat_id.is_special(), "Invalid chat id");
|
ensure!(!msg.chat_id.is_special(), "Invalid chat id");
|
||||||
|
|
||||||
let contact = Contact::load_from_db(context, msg.from_id).await?;
|
let contact = Contact::load_from_db(context, msg.from_id).await?;
|
||||||
let from_addr = context
|
let from_addr = context.get_primary_addr().await?;
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.unwrap_or_default();
|
|
||||||
let from_displayname = context
|
let from_displayname = context
|
||||||
.get_config(Config::Displayname)
|
.get_config(Config::Displayname)
|
||||||
.await?
|
.await?
|
||||||
@@ -278,11 +271,7 @@ impl<'a> MimeFactory<'a> {
|
|||||||
&self,
|
&self,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
) -> Result<Vec<(Option<Peerstate>, &str)>> {
|
) -> Result<Vec<(Option<Peerstate>, &str)>> {
|
||||||
let self_addr = context
|
let self_addr = context.get_primary_addr().await?;
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.context("not configured")?;
|
|
||||||
|
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
for (_, addr) in self
|
for (_, addr) in self
|
||||||
.recipients
|
.recipients
|
||||||
|
|||||||
@@ -449,13 +449,7 @@ impl Context {
|
|||||||
// [======67%===== ]
|
// [======67%===== ]
|
||||||
// =============================================================================================
|
// =============================================================================================
|
||||||
|
|
||||||
let domain = dc_tools::EmailAddress::new(
|
let domain = dc_tools::EmailAddress::new(&self.get_primary_addr().await?)?.domain;
|
||||||
&self
|
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await?
|
|
||||||
.unwrap_or_default(),
|
|
||||||
)?
|
|
||||||
.domain;
|
|
||||||
ret += &format!(
|
ret += &format!(
|
||||||
"<h3>{}</h3><ul>",
|
"<h3>{}</h3><ul>",
|
||||||
stock_str::storage_on_domain(self, domain).await
|
stock_str::storage_on_domain(self, domain).await
|
||||||
|
|||||||
@@ -66,19 +66,7 @@ pub async fn dc_get_securejoin_qr(context: &Context, group: Option<ChatId>) -> R
|
|||||||
.is_none();
|
.is_none();
|
||||||
let invitenumber = token::lookup_or_new(context, Namespace::InviteNumber, group).await;
|
let invitenumber = token::lookup_or_new(context, Namespace::InviteNumber, group).await;
|
||||||
let auth = token::lookup_or_new(context, Namespace::Auth, group).await;
|
let auth = token::lookup_or_new(context, Namespace::Auth, group).await;
|
||||||
let self_addr = match context.get_config(Config::ConfiguredAddr).await {
|
let self_addr = context.get_primary_addr().await?;
|
||||||
Ok(Some(addr)) => addr,
|
|
||||||
Ok(None) => {
|
|
||||||
bail!("Not configured, cannot generate QR code.");
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
bail!(
|
|
||||||
"Unable to retrieve configuration, cannot generate QR code: {:?}",
|
|
||||||
err
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let self_name = context
|
let self_name = context
|
||||||
.get_config(Config::Displayname)
|
.get_config(Config::Displayname)
|
||||||
.await?
|
.await?
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ UPDATE chats SET protected=1, type=120 WHERE type=130;"#,
|
|||||||
|
|
||||||
if dbversion < 71 {
|
if dbversion < 71 {
|
||||||
info!(context, "[migration] v71");
|
info!(context, "[migration] v71");
|
||||||
if let Some(addr) = context.get_config(Config::ConfiguredAddr).await? {
|
if let Ok(addr) = context.get_primary_addr().await {
|
||||||
if let Ok(domain) = addr.parse::<EmailAddress>().map(|email| email.domain) {
|
if let Ok(domain) = addr.parse::<EmailAddress>().map(|email| email.domain) {
|
||||||
context
|
context
|
||||||
.set_config(
|
.set_config(
|
||||||
|
|||||||
@@ -407,12 +407,7 @@ impl TestContext {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let addr = other
|
let addr = other.ctx.get_primary_addr().await.unwrap();
|
||||||
.ctx
|
|
||||||
.get_config(Config::ConfiguredAddr)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
// MailinglistAddress is the lowest allowed origin, we'd prefer to not modify the
|
// MailinglistAddress is the lowest allowed origin, we'd prefer to not modify the
|
||||||
// origin when creating this contact.
|
// origin when creating this contact.
|
||||||
let (contact_id, modified) =
|
let (contact_id, modified) =
|
||||||
|
|||||||
Reference in New Issue
Block a user