f6ae12661235b9b0780e89ec44db9ef3d0180054
[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 # Ensure lines won't get folded
30 echo "mhl: -width 2000" >> "$MMH/profile"
31 trap 'printf "/^mhl:/d\nw\nq\n" | ed - "$MMH/profile"' 0 1 2 15
32
33
34 len=997
35
36 # Write message with long header line
37 msgfile=$(mhpath b)
38 msgnum=$(basename $msgfile)
39 cat > $msgfile <<-EOF
40 From: foo@example.edu
41 To: bar@example.edu
42 `genlongsubject $len`
43 Date: Sun, 15 Jul 2018 12:26:59 +0200
44
45 foo
46 EOF
47
48 # check it
49 cat > $expected <<-EOF
50 Date:    Sun, 15 Jul 2018 12:26:59 +0200
51 From:    foo@example.edu
52 To:      bar@example.edu
53 `genlongsubject $len`
54
55 part       text/plain                   4
56 foo
57 EOF
58
59 COLUMNS=2000 show $msgnum > $actual 2>&1
60 diff -u $expected $actual
61
62
63 len=998
64
65 # Write message with long header line
66 msgfile=$(mhpath b)
67 msgnum=$(basename $msgfile)
68 cat > $msgfile <<-EOF
69 From: foo@example.edu
70 To: bar@example.edu
71 `genlongsubject $len`
72 Date: Sun, 15 Jul 2018 12:26:59 +0200
73
74 foo
75 EOF
76
77 # check it
78 cat > $expected <<-EOF
79 Date:    Sun, 15 Jul 2018 12:26:59 +0200
80 From:    foo@example.edu
81 To:      bar@example.edu
82 `genlongsubject $len`
83
84 part       text/plain                   4
85 foo
86 EOF
87
88 COLUMNS=2000 show $msgnum > $actual 2>&1
89 diff -u $expected $actual
90
91
92 len=999
93
94 # Write message with long header line
95 msgfile=$(mhpath b)
96 msgnum=$(basename $msgfile)
97 cat > $msgfile <<-EOF
98 From: foo@example.edu
99 To: bar@example.edu
100 `genlongsubject $len`
101 Date: Sun, 15 Jul 2018 12:26:59 +0200
102
103 foo
104 EOF
105
106 # check it
107 cat > $expected <<-EOF
108 mhl: format error in message 13
109 part       text/plain                   4
110 foo
111 EOF
112
113 COLUMNS=2000 show $msgnum > $actual 2>&1
114 diff -u $expected $actual
115
116
117
118 # now with CRLF
119
120
121 len=998
122
123 # Write message with long header line
124 msgfile=$(mhpath b)
125 msgnum=$(basename $msgfile)
126 cat > $msgfile <<-EOF
127 From: foo@example.edu
128 To: bar@example.edu
129 `genlongsubject $len | addcr`
130 Date: Sun, 15 Jul 2018 12:26:59 +0200
131
132 foo
133 EOF
134
135 # check it
136 cat > $expected <<-EOF
137 Date:    Sun, 15 Jul 2018 12:26:59 +0200
138 From:    foo@example.edu
139 To:      bar@example.edu
140 `genlongsubject $len`
141
142 part       text/plain                   4
143 foo
144 EOF
145
146 COLUMNS=2000 show $msgnum > $actual 2>&1
147 diff -u $expected $actual
148
149
150 len=999
151
152 # Write message with long header line
153 msgfile=$(mhpath b)
154 msgnum=$(basename $msgfile)
155 cat > $msgfile <<-EOF
156 From: foo@example.edu
157 To: bar@example.edu
158 `genlongsubject $len | addcr`
159 Date: Sun, 15 Jul 2018 12:26:59 +0200
160
161 foo
162 EOF
163
164 # check it
165 cat > $expected <<-EOF
166 mhl: format error in message 15
167 part       text/plain                   4
168 foo
169 EOF
170
171 COLUMNS=2000 show $msgnum > $actual 2>&1
172 diff -u $expected $actual
173