require "vnd.stalwart.testsuite"; require "vnd.stalwart.expressions"; require "vnd.stalwart.while"; require "relational"; require "body"; require "include"; require "variables"; require "regex"; test_set "message" text: From: "Cosmo Kramer" From: George Constanza From: Art Vandelay (Vandelay Industries) To: "Colleagues": "James Smythe" ; Friends: jane@example.com, =?UTF-8?Q?John_Sm=C3=AEth?= ; Cc: bill@example.com, tom@foobar.org Date: Sat, 20 Nov 2021 14:22:01 -0800 Message-ID: Resent-Message-ID: test@resent X-Message-ID: X-Original-Message-ID: test@x-orig Subject: Why not both importing AND exporting? =?utf-8?b?4pi6?= ReCeived: from out-25.smtp.host.com (other.smtp.host.com [192.30.252.208]) (using TLSv1.3 with cipher TLS13_AES_256_GCM_SHA384) by mail.stalw.art (Stalwart SMTP) with ESMTPS id 41A2C80D73C; Tue, 29 Aug 2023 16:20:12 +0000 ReceiveD: from ietfa.amsl.com (localhost [IPv6:::1]) by ietfa.amsl.com (Postfix) with ESMTP id 6296FC13AE3E for ; Mon, 28 Aug 2023 02:21:37 -0700 (PDT) Content-Type: image/gif; name*1="about "; name*0="Book "; name*2*=utf-8''%e2%98%95 tables.gif Content-Transfer-Encoding: Base64 Content-Disposition: attachment R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 . ; test "Header Variables - Received" { if not string :is "${header.received[1].rcvd.from}" "out-25.smtp.host.com" { test_fail "failed to match header.received[1].rcvd.from: ${header.received[1].rcvd.from}"; } if not string :is "${header.received[1].rcvd.from.name}" "out-25.smtp.host.com" { test_fail "failed to match header.received[1].rcvd.from.name: ${header.received[1].rcvd.from.name}"; } if not string :is "${header.received[1].rcvd.from.ip}" "" { test_fail "failed to match header.received[1].rcvd.from.ip: ${header.received[1].rcvd.from.ip}"; } if not string :is "${header.received[1].rcvd.ip}" "192.30.252.208" { test_fail "failed to match header.received[1].rcvd.ip: ${header.received[1].rcvd.ip}"; } if not string :is "${header.received[1].rcvd.iprev}" "other.smtp.host.com" { test_fail "failed to match header.received[1].rcvd.iprev: ${header.received[1].rcvd.iprev}"; } if not string :is "${header.received[1].rcvd.tls}" "TLSv1.3" { test_fail "failed to match header.received[1].rcvd.tls: ${header.received[1].rcvd.tls}"; } if not string :is "${header.received[1].rcvd.cipher}" "TLS13_AES_256_GCM_SHA384" { test_fail "failed to match header.received[1].rcvd.cipher: ${header.received[1].rcvd.cipher}"; } if not string :is "${header.received[-1].rcvd.from}" "ietfa.amsl.com" { test_fail "failed to match header.received[-1].rcvd.from: ${header.received[-1].rcvd.from}"; } if not string :is "${header.received[-1].rcvd.date.raw}" "Mon, 28 Aug 2023 02:21:37 -0700" { test_fail "failed to match header.received[-1].rcvd.date.raw: ${header.received[-1].rcvd.date.raw}"; } if not string :is "${header.received[-1].rcvd.date}" "1693214497" { test_fail "failed to match header.received[-1].rcvd.date: ${header.received[-1].rcvd.date}"; } if eval "header.received[-1].rcvd.date > header.received[1].rcvd.date" { test_fail "header.received[-1].rcvd.date <= header.received[1].rcvd.date: ${header.received[-1].rcvd.date} <= ${header.received[1].rcvd.date}"; } if eval "!header.received.exists" { test_fail "header.received.exists failed"; } if eval "count(header.received[*].exists) != 2" { test_fail "count(header.received[*].exists) != 2"; } if eval "header.received[*].raw_name != ['ReCeived', 'ReceiveD']" { test_fail "header.received[*].raw_name failed"; } } test "Header Variables - Addresses" { if not string :is "${header.subject}" "Why not both importing AND exporting? ☺" { test_fail "failed to match header.subject: ${header.subject}"; } if not string :is "${header.from.name}" "Art Vandelay (Vandelay Industries)" { test_fail "failed to match header.from.name: ${header.from.name}"; } if not string :is "${header.from.addr}" "art@vandelay.com" { test_fail "failed to match header.from.addr: ${header.from.addr}"; } if not string :is "${header.from.raw}" " Art Vandelay (Vandelay Industries)" { test_fail "failed to match header.from.raw: ${header.from.raw}"; } if not string :is "${header.from[1].name}" "Cosmo Kramer" { test_fail "failed to match header.from[1].name: ${header.from[1].name}"; } if not string :is "${header.from[-1].name}" "Art Vandelay (Vandelay Industries)" { test_fail "failed to match header.from[-1].name: ${header.from[-1].name}"; } if not string :is "${header.from[2].name}" "George Constanza" { test_fail "failed to match header.from[2].name: ${header.from[2].name}"; } if not string :is "${header.from[*].addr}" "kramer@kramerica.com george@yankees.com art@vandelay.com" { test_fail "failed to match header.from[*].addr: ${header.from[*].addr}"; } if not string :is "${header.to.addr}" "john@example.com" { test_fail "failed to match header.to.addr: ${header.to.addr}"; } if not string :is "${header.to.addr[-1]}" "john@example.com" { test_fail "failed to match header.to.addr[-1]: ${header.to.addr[-1]}"; } if not string :is "${header.to.addr[1]}" "james@vandelay.com" { test_fail "failed to match header.to.addr[1]: ${header.to.addr[1]}"; } if not string :is "${header.to.addr[2]}" "jane@example.com" { test_fail "failed to match header.to.addr[2]: ${header.to.addr[2]}"; } if not string :is "${header.to.addr[*]}" "james@vandelay.com jane@example.com john@example.com" { test_fail "failed to match header.to.addr[*]: ${header.to.addr[*]}"; } if not string :is "${header.to[*][*]}" "James Smythe John Smîth " { test_fail "failed to match header.to[*][*]: ${header.to[*][*]}"; } if not string :is "${header.to:cc[*][*]}" "James Smythe John Smîth " { test_fail "failed to match header.to:cc[*][*]: ${header.to:cc[*][*]}"; } if not string :is "${header.to:cc[*].addr[*]}" "james@vandelay.com jane@example.com john@example.com bill@example.com tom@foobar.org" { test_fail "failed to match header.to:cc[*].addr[*]: ${header.to:cc[*].addr[*]}"; } if not string :is "${header.message-id:resent-message-id:x-message-id:x-original-message-id[*].id[*]}" "test@id test@resent test@x-id test@x-orig" { test_fail "failed to match header.message-id:resent-message-id:x-message-id:x-original-message-id[*].id[*]: ${header.message-id:resent-message-id:x-message-id:x-original-message-id[*].id[*]}"; } if not eval "header.message-id:resent-message-id:x-message-id:x-original-message-id[*].id[*] == ['test@id', 'test@resent', 'test@x-id', 'test@x-orig']" { test_fail "failed to match header.message-id:resent-message-id:x-message-id:x-original-message-id[*].id[*]: ${header.message-id:resent-message-id:x-message-id:x-original-message-id[*].id[*]}"; } } test "Header Variables - Content-Type" { if not string :is "${header.content-type}" "image/gif" { test_fail "failed to match header.content-type: ${header.content-type}"; } if not eval "header.content-type.type == 'image'" { test_fail "failed to match header.content-type.type == 'image': ${header.content-type.type}"; } let "cts" "header.content-type.type"; set "i" "0"; while "i < count(cts)" { if eval "cts[i] != 'image'" { test_fail "failed to match line: {header.content-type.type} {cts[i]} {i}"; } let "i" "i+1"; } if not string :is "${header.content-type.type}" "image" { test_fail "failed to match header.content-type.type: ${header.content-type.type}"; } if not string :is "${header.content-type.subtype}" "gif" { test_fail "failed to match header.content-type.subtype: ${header.content-type.subtype}"; } if not string :is "${header.content-type.attr.name}" "Book about ☕ tables.gif" { test_fail "failed to match header.content-type.attr.name: ${header.content-type.attr.name}"; } if not string :is "${header.date.date}" "1637446921" { test_fail "failed to match header.date.date: ${header.date.date}"; } }