require "vnd.stalwart.testsuite"; require "variables"; require "enclose"; require "mime"; require "foreverypart"; require "extracttext"; require "replace"; require "editheader"; test "Enclose" { # Basic enclose test_set "message" text: From: stephan@example.com To: nico@nl.example.com, harry@de.example.com Subject: Frobnitzm Comments: This is nonsense. Keywords: nonsense, strange, testing X-Spam: Yes Test. . ; enclose "This message is quite dangerous and has been enclosed."; test_assert_message "Content-Type: multipart/mixed; boundary=\"boundary_0\" Subject: Frobnitzm From: MAILER-DAEMON Date: Tue, 20 Nov 2022 05:14:20 -0300 Message-ID: --boundary_0 Content-Type: text/plain; charset=utf-8 This message is quite dangerous and has been enclosed. --boundary_0 Content-Type: message/rfc822 From: stephan@example.com To: nico@nl.example.com, harry@de.example.com Subject: Frobnitzm Comments: This is nonsense. Keywords: nonsense, strange, testing X-Spam: Yes Test. --boundary_0-- "; # Enclose yet another time enclose :subject "Inception" :headers ["From: john@example.com", "To: Undisclosed recipients;", "Date: my date", "Message-ID: " ] "Enclosing yet another time, just for fun. "; test_assert_message "Content-Type: multipart/mixed; boundary=\"boundary_1\" Subject: Inception From: john@example.com To: Undisclosed recipients; Date: my date Message-ID: --boundary_1 Content-Type: text/plain; charset=utf-8 Enclosing yet another time, just for fun. --boundary_1 Content-Type: message/rfc822 Content-Type: multipart/mixed; boundary=\"boundary_0\" Subject: Frobnitzm From: MAILER-DAEMON Date: Tue, 20 Nov 2022 05:14:20 -0300 Message-ID: --boundary_0 Content-Type: text/plain; charset=utf-8 This message is quite dangerous and has been enclosed. --boundary_0 Content-Type: message/rfc822 From: stephan@example.com To: nico@nl.example.com, harry@de.example.com Subject: Frobnitzm Comments: This is nonsense. Keywords: nonsense, strange, testing X-Spam: Yes Test. --boundary_0-- --boundary_1-- "; # Enclosing a message with replaced parts # Mixed content test_result_reset; test_set "message" text: From: Whomever To: Someone Date: Sat, 10 Oct 2009 00:30:04 +0200 Subject: whatever Content-Type: multipart/mixed; boundary=outer This is a multi-part message in MIME format. --outer Content-Type: multipart/alternative; boundary=inner This is a nested multi-part message in MIME format. --inner Content-Type: text/plain; charset="us-ascii" Hello --inner Content-Type: text/html; charset="us-ascii" Hello --inner-- This is the end of the inner MIME multipart. --outer Content-Type: message/rfc822 From: Someone Else Subject: Hello, this is an elaborate request for you to finally say hello already! Please say Hello --outer-- This is the end of the outer MIME multipart. . ; foreverypart { if header :mime :type "content-type" "text" { extracttext :upper "text_content"; replace "${text_content}"; } else { addheader :last "X-Original" "true"; } } enclose "Enclosing a message that has replacements inside. "; foreverypart { addheader :last "X-Test" "Added automatically"; } test_assert_message "Content-Type: multipart/mixed; boundary=\"boundary_0\" Subject: whatever From: MAILER-DAEMON Date: Tue, 20 Nov 2022 05:14:20 -0300 Message-ID: X-Test: Added automatically --boundary_0 Content-Type: text/plain; charset=utf-8 X-Test: Added automatically Enclosing a message that has replacements inside. --boundary_0 Content-Type: message/rfc822 X-Test: Added automatically From: Whomever To: Someone Date: Sat, 10 Oct 2009 00:30:04 +0200 Subject: whatever Content-Type: multipart/mixed; boundary=outer X-Original: true This is a multi-part message in MIME format. --outer Content-Type: multipart/alternative; boundary=inner X-Original: true This is a nested multi-part message in MIME format. --inner Content-Type: text/plain; charset=utf-8 HELLO --inner Content-Type: text/plain; charset=utf-8 HELLO --inner-- This is the end of the inner MIME multipart. --outer Content-Type: message/rfc822 X-Original: true From: Someone Else Subject: Hello, this is an elaborate request for you to finally say hello already! Please say Hello --outer-- This is the end of the outer MIME multipart. --boundary_0-- "; }