[PATCH proxmox v3 06/23] notify: smtp: Infer auth method for backwards compatibility

Arthur Bied-Charreton
2026-04-15T07:02:37Z

If not set, infer the auth_method SmtpConfig field from the presence
of a password in the config. This makes sure the new API stays
backwards-compatible with old scripts and updates old configurations
when they are edited.

Signed-off-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
---
proxmox-notify/src/api/smtp.rs | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/proxmox-notify/src/api/smtp.rs b/proxmox-notify/src/api/smtp.rs
index b265c26a..71284f63 100644
--- a/proxmox-notify/src/api/smtp.rs
+++ b/proxmox-notify/src/api/smtp.rs
@@ -56,6 +56,20 @@ fn get_private_config(config: &Config, name: &str) -> Result<SmtpPrivateConfig,
})
}

+/// Before the `auth_method` field was introduced into [`SmtpConfig`], the auhentication method
+/// was inferred from the presence of a password in the config. This function should be called
+/// in `add_endpoint` and `update_endpoint` to update old configs and keep backwards compatibility.
+fn infer_auth_method(config: SmtpConfig, private_config: SmtpPrivateConfig) -> SmtpConfig {
+ if config.auth_method.is_none() && private_config.password.is_some() {
+ SmtpConfig {
+ auth_method: Some(SmtpAuthMethod::Plain),
+ ..config
+ }
+ } else {
+ config
+ }
+}
+
/// Add a new smtp endpoint.
///
/// The caller is responsible for any needed permission checks.
@@ -90,11 +104,13 @@ pub fn add_endpoint(

super::set_private_config_entry(
config,
- private_endpoint_config,
+ &private_endpoint_config,
SMTP_TYPENAME,
&endpoint_config.name,
)?;

+ let endpoint_config = infer_auth_method(endpoint_config, private_endpoint_config);
+
config
.config
.set_data(&endpoint_config.name, SMTP_TYPENAME, &endpoint_config)
@@ -209,6 +225,8 @@ pub fn update_endpoint(
}
})?;

+ let endpoint = infer_auth_method(endpoint, get_private_config(config, name)?);
+
config
.config
.set_data(name, SMTP_TYPENAME, &endpoint)
--
2.47.3