chore: Mark old configs as deprecated

Also, fix small bug that the configured server didn't turn
up in get_info().
This commit is contained in:
Hocuri
2025-04-14 12:29:10 +02:00
parent 1379821b03
commit ed9d394daa
8 changed files with 118 additions and 33 deletions

View File

@@ -43,50 +43,84 @@ use crate::tools::get_abs_path;
)] )]
#[strum(serialize_all = "snake_case")] #[strum(serialize_all = "snake_case")]
pub enum Config { pub enum Config {
/// Deprecated(2025-04).
/// Use ConfiguredAddr, EnteredLoginParam, or add_transport{from_qr}()/list_transports() instead.
///
/// Email address, used in the `From:` field. /// Email address, used in the `From:` field.
Addr, Addr,
/// Deprecated(2025-04).
/// Use EnteredLoginParam, and add_transport{from_qr}()/list_transports() instead.
///
/// IMAP server hostname. /// IMAP server hostname.
MailServer, MailServer,
/// Deprecated(2025-04).
/// Use EnteredLoginParam, and add_transport{from_qr}()/list_transports() instead.
///
/// IMAP server username. /// IMAP server username.
MailUser, MailUser,
/// Deprecated(2025-04).
/// Use EnteredLoginParam, and add_transport{from_qr}()/list_transports() instead.
///
/// IMAP server password. /// IMAP server password.
MailPw, MailPw,
/// Deprecated(2025-04).
/// Use EnteredLoginParam, and add_transport{from_qr}()/list_transports() instead.
///
/// IMAP server port. /// IMAP server port.
MailPort, MailPort,
/// Deprecated(2025-04).
/// Use EnteredLoginParam, and add_transport{from_qr}()/list_transports() instead.
///
/// IMAP server security (e.g. TLS, STARTTLS). /// IMAP server security (e.g. TLS, STARTTLS).
MailSecurity, MailSecurity,
/// Deprecated(2025-04).
/// Use EnteredLoginParam, and add_transport{from_qr}()/list_transports() instead.
///
/// How to check TLS certificates. /// How to check TLS certificates.
/// ///
/// "IMAP" in the name is for compatibility, /// "IMAP" in the name is for compatibility,
/// this actually applies to both IMAP and SMTP connections. /// this actually applies to both IMAP and SMTP connections.
ImapCertificateChecks, ImapCertificateChecks,
/// Deprecated(2025-04).
/// Use EnteredLoginParam, and add_transport{from_qr}()/list_transports() instead.
///
/// SMTP server hostname. /// SMTP server hostname.
SendServer, SendServer,
/// Deprecated(2025-04).
/// Use EnteredLoginParam, and add_transport{from_qr}()/list_transports() instead.
///
/// SMTP server username. /// SMTP server username.
SendUser, SendUser,
/// Deprecated(2025-04).
/// Use EnteredLoginParam, and add_transport{from_qr}()/list_transports() instead.
///
/// SMTP server password. /// SMTP server password.
SendPw, SendPw,
/// Deprecated(2025-04).
/// Use EnteredLoginParam, and add_transport{from_qr}()/list_transports() instead.
///
/// SMTP server port. /// SMTP server port.
SendPort, SendPort,
/// Deprecated(2025-04).
/// Use EnteredLoginParam, and add_transport{from_qr}()/list_transports() instead.
///
/// SMTP server security (e.g. TLS, STARTTLS). /// SMTP server security (e.g. TLS, STARTTLS).
SendSecurity, SendSecurity,
/// Deprecated option for backwards compatibility. /// Deprecated(2025-04).
/// Use EnteredLoginParam, and add_transport{from_qr}()/list_transports() instead.
/// ///
/// Certificate checks for SMTP are actually controlled by `imap_certificate_checks` config.
SmtpCertificateChecks,
/// Whether to use OAuth 2. /// Whether to use OAuth 2.
/// ///
/// Historically contained other bitflags, which are now deprecated. /// Historically contained other bitflags, which are now deprecated.
@@ -215,32 +249,47 @@ pub enum Config {
/// The primary email address. Also see `SecondaryAddrs`. /// The primary email address. Also see `SecondaryAddrs`.
ConfiguredAddr, ConfiguredAddr,
/// Deprecated(2025-04).
/// Use ConfiguredLoginParam and add_transport{from_qr}()/list_transports() instead.
///
/// List of configured IMAP servers as a JSON array. /// List of configured IMAP servers as a JSON array.
ConfiguredImapServers, ConfiguredImapServers,
/// Deprecated(2025-04).
/// Use ConfiguredLoginParam and add_transport{from_qr}()/list_transports() instead.
///
/// Configured IMAP server hostname. /// Configured IMAP server hostname.
/// ///
/// This is replaced by `configured_imap_servers` for new configurations. /// This is replaced by `configured_imap_servers` for new configurations.
ConfiguredMailServer, ConfiguredMailServer,
/// Configured IMAP server port. /// Deprecated(2025-04).
/// Use ConfiguredLoginParam and add_transport{from_qr}()/list_transports() instead.
/// ///
/// This is replaced by `configured_imap_servers` for new configurations. /// Configured IMAP server port.
ConfiguredMailPort, ConfiguredMailPort,
/// Configured IMAP server security (e.g. TLS, STARTTLS). /// Deprecated(2025-04).
/// Use ConfiguredLoginParam and add_transport{from_qr}()/list_transports() instead.
/// ///
/// This is replaced by `configured_imap_servers` for new configurations. /// Configured IMAP server security (e.g. TLS, STARTTLS).
ConfiguredMailSecurity, ConfiguredMailSecurity,
/// Configured IMAP server username. /// Deprecated(2025-04).
/// Use ConfiguredLoginParam and add_transport{from_qr}()/list_transports() instead.
/// ///
/// This is set if user has configured username manually. /// Configured IMAP server username.
ConfiguredMailUser, ConfiguredMailUser,
/// Deprecated(2025-04).
/// Use ConfiguredLoginParam and add_transport{from_qr}()/list_transports() instead.
///
/// Configured IMAP server password. /// Configured IMAP server password.
ConfiguredMailPw, ConfiguredMailPw,
/// Deprecated(2025-04).
/// Use ConfiguredLoginParam and add_transport{from_qr}()/list_transports() instead.
///
/// Configured TLS certificate checks. /// Configured TLS certificate checks.
/// This option is saved on successful configuration /// This option is saved on successful configuration
/// and should not be modified manually. /// and should not be modified manually.
@@ -249,29 +298,47 @@ pub enum Config {
/// but has "IMAP" in the name for backwards compatibility. /// but has "IMAP" in the name for backwards compatibility.
ConfiguredImapCertificateChecks, ConfiguredImapCertificateChecks,
/// Deprecated(2025-04).
/// Use ConfiguredLoginParam and add_transport{from_qr}()/list_transports() instead.
///
/// List of configured SMTP servers as a JSON array. /// List of configured SMTP servers as a JSON array.
ConfiguredSmtpServers, ConfiguredSmtpServers,
/// Deprecated(2025-04).
/// Use ConfiguredLoginParam and add_transport{from_qr}()/list_transports() instead.
///
/// Configured SMTP server hostname. /// Configured SMTP server hostname.
/// ///
/// This is replaced by `configured_smtp_servers` for new configurations. /// This is replaced by `configured_smtp_servers` for new configurations.
ConfiguredSendServer, ConfiguredSendServer,
/// Deprecated(2025-04).
/// Use ConfiguredLoginParam and add_transport{from_qr}()/list_transports() instead.
///
/// Configured SMTP server port. /// Configured SMTP server port.
/// ///
/// This is replaced by `configured_smtp_servers` for new configurations. /// This is replaced by `configured_smtp_servers` for new configurations.
ConfiguredSendPort, ConfiguredSendPort,
/// Deprecated(2025-04).
/// Use ConfiguredLoginParam and add_transport{from_qr}()/list_transports() instead.
///
/// Configured SMTP server security (e.g. TLS, STARTTLS). /// Configured SMTP server security (e.g. TLS, STARTTLS).
/// ///
/// This is replaced by `configured_smtp_servers` for new configurations. /// This is replaced by `configured_smtp_servers` for new configurations.
ConfiguredSendSecurity, ConfiguredSendSecurity,
/// Deprecated(2025-04).
/// Use ConfiguredLoginParam and add_transport{from_qr}()/list_transports() instead.
///
/// Configured SMTP server username. /// Configured SMTP server username.
/// ///
/// This is set if user has configured username manually. /// This is set if user has configured username manually.
ConfiguredSendUser, ConfiguredSendUser,
/// Deprecated(2025-04).
/// Use ConfiguredLoginParam and add_transport{from_qr}()/list_transports() instead.
///
/// Configured SMTP server password. /// Configured SMTP server password.
ConfiguredSendPw, ConfiguredSendPw,
@@ -280,6 +347,9 @@ pub enum Config {
/// ConfiguredImapCertificateChecks is actually used. /// ConfiguredImapCertificateChecks is actually used.
ConfiguredSmtpCertificateChecks, ConfiguredSmtpCertificateChecks,
/// Deprecated(2025-04).
/// Use ConfiguredLoginParam and add_transport{from_qr}()/list_transports() instead.
///
/// Whether OAuth 2 is used with configured provider. /// Whether OAuth 2 is used with configured provider.
ConfiguredServerFlags, ConfiguredServerFlags,
@@ -301,6 +371,9 @@ pub enum Config {
/// ID of the configured provider from the provider database. /// ID of the configured provider from the provider database.
ConfiguredProvider, ConfiguredProvider,
/// Deprecated(2025-04).
/// Use [`Context::is_configured()`] instead.
///
/// True if account is configured. /// True if account is configured.
Configured, Configured,

View File

@@ -71,7 +71,7 @@ impl Context {
/// Deprecated since 2025-02; use `add_transport_from_qr()` /// Deprecated since 2025-02; use `add_transport_from_qr()`
/// or `add_transport()` instead. /// or `add_transport()` instead.
pub async fn configure(&self) -> Result<()> { pub async fn configure(&self) -> Result<()> {
let param = EnteredLoginParam::load(self).await?; let param = EnteredLoginParam::load_legacy(self).await?;
self.add_transport_inner(&param).await self.add_transport_inner(&param).await
} }
@@ -147,7 +147,7 @@ impl Context {
progress!(self, 0, Some(error_msg.clone())); progress!(self, 0, Some(error_msg.clone()));
bail!(error_msg); bail!(error_msg);
} else { } else {
param.save(self).await?; param.save_legacy(self).await?;
progress!(self, 1000); progress!(self, 1000);
} }

View File

@@ -28,7 +28,7 @@ use crate::download::DownloadState;
use crate::events::{Event, EventEmitter, EventType, Events}; use crate::events::{Event, EventEmitter, EventType, Events};
use crate::imap::{FolderMeaning, Imap, ServerMetadata}; use crate::imap::{FolderMeaning, Imap, ServerMetadata};
use crate::key::{load_self_public_key, load_self_secret_key, DcKey as _}; use crate::key::{load_self_public_key, load_self_secret_key, DcKey as _};
use crate::login_param::{ConfiguredLoginParam, EnteredLoginParam}; use crate::login_param::ConfiguredLoginParam;
use crate::message::{self, Message, MessageState, MsgId}; use crate::message::{self, Message, MessageState, MsgId};
use crate::param::{Param, Params}; use crate::param::{Param, Params};
use crate::peer_channels::Iroh; use crate::peer_channels::Iroh;
@@ -774,7 +774,7 @@ impl Context {
/// Returns information about the context as key-value pairs. /// Returns information about the context as key-value pairs.
pub async fn get_info(&self) -> Result<BTreeMap<&'static str, String>> { pub async fn get_info(&self) -> Result<BTreeMap<&'static str, String>> {
let unset = "0"; let unset = "0";
let l = EnteredLoginParam::load(self).await?; let l = self.list_transports().await?;
let l2 = ConfiguredLoginParam::load(self) let l2 = ConfiguredLoginParam::load(self)
.await? .await?
.map_or_else(|| "Not configured".to_string(), |param| param.to_string()); .map_or_else(|| "Not configured".to_string(), |param| param.to_string());
@@ -867,7 +867,13 @@ impl Context {
); );
res.insert("is_configured", is_configured.to_string()); res.insert("is_configured", is_configured.to_string());
res.insert("proxy_enabled", proxy_enabled.to_string()); res.insert("proxy_enabled", proxy_enabled.to_string());
res.insert("entered_account_settings", l.to_string()); res.insert(
"entered_account_settings",
l.iter()
.map(|l| l.to_string())
.collect::<Vec<_>>()
.join("; "),
);
res.insert("used_account_settings", l2); res.insert("used_account_settings", l2);
if let Some(server_id) = &*self.server_id.read().await { if let Some(server_id) = &*self.server_id.read().await {

View File

@@ -313,6 +313,22 @@ async fn test_get_info_completeness() {
} }
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_get_info_configured() -> Result<()> {
let alice = TestContext::new_alice().await;
let info = alice.get_info().await?;
let entered_account_settings = &info["entered_account_settings"];
assert_eq!(entered_account_settings, "unset imap:unset:0:unset:0:Automatic:AUTH_NORMAL smtp:unset:0:unset:0:Automatic:AUTH_NORMAL cert_automatic");
let used_account_settings = &info["used_account_settings"];
assert_eq!(
used_account_settings,
"alice@example.org imap:[] smtp:[] provider:none cert_automatic"
);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_search_msgs() -> Result<()> { async fn test_search_msgs() -> Result<()> {
let alice = TestContext::new_alice().await; let alice = TestContext::new_alice().await;

View File

@@ -139,7 +139,7 @@ pub struct EnteredLoginParam {
impl EnteredLoginParam { impl EnteredLoginParam {
/// Loads entered account settings. /// Loads entered account settings.
pub(crate) async fn load(context: &Context) -> Result<Self> { pub(crate) async fn load_legacy(context: &Context) -> Result<Self> {
let addr = context let addr = context
.get_config(Config::Addr) .get_config(Config::Addr)
.await? .await?
@@ -234,7 +234,7 @@ impl EnteredLoginParam {
/// Saves entered account settings, /// Saves entered account settings,
/// so that they can be prefilled if the user wants to configure the server again. /// so that they can be prefilled if the user wants to configure the server again.
pub(crate) async fn save(&self, context: &Context) -> Result<()> { pub(crate) async fn save_legacy(&self, context: &Context) -> Result<()> {
context.set_config(Config::Addr, Some(&self.addr)).await?; context.set_config(Config::Addr, Some(&self.addr)).await?;
context context
@@ -924,7 +924,7 @@ mod tests {
.await?; .await?;
t.set_config(Config::MailPw, Some("foobarbaz")).await?; t.set_config(Config::MailPw, Some("foobarbaz")).await?;
let param = EnteredLoginParam::load(t).await?; let param = EnteredLoginParam::load_legacy(t).await?;
assert_eq!(param.addr, "alice@example.org"); assert_eq!(param.addr, "alice@example.org");
assert_eq!( assert_eq!(
param.certificate_checks, param.certificate_checks,
@@ -933,13 +933,13 @@ mod tests {
t.set_config(Config::ImapCertificateChecks, Some("1")) t.set_config(Config::ImapCertificateChecks, Some("1"))
.await?; .await?;
let param = EnteredLoginParam::load(t).await?; let param = EnteredLoginParam::load_legacy(t).await?;
assert_eq!(param.certificate_checks, EnteredCertificateChecks::Strict); assert_eq!(param.certificate_checks, EnteredCertificateChecks::Strict);
// Fail to load invalid settings, but do not panic. // Fail to load invalid settings, but do not panic.
t.set_config(Config::ImapCertificateChecks, Some("999")) t.set_config(Config::ImapCertificateChecks, Some("999"))
.await?; .await?;
assert!(EnteredLoginParam::load(t).await.is_err()); assert!(EnteredLoginParam::load_legacy(t).await.is_err());
Ok(()) Ok(())
} }
@@ -966,7 +966,7 @@ mod tests {
certificate_checks: Default::default(), certificate_checks: Default::default(),
oauth2: false, oauth2: false,
}; };
param.save(&t).await?; param.save_legacy(&t).await?;
assert_eq!( assert_eq!(
t.get_config(Config::Addr).await?.unwrap(), t.get_config(Config::Addr).await?.unwrap(),
"alice@example.org" "alice@example.org"
@@ -975,7 +975,7 @@ mod tests {
assert_eq!(t.get_config(Config::SendPw).await?, None); assert_eq!(t.get_config(Config::SendPw).await?, None);
assert_eq!(t.get_config_int(Config::SendPort).await?, 2947); assert_eq!(t.get_config_int(Config::SendPort).await?, 2947);
assert_eq!(EnteredLoginParam::load(&t).await?, param); assert_eq!(EnteredLoginParam::load_legacy(&t).await?, param);
Ok(()) Ok(())
} }

View File

@@ -247,9 +247,6 @@ pub(crate) async fn configure_from_login_qr(
context context
.set_config_internal(Config::ImapCertificateChecks, Some(&code.to_string())) .set_config_internal(Config::ImapCertificateChecks, Some(&code.to_string()))
.await?; .await?;
context
.set_config_internal(Config::SmtpCertificateChecks, Some(&code.to_string()))
.await?;
} }
Ok(()) Ok(())
} }

View File

@@ -608,13 +608,6 @@ async fn test_decode_and_apply_dclogin_advanced_options() -> Result<()> {
ctx.ctx.get_config(Config::SendUser).await?, ctx.ctx.get_config(Config::SendUser).await?,
Some("SendUser".to_owned()) Some("SendUser".to_owned())
); );
// `sc` option is actually ignored and `ic` is used instead
// because `smtp_certificate_checks` is deprecated.
assert_eq!(
ctx.ctx.get_config(Config::SmtpCertificateChecks).await?,
Some("1".to_owned())
);
assert_eq!( assert_eq!(
ctx.ctx.get_config(Config::SendSecurity).await?, ctx.ctx.get_config(Config::SendSecurity).await?,
Some("3".to_owned()) // plain Some("3".to_owned()) // plain

View File

@@ -1190,7 +1190,7 @@ CREATE INDEX gossip_timestamp_index ON gossip_timestamp (chat_id, fingerprint);
inc_and_check(&mut migration_version, 131)?; inc_and_check(&mut migration_version, 131)?;
if dbversion < migration_version { if dbversion < migration_version {
let entered_param = EnteredLoginParam::load(context).await?; let entered_param = EnteredLoginParam::load_legacy(context).await?;
let configured_param = ConfiguredLoginParam::load_legacy(context).await?; let configured_param = ConfiguredLoginParam::load_legacy(context).await?;
sql.execute_migration_transaction( sql.execute_migration_transaction(