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