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