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