#! /bin/sh

. ${srcdir:=.}/t.frame

# Test #1: checks if improperly folded encoded words are decoded
# without crash. 
#  test case supplied by Clint Adams, Debian.

# Test #2: checks if improperly terminated encoded words causes 
# improper processing of the mime parts.
# Test case 2 supplied by Evgeny Kotsuba.

# NOTE #####
# Test case 2 is currently disabled because we don't want to
# provide the same output for broken encoded words as for conformant
# ones, so we can tell broken mailers from intact.

##### Test #1 - improper folding #####
cat > "$TMPDIR/input.1" <<_EOF
Subject: [Broken] =?ISO-8859-1?Q?Re=3A_=5BBroken=5D_=3D=3FISO-8859-1=3FQ=3F=3D5B?=
 =?ISO-8859-1?Q?Broken=3D5DBlah=3D20Foo=3DE4=3D20Bar=3D20Blah
 _?= =?ISO-8859-1?Q?Foo=3D3D28=3D5F=3F=3D_Bar=5F=5F=3F=3D_t=E4Blah?=
 =?ISO-8859-1?Q?Foo=E4t=29?=

Hello.
_EOF

$BOGOLEXER -p -C < "$TMPDIR"/input.1 > "$TMPDIR/output.1"

exit $?

##### Test #2a - improperly terminated encoded word #####

cat > "$TMPDIR/input.2a" <<_EOF
Return-Path: <pro@blabla.com>
Content-Type: multipart/mixed; boundary="--ek-1129"

----ek-1129
Content-Type: application/x-zip-compressed; name="filename.txt"
Content-Disposition: attachment; filename="=?Windows-1251?B?Z29v?=
	=?Windows-1251?B?5fTu"
Content-Transfer-Encoding: base64

UEsDBBQAAgAIADyWpzC0Mjdx9ksFAADEBQBJAAAAZ29vLTAwMWQwMDAwLTAxLYegrKXnoK2o
7yCvriCv4K7iruKor+Mg4qWrpeSuraAgR09PLTAwMSCu4iAyMDA0LTA1LTA3LmRvY+xZC1gT

----ek-1129--

_EOF

$BOGOLEXER -p -C < "$TMPDIR"/input.2a > "$TMPDIR/output.2a"

##### Test #2b - properly terminated encoded word #####

cat > "$TMPDIR/input.2b" <<_EOF
Return-Path: <pro@blabla.com>
Content-Type: multipart/mixed; boundary="--ek-1129"

----ek-1129
Content-Type: application/x-zip-compressed; name="filename.txt"
Content-Disposition: attachment; filename="=?Windows-1251?B?Z29v?=
	=?Windows-1251?B?5fTu?="
Content-Transfer-Encoding: base64

UEsDBBQAAgAIADyWpzC0Mjdx9ksFAADEBQBJAAAAZ29vLTAwMWQwMDAwLTAxLYegrKXnoK2o
7yCvriCv4K7iruKor+Mg4qWrpeSuraAgR09PLTAwMSCu4iAyMDA0LTA1LTA3LmRvY+xZC1gT

----ek-1129--

_EOF

$BOGOLEXER -p -C < "$TMPDIR"/input.2b > "$TMPDIR/output.2b"

diff "$TMPDIR/output.2a" "$TMPDIR/output.2b"
