]> diplodocus.org Git - nmh/blob - test/bad-input/test-header
More replacements of mh_strcasecmp() with strcasecmp().
[nmh] / test / bad-input / test-header
1 #!/bin/sh
2 ######################################################
3 #
4 # Test bogus headers (no blank line before body, etc.)
5 #
6 ######################################################
7
8 set -e
9
10 if test -z "${MH_OBJ_DIR}"; then
11 srcdir=`dirname "$0"`/../..
12 MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
13 fi
14
15 . "$MH_OBJ_DIR/test/common.sh"
16
17 setup_test
18
19 expected="$MH_TEST_DIR/$$.expected"
20 expected_err="$MH_TEST_DIR/$$.expected_err"
21 actual="$MH_TEST_DIR/$$.actual"
22 actual_err="$MH_TEST_DIR/$$.actual_err"
23
24 # Write message with bogus header field (missing blank line, really).
25 msgfile="$MH_TEST_DIR/Mail/inbox/11"
26 cat >"$msgfile" <<EOF
27 Date: Sun, 18 Dec 2005 00:52:39 +0100
28 From: foo@example.edu
29 To: bar@example.edu
30 Subject: test
31 This is a multi-part message in MIME format.
32
33 I am a stupid spammer.
34 EOF
35
36 # check scan
37 cat >"$expected" <<EOF
38 11 12/18 foo@example.edu test<<This is a multi-part message in MIME forma
39 EOF
40 scan -width 80 last > "$actual" 2>&1
41 check "$expected" "$actual"
42
43 # check show (mhl)
44 cat >"$expected" <<EOF
45 (Message inbox:11)
46
47 Date: Sun, 18 Dec 2005 00:52:39 +0100
48 To: bar@example.edu
49 From: foo@example.edu
50 Subject: test
51
52
53 This is a multi-part message in MIME format.
54
55 I am a stupid spammer.
56 EOF
57 show last > "$actual" 2>&1
58 check "$expected" "$actual"
59
60 # check mhshow
61 cat >"$expected" <<EOF
62 Date: Sun, 18 Dec 2005 00:52:39 +0100
63 To: bar@example.edu
64 From: foo@example.edu
65 Subject: test
66
67
68 part text/plain 70
69
70 This is a multi-part message in MIME format.
71
72 I am a stupid spammer.
73 EOF
74 mhshow -nopause last > "$actual" 2>&1
75 check "$expected" "$actual"
76
77 # check m_getfld() handling of empty header field
78 msgfile="$MH_TEST_DIR/Mail/inbox/12"
79 printf 'Date: Sat, 12 Jan 2013 09:07:01 -0600\nReceived:' >"$msgfile"
80 cat >"$expected" <<EOF
81 12 01/12
82 EOF
83 cat >"$expected_err" <<EOF
84 scan: eof encountered in field "Received"
85 ??Format error (message 12) in component 2
86 EOF
87
88 scan -width 13 last >"$actual" 2>"$actual_err"
89 check "$expected" "$actual"
90 check "$expected_err" "$actual_err"
91
92 # check m_getfld() handling of excessively long header field name
93 msgfile="$MH_TEST_DIR/Mail/inbox/13"
94 cat >"$msgfile" <<EOF
95 Date: Tue, 15 Jan 2013 21:13:12 -0600
96 ThisHeaderFieldNameIsWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaayTooLong: OK
97 EOF
98 cat >"$expected" <<EOF
99 13 01/15
100 EOF
101
102 scan -width 13 last >"$actual" 2>"$actual_err"
103 check "$expected" "$actual"
104 # Cygwin has a BUFSIZ of 1024 so the error message gets truncated.
105 # Deal with that by grepping to verify that scan showed the proper error.
106 verify_string_in_file() {
107 if grep "$1" "$2" >/dev/null; then
108 :
109 else
110 echo "$0: did not receive expected error message \"$1\""
111 failed=`expr ${failed:-0} + 1`
112 fi
113 }
114 verify_string_in_file 'scan: field name "ThisHeaderFieldNameIsWa' "$actual_err"
115 verify_string_in_file 'exceeds 997' "$actual_err"
116 verify_string_in_file '??Format error (message 13) in component 2' "$actual_err"
117 rm -f "$actual_err"
118
119 # check m_getfld() handling of long header field name without a colon
120 msgfile="$MH_TEST_DIR/Mail/inbox/14"
121 cat >"$msgfile" <<EOF
122 Date: Thu, 17 Jan 2013 19:33:46 -0600
123 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
124
125 Test
126
127
128 EOF
129 cat >"$expected" <<EOF
130 14 01/17
131 EOF
132 cat >"$expected_err" <<EOF
133 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"
134 ??Format error (message 14) in component 2
135 EOF
136
137 scan -width 13 last >"$actual" 2>"$actual_err"
138 check "$expected" "$actual"
139 check "$expected_err" "$actual_err"
140
141
142 exit $failed