]> diplodocus.org Git - nmh/blob - test/mhfixmsg/test-mhfixmsg
Merged two adjacent if (verbose) blocks.
[nmh] / test / mhfixmsg / test-mhfixmsg
1 #!/bin/sh
2 ######################################################
3 #
4 # Test mhfixmsg
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 . "${srcdir}/test/post/test-post-common.sh"
16
17 #### Make sure that html-to-text conversion is what we expect.
18 require_locale en_US.utf-8 en_US.utf8
19 LC_ALL=en_US.UTF-8; export LC_ALL
20
21 expected="$MH_TEST_DIR/test-mhfixmsg$$.expected"
22 expected_err="$MH_TEST_DIR/test-mhfixmsg$$.expected_err"
23 actual="$MH_TEST_DIR/test-mhfixmsg$$.actual"
24 actual_err="$MH_TEST_DIR/test-mhfixmsg$$.actual_err"
25
26 if grep mhfixmsg-format-text/html "${MH_TEST_DIR}/Mail/mhn.defaults" \
27 >/dev/null; then
28 can_reformat_texthtml=1
29 if grep 'mhfixmsg-format-text/html.*w3m' "${MH_TEST_DIR}/Mail/mhn.defaults" \
30 >/dev/null; then
31 #### w3m uses $HOME/.w3m/, and creates it if it doesn't exist. To
32 #### support testing with non-writeable $HOME, and to not leave
33 #### relics from this test if it is writeable but doesn't already
34 #### have a .w3m, and to not depend on whatever is in that if it
35 #### does already exist, overwrite $HOME if using w3m.
36 HOME="$MHTMPDIR"; export HOME
37 fi
38 else
39 echo "$0: skipping -reformat check because no text browser was found"
40 can_reformat_texthtml=0
41 fi
42
43
44 # check -help
45 cat >"$expected" <<EOF
46 Usage: mhfixmsg [+folder] [msgs] [switches]
47 switches are:
48 -decodetext 8bit|7bit
49 -nodecodetext
50 -[no]textcharset
51 -[no]reformat
52 -[no]replacetextplain
53 -[no]fixboundary
54 -[no]fixcte
55 -file file
56 -outfile file
57 -rmmproc program
58 -normmproc
59 -[no]changecur
60 -[no]verbose
61 -version
62 -help
63 EOF
64
65 run_prog mhfixmsg -help >"$actual" 2>&1
66 check "$expected" "$actual"
67
68
69 # check -version
70 case `mhfixmsg -version` in
71 mhfixmsg\ --*) ;;
72 *) printf '%s: mhfixmsg -version generated unexpected output\n' "$0" >&2
73 failed=`expr ${failed:-0} + 1`;;
74 esac
75
76
77 # check that non-MIME messages aren't modified
78 # check -outfile
79 run_test 'mhfixmsg first -outfile '"$actual" ''
80 check "`mhpath first`" "$actual" 'keep first'
81
82
83 # check that non-MIME messages with no bodies aren't modified
84 # check -outfile
85 cat >`mhpath new` <<EOF
86 From: Test <test@example.com>
87 To: Some User <user@example.com>
88 Date: Fri, 29 Sep 2006 00:00:00
89 Message-Id: @test.nmh
90 Subject: message with no body
91 EOF
92
93 run_test 'mhfixmsg last -outfile '"$actual" ''
94 check "`mhpath last`" "$actual"
95
96
97 # check -nofixcte
98 cat >"$MH_TEST_DIR"/Mail/inbox/11 <<EOF
99 From: Anon
100 To: Mailinglist
101 Subject: =?ISO-8859-15?Q?Re=3A_H=E5lla_linuxsystem_uppdaterade?=
102 User-Agent: Alpine 2.00 (DEB 1167 2008-08-23)
103 MIME-Version: 1.0
104 Content-Type: MULTIPART/MIXED;
105 BOUNDARY="----=_NextPart_000_0000_00000000.00000000"
106 Content-Transfer-Encoding: QUOTED-PRINTABLE
107
108 This message is in MIME format. The first part should be readable
109 text,
110 while the remaining parts are likely unreadable without MIME-aware
111 tools.
112
113 ------=_NextPart_000_0000_00000000.00000000
114 Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-15
115 Content-Transfer-Encoding: 8BIT
116
117 Some text in swedish.
118
119 Varf=C3=B6r inte anv=C3=A4nda...
120
121 ------=_NextPart_000_0000_00000000.00000000--
122
123 And some text after the last part.
124 EOF
125
126 cp -p "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/12
127
128 run_test 'mhfixmsg last -nofixcte' ''
129 check "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/12 'keep first'
130
131
132 # check -fixcte (enabled by default): fixup of erroneous C-T-E in multipart
133 # check -verbose
134 cat >"$expected" <<EOF
135 From: Anon
136 To: Mailinglist
137 Subject: =?ISO-8859-15?Q?Re=3A_H=E5lla_linuxsystem_uppdaterade?=
138 User-Agent: Alpine 2.00 (DEB 1167 2008-08-23)
139 MIME-Version: 1.0
140 Content-Type: MULTIPART/MIXED;
141 BOUNDARY="----=_NextPart_000_0000_00000000.00000000"
142 Nmh-REPLACED-INVALID-Content-Transfer-Encoding: QUOTED-PRINTABLE
143 Content-Transfer-Encoding: 8bit
144
145 This message is in MIME format. The first part should be readable
146 text,
147 while the remaining parts are likely unreadable without MIME-aware
148 tools.
149
150 ------=_NextPart_000_0000_00000000.00000000
151 Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-15
152 Content-Transfer-Encoding: 8BIT
153
154 Some text in swedish.
155
156 Varf=C3=B6r inte anv=C3=A4nda...
157
158 ------=_NextPart_000_0000_00000000.00000000--
159
160 And some text after the last part.
161 EOF
162
163 run_test 'mhfixmsg last -outfile '"$actual"' -verbose' \
164 "mhfixmsg: 11, replace Content-Transfer-Encoding of \
165 QUOTED-PRINTABLE with 8 bit"
166 check "$expected" "$actual" 'keep first'
167
168
169 # check with no options: checks backup
170 cp "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/11.original
171 folder last >/dev/null
172 run_test 'mhfixmsg' ''
173 check "$expected" "$MH_TEST_DIR"/Mail/inbox/11 'keep first'
174 cp "$MH_TEST_DIR"/Mail/inbox/11.original "$MH_TEST_DIR"/Mail/inbox/11
175 check "$MH_TEST_DIR"/Mail/inbox/,11 "$MH_TEST_DIR"/Mail/inbox/11.original
176
177
178 # check backup with -file
179 cp "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/11.original
180 folder last >/dev/null
181 run_test 'mhfixmsg -file '"$MH_TEST_DIR"/Mail/inbox/11 ''
182 check "$MH_TEST_DIR"/Mail/inbox/11 "$expected" 'keep first'
183 check "$MH_TEST_DIR"/Mail/inbox/,11 "$MH_TEST_DIR"/Mail/inbox/11.original
184
185
186 # check -reformat (enabled by default): addition of text/plain part
187 # to solitary text/html part
188 #
189 prepare_space >"$expected" <<EOF
190 MIME-Version: 1.0
191 From: sender@example.com
192 To: bonquiqui@example.com
193 Subject: rue
194 Date: Sat, 26 Jan 2013 17:37:53 -0500
195 Content-Type: multipart/alternative; boundary="----=_nmh-multipart"
196
197 ------=_nmh-multipart
198 Content-Type: text/plain; charset="Windows-1252"
199 Content-Transfer-Encoding: 8bit
200
201 Need to go! Need ... to ... go!
202
203 ------=_nmh-multipart
204 Content-Type: text/html; charset="Windows-1252"
205 Content-Transfer-Encoding: 8bit
206
207 <html>
208 <head>
209 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
210 <meta name="Generator" content="Microsoft Exchange Server">
211 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
212 </head>
213 <body>
214 <div>
215 <div>Need to go! Need ... to ... go!</div>
216 </body>
217 </html>
218
219 ------=_nmh-multipart--
220 EOF
221
222 cat >"$MH_TEST_DIR"/Mail/inbox/12 <<EOF
223 MIME-Version: 1.0
224 From: sender@example.com
225 To: bonquiqui@example.com
226 Subject: rue
227 Date: Sat, 26 Jan 2013 17:37:53 -0500
228 Content-Type: text/html; charset="Windows-1252"
229 Content-Transfer-Encoding: quoted-printable
230
231 <html>
232 <head>
233 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
234 252">
235 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
236 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
237 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
238 </head>
239 <body>
240 <div>
241 <div>Need to go! Need ... to ... go!</div>
242 </body>
243 </html>
244 EOF
245
246 if [ $can_reformat_texthtml -eq 1 ]; then
247 printf '%s\n' "mhfixmsg: 12, insert text/plain part
248 mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
249 >"$expected.err"
250
251 #### lynx inserts multiple blank lines, so squeeze them.
252 run_prog mhfixmsg last -outfile - -verbose 2>"$actual.err" | \
253 squeeze_lines >"$actual"
254 check "$expected" "$actual" 'ignore space'
255 check "$expected.err" "$actual.err"
256 else
257 rm -f "$expected"
258 fi
259
260
261 # check implicit -file with absolute pathname
262 run_test "mhfixmsg `mhpath last` -outfile /dev/null" ''
263
264
265 # check handling of boundary string that appears in message body
266 #
267 prepare_space >"$expected" <<EOF
268 MIME-Version: 1.0
269 From: sender@example.com
270 To: bonquiqui@example.com
271 Subject: rue
272 Date: Sat, 26 Jan 2013 17:37:53 -0500
273 Content-Type: multipart/alternative; boundary="----=_nmh-multipart-3"
274
275 ------=_nmh-multipart-3
276 Content-Type: text/plain; charset="Windows-1252"
277 Content-Transfer-Encoding: 8bit
278
279 ------=_nmh-multipart
280 ------=_nmh-multipart-1
281 ------=_nmh-multipart-2
282
283 ------=_nmh-multipart-3
284 Content-Type: text/html; charset="Windows-1252"
285 Content-Transfer-Encoding: 8bit
286
287 <html>
288 <head>
289 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
290 <meta name="Generator" content="Microsoft Exchange Server">
291 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
292 </head>
293 <body>
294 ------=_nmh-multipart<br>
295 ------=_nmh-multipart-1<br>
296 ------=_nmh-multipart-2<br>
297 </body>
298 </html>
299
300 ------=_nmh-multipart-3--
301 EOF
302
303 cat >"$MH_TEST_DIR"/Mail/inbox/12 <<EOF
304 MIME-Version: 1.0
305 From: sender@example.com
306 To: bonquiqui@example.com
307 Subject: rue
308 Date: Sat, 26 Jan 2013 17:37:53 -0500
309 Content-Type: text/html; charset="Windows-1252"
310 Content-Transfer-Encoding: quoted-printable
311
312 <html>
313 <head>
314 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
315 252">
316 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
317 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
318 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
319 </head>
320 <body>
321 ------=3D_nmh-multipart<br>
322 ------=3D_nmh-multipart-1<br>
323 ------=3D_nmh-multipart-2<br>
324 </body>
325 </html>
326 EOF
327
328 if [ $can_reformat_texthtml -eq 1 ]; then
329 printf '%s\n' "mhfixmsg: 12, insert text/plain part
330 mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
331 >"$expected.err"
332
333 #### lynx inserts multiple blank lines, so squeeze them.
334 run_prog mhfixmsg last -outfile - -verbose 2>"$actual.err" | \
335 squeeze_lines >"$actual"
336 check "$expected" "$actual" 'ignore space'
337 check "$expected.err" "$actual.err"
338 else
339 rm -f "$expected"
340 fi
341
342
343 # check -nodecode
344 prepare_space >"$expected" <<EOF
345 MIME-Version: 1.0
346 From: sender@example.com
347 To: bonquiqui@example.com
348 Subject: rue
349 Date: Sat, 26 Jan 2013 17:37:53 -0500
350 Content-Type: multipart/alternative; boundary="----=_nmh-multipart"
351
352 ------=_nmh-multipart
353 Content-Type: text/plain; charset="Windows-1252"
354 Content-Transfer-Encoding: 8bit
355
356 Need to go! Need ... to ... go!
357
358 ------=_nmh-multipart
359 Content-Type: text/html; charset="Windows-1252"
360 Content-Transfer-Encoding: quoted-printable
361
362 <html>
363 <head>
364 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-=
365 1252">
366 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
367 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pa=
368 dding-left: 4pt; border-left: #800000 2px solid; } --></style>
369 </head>
370 <body>
371 <div>
372 <div>Need to go! Need ... to ... go!</div>
373 </body>
374 </html>
375
376 ------=_nmh-multipart--
377 EOF
378
379 cat >"$MH_TEST_DIR"/Mail/inbox/12 <<EOF
380 MIME-Version: 1.0
381 From: sender@example.com
382 To: bonquiqui@example.com
383 Subject: rue
384 Date: Sat, 26 Jan 2013 17:37:53 -0500
385 Content-Type: text/html; charset="Windows-1252"
386 Content-Transfer-Encoding: quoted-printable
387
388 <html>
389 <head>
390 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
391 252">
392 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
393 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
394 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
395 </head>
396 <body>
397 <div>
398 <div>Need to go! Need ... to ... go!</div>
399 </body>
400 </html>
401 EOF
402
403 if [ $can_reformat_texthtml -eq 1 ]; then
404 printf '%s\n' 'mhfixmsg: 12, insert text/plain part' >"$expected.err"
405
406 #### lynx inserts multiple blank lines, so squeeze them.
407 run_prog mhfixmsg last -nodecode -outfile - -verbose 2>"$actual.err" | \
408 squeeze_lines >"$actual"
409 check "$expected" "$actual" 'ignore space'
410 check "$expected.err" "$actual.err"
411 else
412 rm -f "$expected"
413 fi
414
415
416 # check -decode (enabled by default)
417 cat >"$expected" <<EOF
418 To: recipient@example.com
419 From: sender@example.com
420 Subject: mhfixmsg decode test
421 MIME-Version: 1.0
422 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
423
424 ------- =_aaaaaaaaaa0
425 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
426 Content-Disposition: attachment; filename="test4.txt"
427 Content-Transfer-Encoding: 8bit
428
429 This is a text/plain part.
430
431 ------- =_aaaaaaaaaa0--
432 EOF
433
434 cat >`mhpath new` <<EOF
435 To: recipient@example.com
436 From: sender@example.com
437 Subject: mhfixmsg decode test
438 MIME-Version: 1.0
439 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
440
441 ------- =_aaaaaaaaaa0
442 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
443 Content-Disposition: attachment; filename="test4.txt"
444 Content-Transfer-Encoding: base64
445
446 VGhpcyBpcyBhIHRleHQvcGxhaW4gcGFydC4K
447
448 ------- =_aaaaaaaaaa0--
449 EOF
450
451 run_prog mhfixmsg last -outfile "$actual"
452 check "$expected" "$actual"
453
454
455 # check -decode with more complicated content structure
456 cat >$expected <<EOF
457 To: recipient@example.com
458 From: sender@example.com
459 Subject: mhfixmsg decode test 2
460 MIME-Version: 1.0
461 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
462
463 This is additional content before the first subpart of the multipart.
464
465 ------- =_aaaaaaaaaa0
466 Content-Type: multipart/related;
467 type="text/plain"; boundary="subpart__1.1"
468
469 --subpart__1.1
470 Content-Type: text/plain; charset="iso-8859-1"
471 Content-Disposition: attachment; filename="test1.txt"
472
473 This is the first text/plain part, in a subpart.
474
475 --subpart__1.1--
476
477 This is additional content after the last subpart of the multipart.
478
479 ------- =_aaaaaaaaaa0
480 Content-Type: text/plain; charset="iso-8859-1"
481 Content-Disposition: attachment; filename="test2.txt"
482 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
483 Content-Transfer-Encoding: 8bit
484
485 This is the second text/plain part.
486
487 ------- =_aaaaaaaaaa0
488 Content-Type: text/plain; charset="iso-8859-1"
489 Content-Disposition: attachment; filename="test3.txt"
490
491 This is the third text/plain part.
492
493 ------- =_aaaaaaaaaa0
494 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
495 Content-Disposition: attachment; filename="test4.txt"
496 Content-Transfer-Encoding: 8bit
497
498 This is the fourth text/plain part.
499
500 ------- =_aaaaaaaaaa0--
501
502 This is additional content after the last subpart of the multipart.
503 EOF
504
505 cat >`mhpath new` <<EOF
506 To: recipient@example.com
507 From: sender@example.com
508 Subject: mhfixmsg decode test 2
509 MIME-Version: 1.0
510 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
511
512 This is additional content before the first subpart of the multipart.
513
514 ------- =_aaaaaaaaaa0
515 Content-Type: multipart/related;
516 type="text/plain"; boundary="subpart__1.1"
517
518 --subpart__1.1
519 Content-Type: text/plain; charset="iso-8859-1"
520 Content-Disposition: attachment; filename="test1.txt"
521
522 This is the first text/plain part, in a subpart.
523
524 --subpart__1.1--
525
526 This is additional content after the last subpart of the multipart.
527
528 ------- =_aaaaaaaaaa0
529 Content-Type: text/plain; charset="iso-8859-1"
530 Content-Disposition: attachment; filename="test2.txt"
531 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
532 Content-Transfer-Encoding: quoted-printable
533
534 This is the second text/plain part.
535
536 ------- =_aaaaaaaaaa0
537 Content-Type: text/plain; charset="iso-8859-1"
538 Content-Disposition: attachment; filename="test3.txt"
539
540 This is the third text/plain part.
541
542 ------- =_aaaaaaaaaa0
543 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
544 Content-Disposition: attachment; filename="test4.txt"
545 Content-Transfer-Encoding: base64
546
547 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4K
548
549 ------- =_aaaaaaaaaa0--
550
551 This is additional content after the last subpart of the multipart.
552 EOF
553 run_prog mhfixmsg last -outfile "$actual"
554 check "$expected" "$actual"
555
556
557 # check attempted -decode of binary text
558 #### Generated the encoded text below with:
559 #### $ printf '\x0\xbd\xb2=\xbc\n' | base64
560 cat >`mhpath new` <<EOF
561 To: recipient@example.com
562 From: sender@example.com
563 Subject: mhfixmsg attempted binary decode test
564 MIME-Version: 1.0
565 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
566
567 ------- =_aaaaaaaaaa0
568 Content-Type: text/plain; charset="iso-8859-1"; name="nul+square.txt"
569 Content-Transfer-Encoding: base64
570
571 AL2yPbwK
572
573 ------- =_aaaaaaaaaa0--
574 EOF
575
576 cp -p `mhpath last` "$expected"
577 run_prog mhfixmsg last
578 check `mhpath last` "$expected" 'keep first'
579
580
581 # check -decode of binary text
582 printf "%s\x0d\xbd\xb2=\xbc%s" "To: recipient@example.com
583 From: sender@example.com
584 Subject: mhfixmsg binary decode test
585 MIME-Version: 1.0
586 Content-Type: multipart/mixed; boundary=\"----- =_aaaaaaaaaa0\"
587
588 ------- =_aaaaaaaaaa0
589 Content-Type: text/plain; charset=\"iso-8859-1\"; name=\"nul+square.txt\"
590 Content-Transfer-Encoding: binary
591
592 " "
593
594 ------- =_aaaaaaaaaa0--
595 " >"$expected"
596 ## output_content() in mhoutsbr.c can't handle binary content.
597 ## mhfixmsg last -decodetext binary -outfile "$actual"
598 ## check "$expected" "$actual"
599 rm -f "$expected"
600 rmm last
601
602
603 # check that -reformat succeeds when decode of binary text fails
604 prepare_space >"$expected" <<'EOF'
605 MIME-Version: 1.0
606 Date: Thu, 11 Apr 2013 02:47:08 -0700
607 To: <me@example.com>
608 From: <sender@example.com>
609 Subject: body requires binary encoding
610 Content-Type: multipart/alternative; boundary="----=_nmh-multipart"
611
612 ------=_nmh-multipart
613 Content-Type: text/plain; charset="ISO-8859-1"
614 Content-Transfer-Encoding: 8bit
615
616 Mile $0.00
617 Time $78.71
618 State Tax $5.90
619 Vehicle License Fee $1.84
620 State Txn Tax $6.00
621
622 ------=_nmh-multipart
623 Content-Type: text/html; charset="ISO-8859-1"
624 Content-Transfer-Encoding: quoted-printable
625
626 <body>
627 EOF
628
629 cat >`mhpath new` <<'EOF'
630 MIME-Version: 1.0
631 Content-Type: text/html; charset="ISO-8859-1"
632 Content-Transfer-Encoding: quoted-printable
633 Date: Thu, 11 Apr 2013 02:47:08 -0700
634 To: <me@example.com>
635 From: <sender@example.com>
636 Subject: body requires binary encoding
637
638 <body>
639 <table width=3D"325" border=3D"0" cellspacing=3D"0" cellpadding=3D"0">
640 <tr><td><font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" size=
641 =3D"2"><strong>Mile</strong></font></td><td height=3D"3">&nbsp;</td><td ali=
642 gn=3D"right"><font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" =
643 size=3D"2">$0.00</font></td></tr><tr><td><font face=3D"Arial, Helvetica, sa=
644 ns-serif" color=3D"#333333" size=3D"2"><strong>Time</strong></font></td><td=
645 height=3D"3">&nbsp;</td><td align=3D"right"><font face=3D"Arial, Helvetica=
646 , sans-serif" color=3D"#333333" size=3D"2">$78.71</font></td></tr><tr><td><=
647 font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" size=3D"2"><st=
648 rong>State Tax</strong></font></td><td height=3D"3">&nbsp;</td><td align=3D=
649 "right"><font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" size=
650 =3D"2">$5.90</font></td></tr><tr><td><font face=3D"Arial, Helvetica, sans-s=
651 erif" color=3D"#333333" size=3D"2"><strong>Vehicle License Fee</strong></fo=
652 nt></td><td height=3D"3">&nbsp;</td><td align=3D"right"><font face=3D"Arial=
653 , Helvetica, sans-serif" color=3D"#333333" size=3D"2">$1.84</font></td></tr=
654 ><tr><td><font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" size=
655 =3D"2"><strong>State Txn Tax</strong></font></td><td height=3D"3">&nbsp;</t=
656 d><td align=3D"right"><font face=3D"Arial, Helvetica, sans-serif" color=3D"=
657 #333333" size=3D"2">$6.00</font></td></tr>
658
659 </body>
660 </html>
661 EOF
662
663 if [ $can_reformat_texthtml -eq 1 ]; then
664 #### lynx inserts multiple blank lines, so squeeze them.
665 #### Truncate to avoid comparing the html portion because it can
666 #### get reformatted.
667 run_prog mhfixmsg last -outfile - | squeeze_lines | head -22 >"$actual"
668 check "$expected" "$actual" 'ignore space'
669 else
670 cp -p "$MH_TEST_DIR/Mail/inbox/15" "$MH_TEST_DIR/Mail/inbox/15.backup"
671 rm -f "$expected"
672 fi
673
674
675 # check -textcharset
676 # Also checks preservation of attributes after one (charset) that is
677 # modified.
678 cat >"$expected" <<EOF
679 To: recipient@example.com
680 From: sender@example.com
681 Subject: mhfixmsg textcharset test
682 MIME-Version: 1.0
683 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
684
685 ------- =_aaaaaaaaaa0
686 Content-Type: text/plain; charset="utf-8"; name="square.txt"
687 Content-Disposition: attachment; filename="square.txt"
688 Content-Transfer-Encoding: 8bit
689
690 ½²=¼
691
692 ------- =_aaaaaaaaaa0--
693 EOF
694
695 #### Generated the encoded text below with:
696 #### $ printf '\xbd\xb2=\xbc\n' | base64
697 cat >`mhpath new` <<EOF
698 To: recipient@example.com
699 From: sender@example.com
700 Subject: mhfixmsg textcharset test
701 MIME-Version: 1.0
702 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
703
704 ------- =_aaaaaaaaaa0
705 Content-Type: text/plain; charset="iso-8859-1"; name="square.txt"
706 Content-Disposition: attachment; filename="square.txt"
707 Content-Transfer-Encoding: base64
708
709 vbI9vAo=
710
711 ------- =_aaaaaaaaaa0--
712 EOF
713
714 if test "$ICONV_ENABLED" -eq 1; then
715 run_prog mhfixmsg last -textcharset utf-8 -outfile "$actual" 2>&1
716 check "$expected" "$actual"
717 else
718 echo "$0: skipping -textcharset check because nmh was built without iconv"
719 rm -f "$expected"
720 fi
721
722
723 # check -nofixboundary
724 cat >"$expected" <<EOF
725 EOF
726
727 cat >`mhpath new` <<EOF
728 Date: Fri, 13 May 2011 08:21:12 -0500
729 Content-Type: multipart/alternative;
730 boundary="----=_NextPart_000_1781A17_01CC1147.81E9467A"
731 Content-Transfer-Encoding: 8bit
732 MIME-Version: 1.0
733 From: <sender@example.com>
734 To: <recipient@example.com>
735 Subject: mhfixmsg bad boundary test
736
737 This is a multi-part message in MIME format.
738
739 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4
740 Content-Type: text/plain
741
742 The boundaries of this part don't match the header boundary.
743
744 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4--
745 EOF
746
747 cp -p `mhpath last` `mhpath new`
748
749 run_test 'mhfixmsg last -nofixboundary' ''
750 check "$MH_TEST_DIR"/Mail/inbox/17 "$MH_TEST_DIR"/Mail/inbox/18 'keep first'
751
752
753 # check that message is not output when fed through stdin
754 run_prog mhfixmsg -file - -verbose <`mhpath last` >"$actual" 2>"$actual.err"
755 check "$expected" "$actual"
756 if grep "mhfixmsg: $MH_TEST_DIR/Mail/.*, fix multipart boundary" \
757 "$actual.err" >/dev/null; then
758 rm -f "$actual.err"
759 else
760 echo "$0: test failed, output is in $actual.err."
761 failed=`expr ${failed:-0} + 1`
762 fi
763
764
765 # check fixup of erroneous boundary in multipart (-fixboundary,
766 # enabled by default)
767 # check -verbose
768 cat >"$expected" <<EOF
769 Date: Fri, 13 May 2011 08:21:12 -0500
770 Content-Type: multipart/alternative;
771 boundary="----=_NextPart_000_1781A1A_01CC1147.81EBA8D4"
772 Content-Transfer-Encoding: 8bit
773 MIME-Version: 1.0
774 From: <sender@example.com>
775 To: <recipient@example.com>
776 Subject: mhfixmsg bad boundary test
777
778 This is a multi-part message in MIME format.
779
780 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4
781 Content-Type: text/plain
782
783 The boundaries of this part don't match the header boundary.
784
785 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4--
786 EOF
787
788 run_test 'mhfixmsg last -outfile '"$actual"' -verbose' \
789 "mhfixmsg: 17, fix multipart boundary"
790 check "$expected" "$actual"
791
792
793 # check that text/plain part is not added to text/html in multipart/related
794 # when it shouldn't be
795 cat >`mhpath new` <<EOF
796 MIME-Version: 1.0
797 Date: Tue, 26 Feb 2013 18:07:20 -0600
798 Subject: multipart/related, not /alternative
799 Content-Type: multipart/related;
800 type="text/html"; boundary="----=_Part_90310_101292502.1"
801
802 ------=_Part_90310_101292502.1
803 Content-Type: text/html; charset="us-ascii"
804 Content-Transfer-Encoding: 7bit
805
806 <html><head>
807 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
808 <title>HTML Content</title>
809 </head>
810 <body>
811 This is the real content.
812 </body>
813 </html>
814
815 ------=_Part_90310_101292502.1
816 Content-Type: text/plain; charset="us-ascii"
817 Content-Transfer-Encoding: 7bit
818
819 Your email client does not support HTML messages
820
821 ------=_Part_90310_101292502.1--
822 EOF
823
824 cp -p `mhpath last` "$expected"
825
826 if [ $can_reformat_texthtml -eq 1 ]; then
827 #### lynx inserts multiple blank lines, so squeeze them.
828 run_prog mhfixmsg last -outfile - | squeeze_lines >"$actual"
829 check "$expected" "$actual" 'ignore space'
830 else
831 rm -f "$expected"
832 fi
833
834
835 # check handling of rfc822 message type
836 cat >"$expected" <<EOF
837 From: Test <test@example.com>
838 To: Some User <user@example.com>
839 Date: Fri, 29 Sep 2006 00:00:00
840 Message-Id: @test.nmh
841 Subject: message with message/rfc822 attachment
842 MIME-Version: 1.0
843 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
844
845 and some garbage before the attachment
846
847 ------- =_aaaaaaaaaa0
848 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
849 Content-Description: 1552
850 Content-Disposition: attachment; filename="1552"
851
852 From: Test <test@example.com>
853 To: <another_user@example.com>
854 Date: Thu, 28 Sep 2006 00:00:00
855 Message-Id: @test.nmh
856 Subject: message/rfc822 attachment
857
858 This is an RFC-822 message.
859
860 ------- =_aaaaaaaaaa0--
861
862 and some garbage at the end
863 EOF
864
865 cat >`mhpath new` <<EOF
866 From: Test <test@example.com>
867 To: Some User <user@example.com>
868 Date: Fri, 29 Sep 2006 00:00:00
869 Message-Id: @test.nmh
870 Subject: message with message/rfc822 attachment
871 MIME-Version: 1.0
872 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaa0"
873
874 and some garbage before the attachment
875
876 ------- =_aaaaaaaaaa0
877 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
878 Content-Description: 1552
879 Content-Disposition: attachment; filename="1552"
880
881 From: Test <test@example.com>
882 To: <another_user@example.com>
883 Date: Thu, 28 Sep 2006 00:00:00
884 Message-Id: @test.nmh
885 Subject: message/rfc822 attachment
886
887 This is an RFC-822 message.
888
889 ------- =_aaaaaaaaaa0--
890
891 and some garbage at the end
892 EOF
893
894 run_test 'mhfixmsg last -outfile '"$actual" ''
895 check "$expected" "$actual"
896
897
898 # check stripping of CRs from ASCII text context
899 cat >"$expected" <<EOF
900 MIME-Version: 1.0
901 From: sender@example.com
902 To: recipient@example.com
903 Subject: message with CR's
904 Date: Mon, 29 Apr 2013 11:51:45 -0400
905
906 There are two CR-LF pairs at the end of this sentence.
907
908 EOF
909
910 cat >`mhpath new` <<'EOF'
911 MIME-Version: 1.0
912 From: sender@example.com
913 To: recipient@example.com
914 Subject: message with CR's
915 Date: Mon, 29 Apr 2013 11:51:45 -0400
916
917 There are two CR-LF pairs at the end of this sentence.
918
919 EOF
920
921 run_prog mhfixmsg last -outfile "$actual"
922 check "$expected" "$actual"
923
924
925 # check -replacetextplain
926 prepare_space >"$expected" <<EOF
927 To: recipient@example.com
928 From: sender@example.com
929 Subject: mhfixmsg replacement of bad text/plain part test
930 MIME-Version: 1.0
931 Content-Type: multipart/alternative; boundary="----=_Part_876302"
932
933 ------=_Part_876302
934 Content-Type: text/plain; charset="UTF-8"
935 Content-Transfer-Encoding: 8bit
936
937 Yes, the text/plain part really was empty.
938
939 ------=_Part_876302
940 Content-Type: text/html; charset="UTF-8"
941 Content-Transfer-Encoding: 8bit
942 Content-Disposition: inline
943
944 <html><head>
945 <title>eticket</title>
946 </head>
947 <body>
948 Yes, the text/plain part really was empty.
949 </body>
950 </html>
951
952 ------=_Part_876302--
953 EOF
954
955 cat >`mhpath new` <<'EOF'
956 To: recipient@example.com
957 From: sender@example.com
958 Subject: mhfixmsg replacement of bad text/plain part test
959 MIME-Version: 1.0
960 Content-Type: multipart/alternative; boundary="----=_Part_876302"
961
962 ------=_Part_876302
963 Content-Type: text/plain; charset="iso-8859-15"
964 Content-Transfer-Encoding: 7bit
965 Content-Disposition: inline
966
967
968
969 ------=_Part_876302
970 Content-Type: text/html; charset="UTF-8"
971 Content-Transfer-Encoding: 8bit
972 Content-Disposition: inline
973
974 <html><head>
975 <title>eticket</title>
976 </head>
977 <body>
978 Yes, the text/plain part really was empty.
979 </body>
980 </html>
981
982 ------=_Part_876302--
983 EOF
984
985 if [ $can_reformat_texthtml -eq 1 ]; then
986 #### lynx inserts multiple blank lines, so squeeze them.
987 run_prog mhfixmsg last -replacetextplain -outfile - | \
988 squeeze_lines > "$actual"
989 check "$expected" "$actual" 'ignore space'
990 else
991 rm -f "$expected"
992 fi
993
994
995 # check -noreplacetextplain
996 cat >"$expected" <<EOF
997 To: recipient@example.com
998 From: sender@example.com
999 Subject: mhfixmsg replacement of bad text/plain part test
1000 MIME-Version: 1.0
1001 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1002
1003 ------=_Part_876302
1004 Content-Type: text/plain; charset="iso-8859-15"
1005 Content-Transfer-Encoding: 7bit
1006 Content-Disposition: inline
1007
1008
1009
1010 ------=_Part_876302
1011 Content-Type: text/html; charset="UTF-8"
1012 Content-Transfer-Encoding: 8bit
1013 Content-Disposition: inline
1014
1015 <html><head>
1016 <title>eticket</title>
1017 </head>
1018 <body>
1019 Yes, the text/plain part really was empty.
1020 </body>
1021 </html>
1022
1023 ------=_Part_876302--
1024 EOF
1025
1026 run_prog mhfixmsg last -replacetextplain -noreplacetextplain -outfile "$actual"
1027 check "$expected" "$actual"
1028
1029
1030 # check removal of extraneous trailing semicolon from header parameter list
1031 cat >"$expected" <<EOF
1032 To: recipient@example.com
1033 Subject: test
1034 From: sender@example.com
1035 MIME-Version: 1.0
1036 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1037
1038 ------- =_aaaaaaaaaa0
1039 Content-Type: text/plain; charset="us-ascii"
1040
1041 test
1042
1043 ------- =_aaaaaaaaaa0
1044 Content-Type: text/plain; charset="us-ascii";
1045 name="DATE"
1046 Content-Description: check folded headers, with and without trailing semicolon
1047 Content-Disposition: attachment;
1048 filename="DATE"
1049
1050 14 April 2014
1051
1052 ------- =_aaaaaaaaaa0--
1053 EOF
1054
1055 cat >`mhpath new` <<EOF
1056 To: recipient@example.com
1057 Subject: test
1058 From: sender@example.com
1059 MIME-Version: 1.0
1060 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1061
1062 ------- =_aaaaaaaaaa0
1063 Content-Type: text/plain; charset="us-ascii";
1064
1065 test
1066
1067 ------- =_aaaaaaaaaa0
1068 Content-Type: text/plain; charset="us-ascii";
1069 name="DATE"
1070 Content-Description: check folded headers, with and without trailing semicolon
1071 Content-Disposition: attachment;
1072 filename="DATE";
1073
1074 14 April 2014
1075
1076 ------- =_aaaaaaaaaa0--
1077 EOF
1078 run_test 'mhfixmsg last -outfile '"$actual" ''
1079 check "$expected" "$actual"
1080
1081
1082 # check rmmproc
1083 cat >"$MH_TEST_DIR/Mail/rmmproc" <<'EOF'
1084 mv "$1" "$1.backup"
1085 EOF
1086 chmod a+x "${MH_TEST_DIR}/Mail/rmmproc"
1087 echo "rmmproc: ${MH_TEST_DIR}/Mail/rmmproc" >>"$MH"
1088 cp "${MH_TEST_DIR}/Mail/inbox/15" "${MH_TEST_DIR}/Mail/inbox/15.original"
1089
1090 run_test 'mhfixmsg 15' ''
1091 check "${MH_TEST_DIR}/Mail/inbox/15.backup" \
1092 "${MH_TEST_DIR}/Mail/inbox/15.original"
1093
1094
1095 # check -normmproc
1096 cp "${MH_TEST_DIR}/Mail/inbox/19" "${MH_TEST_DIR}/Mail/inbox/20"
1097
1098 run_test 'mhfixmsg 19 -normmproc'
1099 check "${MH_TEST_DIR}/Mail/inbox/20" \
1100 "${MH_TEST_DIR}/Mail/inbox/,19" 'keep first'
1101
1102
1103 # check -rmmproc
1104 run_test 'mhfixmsg 20 -rmmproc true'
1105 if test -f '${MH_TEST_DIR}/Mail/inbox/20.backup'; then
1106 echo check of mhfixmsg -rmmproc FAILED, should not have created backup file
1107 failed=`expr ${failed:-0} + 1`
1108 fi
1109
1110
1111 # make sure there are no tmp files left over
1112 find "$MH_TEST_DIR/Mail" \( -name 'mhfix*' -o -name ',mhfix*' \) -print \
1113 >"$actual"
1114 cat >"$expected" <<EOF
1115 EOF
1116
1117 check "$expected" "$actual"
1118
1119
1120 exit $failed