]> diplodocus.org Git - nmh/blob - test/bad-input/test-header
back out use of RFC 2047 decoding on the filename
[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 format
39 EOF
40 run_prog scan -width 80 last > "$actual" 2>&1
41 check "$expected" "$actual" : scan with bogus header field
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 run_prog show last > "$actual" 2>&1
58 check "$expected" "$actual" : "show (mhl) with bogus header field"
59
60 # check mhshow
61 cat >"$expected" <<EOF
62 [ Message inbox:11 ]
63 Date: Sun, 18 Dec 2005 00:52:39 +0100
64 To: bar@example.edu
65 From: foo@example.edu
66 Subject: test
67
68
69 [ part - text/plain - 70B ]
70
71 This is a multi-part message in MIME format.
72
73 I am a stupid spammer.
74 EOF
75 run_prog mhshow last > "$actual" 2>&1
76 check "$expected" "$actual" : mhshow with bogus header field
77
78 # check m_getfld() handling of empty header field
79 msgfile="$MH_TEST_DIR/Mail/inbox/12"
80 printf 'Date: Sat, 12 Jan 2013 09:07:01 -0600\nReceived:' >"$msgfile"
81 cat >"$expected" <<EOF
82 12 01/12
83 EOF
84 cat >"$expected_err" <<EOF
85 scan: eof encountered in field "Received"
86 ??Format error (message 12) in component 2
87 EOF
88
89 run_prog scan -width 13 last >"$actual" 2>"$actual_err"
90 check "$expected" "$actual" : m_getfld, empty header output
91 check "$expected_err" "$actual_err" : m_getfld, empty header error
92
93 # check m_getfld() handling of excessively long header field name
94 msgfile="$MH_TEST_DIR/Mail/inbox/13"
95 cat >"$msgfile" <<EOF
96 Date: Tue, 15 Jan 2013 21:13:12 -0600
97 ThisHeaderFieldNameIsWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaayTooLong: OK
98 EOF
99 cat >"$expected" <<EOF
100 13 01/15
101 EOF
102
103 run_prog scan -width 13 last >"$actual" 2>"$actual_err"
104 check "$expected" "$actual" : m_getfld with excessively long header field name
105 # Cygwin has a BUFSIZ of 1024 so the error message gets truncated.
106 # Deal with that by grepping to verify that scan showed the proper error.
107 verify_string_in_file() {
108 if grep "$1" "$2" >/dev/null; then
109 :
110 else
111 echo "$0: did not receive expected error message \"$1\""
112 failed=`expr ${failed:-0} + 1`
113 fi
114 }
115 verify_string_in_file 'scan: field name "ThisHeaderFieldNameIsWa' "$actual_err"
116 verify_string_in_file 'exceeds 997' "$actual_err"
117 verify_string_in_file '??Format error (message 13) in component 2' "$actual_err"
118 rm -f "$actual_err"
119
120 # check m_getfld() handling of long header field name without a colon
121 msgfile="$MH_TEST_DIR/Mail/inbox/14"
122 cat >"$msgfile" <<EOF
123 Date: Thu, 17 Jan 2013 19:33:46 -0600
124 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
125
126 Test
127
128
129 EOF
130 cat >"$expected" <<EOF
131 14 01/17
132 EOF
133 cat >"$expected_err" <<EOF
134 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"
135 ??Format error (message 14) in component 2
136 EOF
137
138 run_prog scan -width 13 last >"$actual" 2>"$actual_err"
139 check "$expected" "$actual" : m_getfld with long header, no colon output
140 check "$expected_err" "$actual_err" : m_getfld with long header, no colon error
141
142
143 exit $failed