#!/bin/sh
-######################################################
#
-# Test bogus headers (no blank line before body, etc.)
-#
-######################################################
+# Test bogus and strange headers
+
. "$MH_TEST_COMMON"
expected=$MH_TEST_DIR/$$.expected
# Write message with bogus header field (missing blank line, really).
-msgfile="$(mhpath b)"
-msgnum="$(basename $msgfile)"
-cat > $msgfile <<EOF
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
Date: Sun, 18 Dec 2005 00:52:39 +0100
From: foo@example.edu
To: bar@example.edu
This is a multi-part message in MIME format.
I am a stupid spammer.
-EOF
-
+!
-# check scan
runandcheck "scan $msgnum" <<!
- 11 2005-12-18 00:52 foo@example.edu test
+??Format error (message $msgnum) in component 5
+ $msgnum 2005-12-18 00:52 foo@example.edu test
!
-
-# check show
runandcheck "show $msgnum" <<!
show: message format error in component #5
!
# check m_getfld() handling of empty header field
+
msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
printf 'Date: Sat, 12 Jan 2013 09:07:01 -0600\nReceived:' >"$msgfile"
+
runandcheck "scan l" <<!
-scan: eof encountered in field "Received"
-??Format error (message 12) in component 2
- 12 2013-01-12 09:07
+??Format error (message $msgnum) in component 2
+ $msgnum 2013-01-12 09:07
!
# check m_getfld() handling of excessively long header field name
-msgfile="$MH_TEST_DIR/Mail/inbox/13"
-cat >"$msgfile" <<EOF
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
Date: Tue, 15 Jan 2013 21:13:12 -0600
ThisHeaderFieldNameIsWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaayTooLong: OK" too long
+??Format error (message $msgnum) in component 2
+ $msgnum 2013-01-15 21:13
+!
+
+
+
+# check m_getfld() handling of header field name with whitespace
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:33:46 -0600
+A header field name with whitespace: foo
+Subject: Will this be printed?
+
+Test
+
+!
+
runandcheck "scan l" <<!
-scan: field name "ThisHeaderFieldNameIsWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaayTooLong" exceeds 997 bytes
-??Format error (message 13) in component 2
- 13 2013-01-15 21:13
+??Format error (message $msgnum) in component 2
+ $msgnum 2013-01-17 19:33
!
-# # Cygwin has a BUFSIZ of 1024 so the error message gets truncated.
-# # Deal with that by grepping to verify that scan showed the proper error.
-# verify_string_in_file() {
-# if grep "$1" "$2" >/dev/null; then
-# :
-# else
-# echo "$0: did not receive expected error message \"$1\""
-# failed=`expr ${failed:-0} + 1`
-# fi
-# }
-# verify_string_in_file 'scan: field name "ThisHeaderFieldNameIsWa' "$actual_err"
-# verify_string_in_file 'exceeds 997' "$actual_err"
-# verify_string_in_file '??Format error (message 13) in component 2' "$actual_err"
-# rm -f "$actual_err"
+# check m_getfld() handling of header field name without a colon
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:33:46 -0600
+A_header_field_name_without_a_colon_..._or_is_this_the_first_line_of_the_body_question-mark
+Subject: Will this be printed?
+
+Test
+!
+
+runandcheck "scan l" <<!
+??Format error (message $msgnum) in component 2
+ $msgnum 2013-01-17 19:33
+!
-# check m_getfld() handling of long header field name without a colon
+# check m_getfld() handling of empty field name
-msgfile="$MH_TEST_DIR/Mail/inbox/14"
-cat >"$msgfile" <<EOF
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
Date: Thu, 17 Jan 2013 19:33:46 -0600
-If a header field name has at least 512 characters without a newline or colon, it will raise a format error in m_getfld(). Here is a test of that. 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901
+: foo
+Subject: Will this be printed?
Test
+!
+
+runandcheck "scan l" <<!
+??Format error (message $msgnum) in component 2
+ $msgnum 2013-01-17 19:33
+!
+
-EOF
+
+
+# check m_getfld() handling of dashed body separator (as in drafts)
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:33:46 -0600
+----------
+Subject: Will this be printed?
+
+Test
+
+!
runandcheck "scan l" <<!
-scan: eol encountered in field "If a header field name has at least 512 characters without a newline or colon, it will raise a format error in m_getfld(). Here is a test of that. 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901"
-??Format error (message 14) in component 2
- 14 2013-01-17 19:33
+ $msgnum 2013-01-17 19:33
!
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:33:46 -0600
+-
+Subject: Will this be printed?
+
+Test
+
+!
+
+runandcheck "scan l" <<!
+ $msgnum 2013-01-17 19:33
+!
+
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:33:46 -0600
+-----foo
+Subject: Will this be printed?
+
+Test
+
+!
+
+runandcheck "scan l" <<!
+??Format error (message $msgnum) in component 2
+ $msgnum 2013-01-17 19:33
+!
+
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:33:46 -0600
+-foo
+Subject: Will this be printed?
+
+Test
+
+!
+
+runandcheck "scan l" <<!
+??Format error (message $msgnum) in component 2
+ $msgnum 2013-01-17 19:33
+!
+
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:33:46 -0600
+--- --- ---
+Subject: Will this be printed?
+
+Test
+
+!
+
+runandcheck "scan l" <<!
+??Format error (message $msgnum) in component 2
+ $msgnum 2013-01-17 19:33
+!
+
+
+# valid headers that might be treated as body separators but should not
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:33:46 -0600
+-: strange but valid header name
+-------: also a valid header name
+-dash: nothing special if it start with a dash
+-------dash: or with many dashes
+-..|.-|...|....: could even be morse code ;-)
+sort</etc/passwd|lp&&date: ... o ar command lins *eek*
+Subject: This will be printed!
+
+Test
+
+!
+
+runandcheck "scan l" <<!
+ $msgnum 2013-01-17 19:33 This will be printed!
+!