From: Lukas Wagner <l.wagner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox 2/3] notify: smtp: add test for building forwarded messages
Date: Fri, 23 May 2025 14:26:14 +0200 [thread overview]
Message-ID: <20250523122615.251430-6-l.wagner@proxmox.com> (raw)
In-Reply-To: <20250523122615.251430-1-l.wagner@proxmox.com>
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
proxmox-notify/src/endpoints/smtp.rs | 32 ++++++
proxmox-notify/testdata/test1.msg | 104 ++++++++++++++++++
.../test_forward_message_from_raw.ref | 95 ++++++++++++++++
3 files changed, 231 insertions(+)
create mode 100644 proxmox-notify/testdata/test1.msg
create mode 100644 proxmox-notify/testdata/test_forward_message_from_raw.ref
diff --git a/proxmox-notify/src/endpoints/smtp.rs b/proxmox-notify/src/endpoints/smtp.rs
index 2f4bad3c..7ad85de8 100644
--- a/proxmox-notify/src/endpoints/smtp.rs
+++ b/proxmox-notify/src/endpoints/smtp.rs
@@ -376,3 +376,35 @@ fn build_forwarded_message(
Ok(message)
}
+
+#[cfg(all(test, feature = "mail-forwarder"))]
+mod tests {
+ use lettre::message::header::Date;
+
+ use super::*;
+
+ #[test]
+ fn test_forward_message_from_raw() {
+ let input = "testdata/test1.msg";
+ let reference = "testdata/test_forward_message_from_raw.ref";
+
+ let mut email_builder =
+ Message::builder().from("Sender <sender@example.com>".parse().unwrap());
+
+ email_builder = email_builder.to("Recipient <recipient@example.com>".parse().unwrap());
+
+ let raw_mail = std::fs::read(input).unwrap();
+ let mut message = build_forwarded_message(email_builder, "test", &raw_mail).unwrap();
+
+ // The Date header contains the current time, let's just remove it
+ // for this test.
+ message.headers_mut().remove::<Date>();
+
+ let formatted = message.formatted();
+
+ // Uncomment to update the reference file.
+ // std::fs::write(reference, &formatted).unwrap();
+
+ assert_eq!(formatted, std::fs::read(reference).unwrap());
+ }
+}
diff --git a/proxmox-notify/testdata/test1.msg b/proxmox-notify/testdata/test1.msg
new file mode 100644
index 00000000..634e7522
--- /dev/null
+++ b/proxmox-notify/testdata/test1.msg
@@ -0,0 +1,104 @@
+From root@host.example.com Fri May 23 11:59:32 2025
+Return-Path: <root@host.example.com>
+X-Original-To: root
+Delivered-To: root@host.example.com
+Received: by host.example.com (Postfix, from userid 0)
+ id 25CE920081A; Fri, 23 May 2025 11:59:32 +0200 (CEST)
+Content-Type: multipart/alternative;
+ boundary="----_=_NextPart_002_1747994372"
+MIME-Version: 1.0
+Subject: vzdump backup status (host.example.com): backup successful
+From: Proxmox VE <root@host.example.com>
+To: root@host.example.com
+Date: Fri, 23 May 2025 11:59:32 +0200
+Auto-Submitted: auto-generated;
+Message-Id: <20250523095932.25CE920081A@host.example.com>
+
+This is a multi-part message in MIME format.
+
+------_=_NextPart_002_1747994372
+Content-Type: text/plain;
+ charset="UTF-8"
+Content-Transfer-Encoding: 8bit
+
+
+Details
+=======
+VMID Name Status Time Size Filename
+187 smtp-sink ok 11s 430.758 MiB /var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst
+
+Total running time: 11s
+Total size: 430.758 MiB
+
+Logs
+====
+vzdump 187 --compress zstd --notes-template '{{guestname}}' --remove 0 --storage local --mode snapshot --notification-mode notification-system --node host
+
+
+187: 2025-05-23 11:59:21 INFO: Starting Backup of VM 187 (lxc)
+187: 2025-05-23 11:59:21 INFO: status = stopped
+187: 2025-05-23 11:59:21 INFO: backup mode: stop
+187: 2025-05-23 11:59:21 INFO: ionice priority: 7
+187: 2025-05-23 11:59:21 INFO: CT Name: smtp-sink
+187: 2025-05-23 11:59:21 INFO: including mount point rootfs ('/') in backup
+187: 2025-05-23 11:59:21 INFO: creating vzdump archive '/var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst'
+187: 2025-05-23 11:59:32 INFO: Total bytes written: 1519319040 (1.5GiB, 135MiB/s)
+187: 2025-05-23 11:59:32 INFO: archive file size: 430MB
+187: 2025-05-23 11:59:32 INFO: adding notes to backup
+187: 2025-05-23 11:59:32 INFO: Finished Backup of VM 187 (00:00:11)
+
+
+
+------_=_NextPart_002_1747994372
+Content-Type: text/html;
+ charset="UTF-8"
+Content-Transfer-Encoding: 8bit
+
+<html>
+ <body>
+
+ <h1 style="font-size: 1.2em">Details</h1>
+ <table style="border: 1px solid;border-collapse=collapse;">
+ <tr>
+ <th style="border: 1px solid;border-collapse=collapse;">VMID</th>
+ <th style="border: 1px solid;border-collapse=collapse;">Name</th>
+ <th style="border: 1px solid;border-collapse=collapse;">Status</th>
+ <th style="border: 1px solid;border-collapse=collapse;">Time</th>
+ <th style="border: 1px solid;border-collapse=collapse;">Size</th>
+ <th style="border: 1px solid;border-collapse=collapse;">Filename</th>
+ </tr>
+
+ <tr>
+ <td style="border: 1px solid;border-collapse=collapse;">187</th>
+ <td style="border: 1px solid;border-collapse=collapse;">smtp-sink</th>
+ <td style="border: 1px solid;border-collapse=collapse;">ok</th>
+ <td style="border: 1px solid;border-collapse=collapse;">11s</th>
+ <td style="border: 1px solid;border-collapse=collapse;">430.758 MiB</th>
+ <td style="border: 1px solid;border-collapse=collapse;">/var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst</th>
+ </tr>
+
+ </table>
+ <br/>
+ Total running time: 11s<br/>
+ Total size: 430.758 MiB<br/>
+ <h1 style="font-size: 1.2em">Logs</h1>
+ <pre>vzdump 187 --compress zstd --notes-template '{{guestname}}' --remove 0 --storage local --mode snapshot --notification-mode notification-system --node host
+
+
+187: 2025-05-23 11:59:21 INFO: Starting Backup of VM 187 (lxc)
+187: 2025-05-23 11:59:21 INFO: status = stopped
+187: 2025-05-23 11:59:21 INFO: backup mode: stop
+187: 2025-05-23 11:59:21 INFO: ionice priority: 7
+187: 2025-05-23 11:59:21 INFO: CT Name: smtp-sink
+187: 2025-05-23 11:59:21 INFO: including mount point rootfs ('/') in backup
+187: 2025-05-23 11:59:21 INFO: creating vzdump archive '/var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst'
+187: 2025-05-23 11:59:32 INFO: Total bytes written: 1519319040 (1.5GiB, 135MiB/s)
+187: 2025-05-23 11:59:32 INFO: archive file size: 430MB
+187: 2025-05-23 11:59:32 INFO: adding notes to backup
+187: 2025-05-23 11:59:32 INFO: Finished Backup of VM 187 (00:00:11)
+
+</pre>
+ </body>
+</html>
+
+------_=_NextPart_002_1747994372--
diff --git a/proxmox-notify/testdata/test_forward_message_from_raw.ref b/proxmox-notify/testdata/test_forward_message_from_raw.ref
new file mode 100644
index 00000000..79fede27
--- /dev/null
+++ b/proxmox-notify/testdata/test_forward_message_from_raw.ref
@@ -0,0 +1,95 @@
+From: Sender <sender@example.com>
+To: Recipient <recipient@example.com>
+Subject: vzdump backup status (host.example.com): backup successful
+Content-Type: multipart/alternative;
+ boundary="----_=_NextPart_002_1747994372"
+MIME-Version: 1.0
+
+This is a multi-part message in MIME format.
+
+------_=_NextPart_002_1747994372
+Content-Type: text/plain;
+ charset="UTF-8"
+Content-Transfer-Encoding: 8bit
+
+
+Details
+=======
+VMID Name Status Time Size Filename
+187 smtp-sink ok 11s 430.758 MiB /var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst
+
+Total running time: 11s
+Total size: 430.758 MiB
+
+Logs
+====
+vzdump 187 --compress zstd --notes-template '{{guestname}}' --remove 0 --storage local --mode snapshot --notification-mode notification-system --node host
+
+
+187: 2025-05-23 11:59:21 INFO: Starting Backup of VM 187 (lxc)
+187: 2025-05-23 11:59:21 INFO: status = stopped
+187: 2025-05-23 11:59:21 INFO: backup mode: stop
+187: 2025-05-23 11:59:21 INFO: ionice priority: 7
+187: 2025-05-23 11:59:21 INFO: CT Name: smtp-sink
+187: 2025-05-23 11:59:21 INFO: including mount point rootfs ('/') in backup
+187: 2025-05-23 11:59:21 INFO: creating vzdump archive '/var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst'
+187: 2025-05-23 11:59:32 INFO: Total bytes written: 1519319040 (1.5GiB, 135MiB/s)
+187: 2025-05-23 11:59:32 INFO: archive file size: 430MB
+187: 2025-05-23 11:59:32 INFO: adding notes to backup
+187: 2025-05-23 11:59:32 INFO: Finished Backup of VM 187 (00:00:11)
+
+
+
+------_=_NextPart_002_1747994372
+Content-Type: text/html;
+ charset="UTF-8"
+Content-Transfer-Encoding: 8bit
+
+<html>
+ <body>
+
+ <h1 style="font-size: 1.2em">Details</h1>
+ <table style="border: 1px solid;border-collapse=collapse;">
+ <tr>
+ <th style="border: 1px solid;border-collapse=collapse;">VMID</th>
+ <th style="border: 1px solid;border-collapse=collapse;">Name</th>
+ <th style="border: 1px solid;border-collapse=collapse;">Status</th>
+ <th style="border: 1px solid;border-collapse=collapse;">Time</th>
+ <th style="border: 1px solid;border-collapse=collapse;">Size</th>
+ <th style="border: 1px solid;border-collapse=collapse;">Filename</th>
+ </tr>
+
+ <tr>
+ <td style="border: 1px solid;border-collapse=collapse;">187</th>
+ <td style="border: 1px solid;border-collapse=collapse;">smtp-sink</th>
+ <td style="border: 1px solid;border-collapse=collapse;">ok</th>
+ <td style="border: 1px solid;border-collapse=collapse;">11s</th>
+ <td style="border: 1px solid;border-collapse=collapse;">430.758 MiB</th>
+ <td style="border: 1px solid;border-collapse=collapse;">/var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst</th>
+ </tr>
+
+ </table>
+ <br/>
+ Total running time: 11s<br/>
+ Total size: 430.758 MiB<br/>
+ <h1 style="font-size: 1.2em">Logs</h1>
+ <pre>vzdump 187 --compress zstd --notes-template '{{guestname}}' --remove 0 --storage local --mode snapshot --notification-mode notification-system --node host
+
+
+187: 2025-05-23 11:59:21 INFO: Starting Backup of VM 187 (lxc)
+187: 2025-05-23 11:59:21 INFO: status = stopped
+187: 2025-05-23 11:59:21 INFO: backup mode: stop
+187: 2025-05-23 11:59:21 INFO: ionice priority: 7
+187: 2025-05-23 11:59:21 INFO: CT Name: smtp-sink
+187: 2025-05-23 11:59:21 INFO: including mount point rootfs ('/') in backup
+187: 2025-05-23 11:59:21 INFO: creating vzdump archive '/var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst'
+187: 2025-05-23 11:59:32 INFO: Total bytes written: 1519319040 (1.5GiB, 135MiB/s)
+187: 2025-05-23 11:59:32 INFO: archive file size: 430MB
+187: 2025-05-23 11:59:32 INFO: adding notes to backup
+187: 2025-05-23 11:59:32 INFO: Finished Backup of VM 187 (00:00:11)
+
+</pre>
+ </body>
+</html>
+
+------_=_NextPart_002_1747994372--
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-05-23 12:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-23 12:26 [pve-devel] [PATCH debcargo-config/proxmox 0/6] package `mail-parser` for trixie; update proxmox-notify for newest mail-parser version Lukas Wagner
2025-05-23 12:26 ` [pve-devel] [PATCH debcargo-config 1/3] import mail-parser from bookworm Lukas Wagner
2025-05-23 12:26 ` [pve-devel] [PATCH debcargo-config 2/3] package hashify 0.2.6 Lukas Wagner
2025-05-23 12:26 ` [pve-devel] [PATCH debcargo-config 3/3] update mail-parser to 0.11.0 Lukas Wagner
2025-05-23 12:26 ` [pve-devel] [PATCH proxmox 1/3] notify: smtp: move building of forwarded mails to separate function Lukas Wagner
2025-05-23 12:26 ` Lukas Wagner [this message]
2025-05-23 12:26 ` [pve-devel] [PATCH proxmox 3/3] notify: update mail-parser dependency to 0.11 Lukas Wagner
2025-05-26 14:01 ` [pve-devel] applied: [PATCH debcargo-config/proxmox 0/6] package `mail-parser` for trixie; update proxmox-notify for newest mail-parser version Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250523122615.251430-6-l.wagner@proxmox.com \
--to=l.wagner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.