Fix tests to run on OpenBSD
[mmh] / test / tests / show / test-longlines
1 #!/bin/sh
2 ######################################################
3 #
4 # Test long header line handling (998 chars)
5 #
6 ######################################################
7
8 set -e
9
10 expected=$MH_TEST_DIR/$$.expected
11 actual=$MH_TEST_DIR/$$.actual
12
13 genlongsubject() {
14         len="${1:-998}"
15         awk -v len="$len" 'BEGIN {
16                 prefix = "Subject: " len " "
17                 while (i++<len) {
18                         s = s "x"
19                 }
20                 print prefix substr(s, length(prefix) + 1)
21         }'
22 }
23
24 addcr() {
25         awk '{printf($0 "\r\n")}'
26 }
27
28
29 len=997
30
31 # Write message with long header line
32 msgfile=$(mhpath b)
33 msgnum=$(basename $msgfile)
34 cat > $msgfile <<-EOF
35 From: foo@example.edu
36 To: bar@example.edu
37 `genlongsubject $len`
38 Date: Sun, 15 Jul 2018 12:26:59 +0200
39
40 foo
41 EOF
42
43 # check it
44 cat > $expected <<-EOF
45 Date:    Sun, 15 Jul 2018 12:26:59 +0200
46 From:    foo@example.edu
47 To:      bar@example.edu
48 `genlongsubject $len`
49
50 part       text/plain                   4
51 foo
52 EOF
53
54 COLUMNS=2000 show $msgnum > $actual 2>&1
55 diff -u $expected $actual
56
57
58 len=998
59
60 # Write message with long header line
61 msgfile=$(mhpath b)
62 msgnum=$(basename $msgfile)
63 cat > $msgfile <<-EOF
64 From: foo@example.edu
65 To: bar@example.edu
66 `genlongsubject $len`
67 Date: Sun, 15 Jul 2018 12:26:59 +0200
68
69 foo
70 EOF
71
72 # check it
73 cat > $expected <<-EOF
74 Date:    Sun, 15 Jul 2018 12:26:59 +0200
75 From:    foo@example.edu
76 To:      bar@example.edu
77 `genlongsubject $len`
78
79 part       text/plain                   4
80 foo
81 EOF
82
83 COLUMNS=2000 show $msgnum > $actual 2>&1
84 diff -u $expected $actual
85
86
87 len=999
88
89 # Write message with long header line
90 msgfile=$(mhpath b)
91 msgnum=$(basename $msgfile)
92 cat > $msgfile <<-EOF
93 From: foo@example.edu
94 To: bar@example.edu
95 `genlongsubject $len`
96 Date: Sun, 15 Jul 2018 12:26:59 +0200
97
98 foo
99 EOF
100
101 # check it
102 cat > $expected <<-EOF
103 mhl: format error in message 13
104 part       text/plain                   4
105 foo
106 EOF
107
108 COLUMNS=2000 show $msgnum > $actual 2>&1
109 diff -u $expected $actual
110
111
112
113 # now with CRLF
114
115
116 len=998
117
118 # Write message with long header line
119 msgfile=$(mhpath b)
120 msgnum=$(basename $msgfile)
121 cat > $msgfile <<-EOF
122 From: foo@example.edu
123 To: bar@example.edu
124 `genlongsubject $len | addcr`
125 Date: Sun, 15 Jul 2018 12:26:59 +0200
126
127 foo
128 EOF
129
130 # check it
131 cat > $expected <<-EOF
132 Date:    Sun, 15 Jul 2018 12:26:59 +0200
133 From:    foo@example.edu
134 To:      bar@example.edu
135 `genlongsubject $len`
136
137 part       text/plain                   4
138 foo
139 EOF
140
141 COLUMNS=2000 show $msgnum > $actual 2>&1
142 diff -u $expected $actual
143
144
145 len=999
146
147 # Write message with long header line
148 msgfile=$(mhpath b)
149 msgnum=$(basename $msgfile)
150 cat > $msgfile <<-EOF
151 From: foo@example.edu
152 To: bar@example.edu
153 `genlongsubject $len | addcr`
154 Date: Sun, 15 Jul 2018 12:26:59 +0200
155
156 foo
157 EOF
158
159 # check it
160 cat > $expected <<-EOF
161 mhl: format error in message 15
162 part       text/plain                   4
163 foo
164 EOF
165
166 COLUMNS=2000 show $msgnum > $actual 2>&1
167 diff -u $expected $actual
168