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