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

View File

@@ -71,7 +71,7 @@ impl Context {
/// Deprecated since 2025-02; use `add_transport_from_qr()`
/// or `add_transport()` instead.
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
}
@@ -147,7 +147,7 @@ impl Context {
progress!(self, 0, Some(error_msg.clone()));
bail!(error_msg);
} else {
param.save(self).await?;
param.save_legacy(self).await?;
progress!(self, 1000);
}

View File

@@ -28,7 +28,7 @@ use crate::download::DownloadState;
use crate::events::{Event, EventEmitter, EventType, Events};
use crate::imap::{FolderMeaning, Imap, ServerMetadata};
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::param::{Param, Params};
use crate::peer_channels::Iroh;
@@ -774,7 +774,7 @@ impl Context {
/// Returns information about the context as key-value pairs.
pub async fn get_info(&self) -> Result<BTreeMap<&'static str, String>> {
let unset = "0";
let l = EnteredLoginParam::load(self).await?;
let l = self.list_transports().await?;
let l2 = ConfiguredLoginParam::load(self)
.await?
.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("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);
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)]
async fn test_search_msgs() -> Result<()> {
let alice = TestContext::new_alice().await;

View File

@@ -139,7 +139,7 @@ pub struct EnteredLoginParam {
impl EnteredLoginParam {
/// 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
.get_config(Config::Addr)
.await?
@@ -234,7 +234,7 @@ impl EnteredLoginParam {
/// Saves entered account settings,
/// 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
@@ -924,7 +924,7 @@ mod tests {
.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.certificate_checks,
@@ -933,13 +933,13 @@ mod tests {
t.set_config(Config::ImapCertificateChecks, Some("1"))
.await?;
let param = EnteredLoginParam::load(t).await?;
let param = EnteredLoginParam::load_legacy(t).await?;
assert_eq!(param.certificate_checks, EnteredCertificateChecks::Strict);
// Fail to load invalid settings, but do not panic.
t.set_config(Config::ImapCertificateChecks, Some("999"))
.await?;
assert!(EnteredLoginParam::load(t).await.is_err());
assert!(EnteredLoginParam::load_legacy(t).await.is_err());
Ok(())
}
@@ -966,7 +966,7 @@ mod tests {
certificate_checks: Default::default(),
oauth2: false,
};
param.save(&t).await?;
param.save_legacy(&t).await?;
assert_eq!(
t.get_config(Config::Addr).await?.unwrap(),
"alice@example.org"
@@ -975,7 +975,7 @@ mod tests {
assert_eq!(t.get_config(Config::SendPw).await?, None);
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(())
}

View File

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

View File

@@ -608,13 +608,6 @@ async fn test_decode_and_apply_dclogin_advanced_options() -> Result<()> {
ctx.ctx.get_config(Config::SendUser).await?,
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!(
ctx.ctx.get_config(Config::SendSecurity).await?,
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)?;
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?;
sql.execute_migration_transaction(