spf: avoid wrong kind of json -> string conversion

When populating ehlo_domain in particular, we were using the json
Value::to_string() impl which produces a json-serialized string
which includes quotes.

This is a bit of a foot-gun, so let's add a get_meta_string method
to ConnectionMetaData to parallel the equivalent
Message::get_meta_string method.
This commit is contained in:
Wez Furlong
2025-10-11 07:00:21 +01:00
parent b73d81b0fc
commit 236afa417f
2 changed files with 7 additions and 2 deletions
+5
View File
@@ -2965,6 +2965,11 @@ impl ConnectionMetaData {
meta.get(name.as_ref()).cloned()
}
pub fn get_meta_string<N: AsRef<str>>(&self, name: N) -> Option<String> {
self.get_meta(name)
.and_then(|v| v.as_str().map(|s| s.to_string()))
}
pub fn clone_inner(&self) -> serde_json::Value {
self.map.lock().clone()
}
+2 -2
View File
@@ -26,8 +26,8 @@ pub fn register<'lua>(lua: &'lua Lua) -> anyhow::Result<()> {
.and_then(|v| SocketAddr::from_str(v.as_str()?).ok())
.expect("`received_from` is always set, and always to a value representing a `SocketAddr`");
let ehlo_domain = meta.get_meta("ehlo_domain").map(|s| s.to_string());
let relaying_host_name = meta.get_meta("hostname").map(|s| s.to_string());
let ehlo_domain = meta.get_meta_string("ehlo_domain");
let relaying_host_name = meta.get_meta_string("hostname");
let resolver = dns_resolver::get_resolver();
let result = CheckHostParams {