Adjust tests/bad-input/test-header for m_gefld2()
[mmh] / test / tests / bad-input / test-header
index 4832106..f0e7a45 100644 (file)
@@ -1,21 +1,17 @@
 #!/bin/sh
+#
+# Test bogus and strange headers
 
-# TODO: Move to a common file tests can source; need more framework...
-failed=0
-check() {
-    diff -u $expected $actual
-    if [ $? -ne 0 ]; then
-        failed=$((failed + 1))
-    fi
-}
+
+. "$MH_TEST_COMMON"
 
 expected=$MH_TEST_DIR/$$.expected
-actual=$MH_TEST_DIR/$$.actual
 
 # Write message with bogus header field (missing blank line, really).
-msgfile=$(mhpath new)
-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
@@ -23,46 +19,215 @@ Subject: test
 This is a multi-part message in MIME format.
 
 I am a stupid spammer.
-EOF
-
-# check scan
-cat > $expected <<EOF
-  11  12/18 foo@example.edu    test<<This is a multi-part message in MIME forma
-EOF
-scan $msgnum > $actual 2>&1
-check
-
-# check show (mhl)
-cat > $expected <<EOF
-(Message inbox:11)
-
-Date:    Sun, 18 Dec 2005 00:52:39 +0100
-To:      bar@example.edu
-From:    foo@example.edu
-Subject: test
+!
 
+runandcheck "scan $msgnum" <<!
+??Format error (message $msgnum) in component 5
+  $msgnum  2005-12-18 00:52  foo@example.edu    test
+!
 
-This is a multi-part message in MIME format.
+runandcheck "show $msgnum" <<!
+show: message format error in component #5
+mhl: format error in message 11
+part       text/plain                  23
+I am a stupid spammer.
+!
 
 
-I am a stupid spammer.
-EOF
-show $msgnum > $actual 2>&1
-check
-
-# check mhshow
-cat > $expected <<EOF
-Date:    Sun, 18 Dec 2005 00:52:39 +0100
-To:      bar@example.edu
-From:    foo@example.edu
-Subject: test
 
+# check m_getfld() handling of empty header field
 
-part       text/plain                  70
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+printf 'Date: Sat, 12 Jan 2013 09:07:01 -0600\nReceived:' >"$msgfile"
 
-This is a multi-part message in MIME format.
+runandcheck "scan l" <<!
+??Format error (message $msgnum) in component 2
+  $msgnum  2013-01-12 09:07                     
+!
 
-I am a stupid spammer.
-EOF
-mhshow -nopause $msgnum > $actual 2>&1
-check
+
+
+# check m_getfld() handling of excessively long header field name
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Tue, 15 Jan 2013 21:13:12 -0600
+ThisHeaderFieldNameIsWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaayTooLong: OK
+!
+
+runandcheck "scan l" <<!
+??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" <<!
+??Format error (message $msgnum) in component 2
+  $msgnum  2013-01-17 19:33                     Will this be printed?
+!
+
+
+
+# check m_getfld() handling of header field name without a colon
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:34: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:34                     Will this be printed?
+!
+
+
+
+# check m_getfld() handling of empty field name
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:35:46 -0600
+: foo
+Subject: Will this be printed?
+
+Test
+
+!
+
+runandcheck "scan l" <<!
+??Format error (message $msgnum) in component 2
+  $msgnum  2013-01-17 19:35                     Will this be printed?
+!
+
+
+
+
+# check m_getfld() handling of dashed body separator (as in drafts)
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:36:46 -0600
+----------
+Subject: Will this be printed?
+
+Test
+
+!
+
+runandcheck "scan l" <<!
+  $msgnum  2013-01-17 19:36                     
+!
+
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:37:46 -0600
+-
+Subject: Will this be printed?
+
+Test
+
+!
+
+runandcheck "scan l" <<!
+  $msgnum  2013-01-17 19:37                     
+!
+
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:39:46 -0600
+-----foo
+Subject: Will this be printed?
+
+Test
+
+!
+
+runandcheck "scan l" <<!
+??Format error (message $msgnum) in component 2
+  $msgnum  2013-01-17 19:39                     Will this be printed?
+!
+
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:40:46 -0600
+-foo
+Subject: Will this be printed?
+
+Test
+
+!
+
+runandcheck "scan l" <<!
+??Format error (message $msgnum) in component 2
+  $msgnum  2013-01-17 19:40                     Will this be printed?
+!
+
+
+msgfile="`mhpath b`"
+msgnum="${msgfile##*/}"
+cat >"$msgfile" <<!
+Date: Thu, 17 Jan 2013 19:41:46 -0600
+--- --- ---
+Subject: Will this be printed?
+
+Test
+
+!
+
+runandcheck "scan l" <<!
+??Format error (message $msgnum) in component 2
+  $msgnum  2013-01-17 19:41                     Will this be printed?
+!
+
+
+# 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:42: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:42                     This will be printed!
+!