test_skip 'test-textcharset requires that nmh have been built with iconv'
fi
-require_locale en_US.utf-8 en_US.utf8
-LC_ALL=en_US.UTF-8; export LC_ALL
+require_locale en_US.UTF-8 en_US.UTF8 en_US.utf-8 en_US.utf8
expected="$MH_TEST_DIR"/$$.expected
actual="$MH_TEST_DIR"/$$.actual
# check charset conversion
msgfile=`mhpath new`
+msgnum=`basename $msgfile`
cat >"$msgfile" <<'EOF'
From: foo@example.edu
To: bar@example.edu
4 =F7 2 =3D 2
EOF
-cat >"$expected" <<'EOF'
+cat >"$expected" <<EOF
+[ Message inbox:$msgnum ]
Date: Sun, 18 Dec 2005 00:52:39 +0100
To: bar@example.edu
From: foo@example.edu
EOF
run_prog mhshow last >"$actual" 2>&1
-check "$expected" "$actual"
+check "$expected" "$actual" : check charset conversion
cat >>"$MH" <<'EOF'
mhshow-show-text/plain: echo %{charset}
# check expansion of %{charset} by itself
msgfile=`mhpath new`
+msgnum=`basename $msgfile`
cat >"$msgfile" <<'EOF'
From: foo@example.edu
To: bar@example.edu
4 =F7 2 =3D 2
EOF
-cat >"$expected" <<'EOF'
+cat >"$expected" <<EOF
+[ Message inbox:$msgnum ]
Date: Sun, 18 Dec 2005 00:52:39 +0100
To: bar@example.edu
From: foo@example.edu
EOF
run_prog mhshow last >"$actual" 2>&1
-check "$expected" "$actual"
+check "$expected" "$actual" : check %{charset} by itself
# check expansion of empty %{charset} by itself
msgfile=`mhpath new`
+omsgnum=$msgnum
+msgnum=`basename $msgfile`
cat >"$msgfile" <<'EOF'
From: foo@example.edu
To: bar@example.edu
4 =F7 2 =3D 2
EOF
-cat >"$expected" <<'EOF'
+cat >"$expected" <<EOF
+[ Message inbox:$msgnum ]
Date: Sun, 18 Dec 2005 00:52:39 +0100
To: bar@example.edu
From: foo@example.edu
EOF
run_prog mhshow last >"$actual" 2>&1
-check "$expected" "$actual"
+check "$expected" "$actual" : check empty %{charset} by itself
grep -v 'mhshow-show-text/plain:' "$MH" >"$MH.new"
EOF
# check expansion of embedded %{charset} with no text following
-cat >"$expected" <<'EOF'
+cat >"$expected" <<EOF
+[ Message inbox:$omsgnum ]
Date: Sun, 18 Dec 2005 00:52:39 +0100
To: bar@example.edu
From: foo@example.edu
-I UTF-8
EOF
-run_prog mhshow prev >"$actual" 2>&1
-check "$expected" "$actual"
+run_prog mhshow prev >"$actual" 2>&1 # NB: "mhshow prev" !!!
+check "$expected" "$actual" : check embedded %{charset} with no text
# check expansion of empty embedded %{charset} with no text following
-cat >"$expected" <<'EOF'
+cat >"$expected" <<EOF
+[ Message inbox:$msgnum ]
Date: Sun, 18 Dec 2005 00:52:39 +0100
To: bar@example.edu
From: foo@example.edu
EOF
run_prog mhshow last >"$actual" 2>&1
-check "$expected" "$actual"
+check "$expected" "$actual" : check empty embedded %{charset} with no text following
sed -e 's%\(mhshow-show-text/plain:.*\)%\1 file%' "$MH" >"$MH.new"
mv -f "$MH.new" "$MH"
# check expansion of embedded %{charset} with text following
-cat >"$expected" <<'EOF'
+cat >"$expected" <<EOF
+[ Message inbox:$omsgnum ]
Date: Sun, 18 Dec 2005 00:52:39 +0100
To: bar@example.edu
From: foo@example.edu
-I UTF-8 file
EOF
-run_prog mhshow prev >"$actual" 2>&1
-check "$expected" "$actual"
+run_prog mhshow prev >"$actual" 2>&1 # NB: "mhshow prev" !!!
+check "$expected" "$actual" : check embedded %{charset} with text following
# check expansion of empty embedded %{charset} with text following
-cat >"$expected" <<'EOF'
+cat >"$expected" <<EOF
+[ Message inbox:$msgnum ]
Date: Sun, 18 Dec 2005 00:52:39 +0100
To: bar@example.edu
From: foo@example.edu
EOF
run_prog mhshow last >"$actual" 2>&1
-check "$expected" "$actual"
+check "$expected" "$actual" : check empty embedded %{charset} with text following
sed -e 's/charset/method/g' "$MH" >"$MH.new"
# check parameter value quoting
msgfile=`mhpath new`
+msgnum=`basename $msgfile`
cat >"$msgfile" <<'EOF'
From: foo@example.edu
To: bar@example.edu
4 =F7 2 =3D 2
EOF
-cat >"$expected" <<'EOF'
+cat >"$expected" <<EOF
+[ Message inbox:$msgnum ]
+EOF
+cat >>"$expected" <<'EOF'
Date: Sun, 18 Dec 2005 00:52:39 +0100
To: bar@example.edu
From: foo@example.edu
EOF
run_prog mhshow last >"$actual" 2>&1
-check "$expected" "$actual"
+check "$expected" "$actual" : check parameter value quoting
sed -e 's/method/unknown/g' "$MH" >"$MH.new"
# check that unknown parameter is not expanded
msgfile=`mhpath new`
+msgnum=`basename $msgfile`
cat >"$msgfile" <<'EOF'
From: foo@example.edu
To: bar@example.edu
4 =F7 2 =3D 2
EOF
-cat >"$expected" <<'EOF'
+cat >"$expected" <<EOF
+[ Message inbox:$msgnum ]
Date: Sun, 18 Dec 2005 00:52:39 +0100
To: bar@example.edu
From: foo@example.edu
EOF
run_prog mhshow last >"$actual" 2>&1
-check "$expected" "$actual"
+check "$expected" "$actual" : check unknown parameter is not expanded
grep -v '^mhshow-show-text/plain: ' "$MH" >>"$MH.new"
# check parameter value quoting with text following
msgfile=`mhpath new`
+msgnum=`basename $msgfile`
cat >"$msgfile" <<'EOF'
From: foo@example.edu
To: bar@example.edu
This is a test.
EOF
-cat >"$expected" <<'EOF'
+cat >"$expected" <<EOF
+[ Message inbox:$msgnum ]
Date: Sun, 18 Dec 2005 00:52:39 +0100
To: bar@example.edu
From: foo@example.edu
EOF
run_prog mhshow last >"$actual" 2>&1
-check "$expected" "$actual"
+check "$expected" "$actual" : parameter value quoting with text following
+
+# check malicious parameter value quoting
+msgfile=`mhpath new`
+msgnum=`basename $msgfile`
+cat >"$msgfile" <<'EOF'
+Subject: shows difficulty of quoting with /bin/sh -c
+MIME-Version: 1.0
+Content-Type: text/html; charset="oops'; echo should not see this!"
+
+EOF
+
+cat >"$expected" <<EOF
+[ part - text/html - 0B ]
+EOF
+
+run_prog mhshow -noheader -form mhl.null last 2>&1 | squeeze_whitespace >"$actual"
+check "$expected" "$actual" : malicious parameter value quoting
#
# test a large file that needs to be converted to UTF-8
grep -v '^mhshow-show-text/plain: ' "$MH" >>"$MH.new"
mv -f "$MH.new" "$MH"
msgfile=`mhpath new`
+msgnum=`basename $msgfile`
cat >"$msgfile" <<'EOF'
From: foo@example.edu
To: bar@example.edu
=93How strange!=94 she exclaimed, drawing a long breath.
EOF
-cat >"$expected" <<'EOF'
+cat >"$expected" <<EOF
+[ Message inbox:$msgnum ]
Date: Sun, 18 Dec 2005 00:52:39 +0100
To: bar@example.edu
From: foo@example.edu
EOF
run_prog mhshow last >"$actual" 2>&1
-check "$expected" "$actual"
+check "$expected" "$actual" : large file conversion to UTF-8
exit $failed