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