From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 30C6F1FF0C0 for ; Wed, 18 Nov 2026 10:47:37 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 5B1DE2166F; Wed, 18 Nov 2026 10:44:56 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox v2 34/63] notify: serialize raw, forwarded mail content as base64 Date: Wed, 18 Nov 2026 10:43:18 +0100 Message-ID: <20261118094348.273646-35-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118094348.273646-1-l.wagner@proxmox.com> References: <20261118094348.273646-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794995039188 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.193 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: Y5WYXXK2DHSXROUJUU4MC3SCX2X2HDBR X-Message-ID-Hash: Y5WYXXK2DHSXROUJUU4MC3SCX2X2HDBR X-MailFrom: l.wagner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: base64 is much more space-efficient than a JSON number array for storing binary data. In an array of numbers, each byte consumes 2-4 bytes of space (1-3 digits plus a comma), while base64 has a constant 1.33x overhead. Signed-off-by: Lukas Wagner --- proxmox-notify/Cargo.toml | 4 +--- proxmox-notify/src/notification.rs | 37 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml index 1971f5b60..e47912d11 100644 --- a/proxmox-notify/Cargo.toml +++ b/proxmox-notify/Cargo.toml @@ -26,7 +26,7 @@ serde_regex = { workspace = true, optional = true } thiserror.workspace = true proxmox-api-macro = { workspace = true, optional = true } -proxmox-base64 = { workspace = true, optional = true } +proxmox-base64 = { workspace = true, features = ["serde"]} proxmox-config-digest = { workspace = true, features = ["openssl"], optional = true } proxmox-http = { workspace = true, optional = true } proxmox-http-error = { workspace = true, optional = true } @@ -55,7 +55,6 @@ api-impl = [ ] api-types = [ "dep:proxmox-api-macro", - "dep:proxmox-base64", "dep:proxmox-match-expression", "dep:regex", "dep:serde_regex", @@ -68,7 +67,6 @@ send-impl = [ "dep:proxmox-config-digest", "dep:mail-parser", "dep:percent-encoding", - "dep:proxmox-base64", "dep:proxmox-http", "proxmox-http/client-sync", "dep:proxmox-human-byte", diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs index 45ab08b87..06b6e67e7 100644 --- a/proxmox-notify/src/notification.rs +++ b/proxmox-notify/src/notification.rs @@ -65,6 +65,10 @@ pub enum Content { #[serde(rename_all = "kebab-case")] ForwardedMail { /// Raw mail contents + #[serde( + serialize_with = "proxmox_base64::serialize_as_base64", + deserialize_with = "proxmox_base64::deserialize_from_base64" + )] raw: Vec, }, } @@ -248,6 +252,39 @@ mod tests { ); } + #[test] + fn forwarded_mail_base64_roundtrip() { + // Not valid UTF-8 and not a multiple of three bytes, so the encoding needs padding. + let content = Content::ForwardedMail { + raw: b"\xff\x00mai".to_vec(), + }; + + let serialized = serde_json::to_value(&content).unwrap(); + assert_eq!(serialized, json!({"forwarded-mail": {"raw": "/wBtYWk="}})); + + let deserialized: Content = serde_json::from_value(serialized).unwrap(); + assert_eq!(deserialized, content); + + let content = Content::ForwardedMail { + raw: TEST_MAIL.to_vec(), + }; + + let serialized = serde_json::to_value(&content).unwrap(); + assert_eq!( + serialized["forwarded-mail"]["raw"], + proxmox_base64::encode(TEST_MAIL) + ); + + let deserialized: Content = serde_json::from_value(serialized).unwrap(); + assert_eq!(deserialized, content); + } + + #[test] + fn forwarded_mail_base64_invalid() { + let result = serde_json::from_value::(json!({"forwarded-mail": {"raw": "$$$"}})); + assert!(result.is_err()); + } + #[test] fn serde_roundtrip() { let fields = HashMap::from([("hostname".to_string(), "pve".to_string())]); -- 2.47.3