]> diplodocus.org Git - nmh/blob - test/mhfixmsg/test-mhfixmsg
Removed improperly copied comment from test-mhfixmsg.
[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 #### Make sure that html-to-text conversion is what we expect.
18 require_locale en_US.utf-8 en_US.utf8
19 LC_ALL=en_US.UTF-8; export LC_ALL
20
21 expected="$MH_TEST_DIR/test-mhfixmsg$$.expected"
22 expected_err="$MH_TEST_DIR/test-mhfixmsg$$.expected_err"
23 actual="$MH_TEST_DIR/test-mhfixmsg$$.actual"
24 actual_err="$MH_TEST_DIR/test-mhfixmsg$$.actual_err"
25
26 if grep mhfixmsg-format-text/html "${MH_TEST_DIR}/Mail/mhn.defaults" \
27 >/dev/null; then
28 can_reformat_texthtml=1
29 if grep 'mhfixmsg-format-text/html.*w3m' "${MH_TEST_DIR}/Mail/mhn.defaults" \
30 >/dev/null; then
31 #### w3m uses $HOME/.w3m/, and creates it if it doesn't exist. To
32 #### support testing with non-writeable $HOME, and to not leave
33 #### relics from this test if it is writeable but doesn't already
34 #### have a .w3m, and to not depend on whatever is in that if it
35 #### does already exist, overwrite $HOME if using w3m.
36 HOME="$MHTMPDIR"; export HOME
37 fi
38 else
39 echo "$0: skipping -reformat check because no text browser was found"
40 can_reformat_texthtml=0
41 fi
42
43
44 # check -help
45 cat >"$expected" <<EOF
46 Usage: mhfixmsg [+folder] [msgs] [switches]
47 switches are:
48 -decodetext 8bit|7bit
49 -nodecodetext
50 -[no]textcharset
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]changecur
60 -[no]verbose
61 -version
62 -help
63 EOF
64
65 run_prog 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 prepare_space >"$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 squeeze them.
253 run_prog mhfixmsg last -outfile - -verbose 2>"$actual.err" | \
254 squeeze_lines >"$actual"
255 check "$expected" "$actual" 'ignore space'
256 check "$expected.err" "$actual.err"
257 else
258 rm -f "$expected"
259 fi
260
261
262 # check implicit -file with absolute pathname
263 run_test "mhfixmsg `mhpath last` -outfile /dev/null" ''
264
265
266 # check handling of boundary string that appears in message body
267 #
268 prepare_space >"$expected" <<EOF
269 MIME-Version: 1.0
270 From: sender@example.com
271 To: bonquiqui@example.com
272 Subject: rue
273 Date: Sat, 26 Jan 2013 17:37:53 -0500
274 Content-Type: multipart/alternative; boundary="----=_nmh-multipart-3"
275
276 ------=_nmh-multipart-3
277 Content-Type: text/plain; charset="Windows-1252"
278 Content-Transfer-Encoding: 8bit
279
280 ------=_nmh-multipart
281 ------=_nmh-multipart-1
282 ------=_nmh-multipart-2
283
284 ------=_nmh-multipart-3
285 Content-Type: text/html; charset="Windows-1252"
286 Content-Transfer-Encoding: 8bit
287
288 <html>
289 <head>
290 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
291 <meta name="Generator" content="Microsoft Exchange Server">
292 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
293 </head>
294 <body>
295 ------=_nmh-multipart<br>
296 ------=_nmh-multipart-1<br>
297 ------=_nmh-multipart-2<br>
298 </body>
299 </html>
300
301 ------=_nmh-multipart-3--
302 EOF
303
304 cat >"$MH_TEST_DIR"/Mail/inbox/12 <<EOF
305 MIME-Version: 1.0
306 From: sender@example.com
307 To: bonquiqui@example.com
308 Subject: rue
309 Date: Sat, 26 Jan 2013 17:37:53 -0500
310 Content-Type: text/html; charset="Windows-1252"
311 Content-Transfer-Encoding: quoted-printable
312
313 <html>
314 <head>
315 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
316 252">
317 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
318 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
319 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
320 </head>
321 <body>
322 ------=3D_nmh-multipart<br>
323 ------=3D_nmh-multipart-1<br>
324 ------=3D_nmh-multipart-2<br>
325 </body>
326 </html>
327 EOF
328
329 if [ $can_reformat_texthtml -eq 1 ]; then
330 printf '%s\n' "mhfixmsg: 12, insert text/plain part
331 mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
332 >"$expected.err"
333
334 #### lynx inserts multiple blank lines, so squeeze them.
335 run_prog mhfixmsg last -outfile - -verbose 2>"$actual.err" | \
336 squeeze_lines >"$actual"
337 check "$expected" "$actual" 'ignore space'
338 check "$expected.err" "$actual.err"
339 else
340 rm -f "$expected"
341 fi
342
343
344 # check -nodecode
345 prepare_space >"$expected" <<EOF
346 MIME-Version: 1.0
347 From: sender@example.com
348 To: bonquiqui@example.com
349 Subject: rue
350 Date: Sat, 26 Jan 2013 17:37:53 -0500
351 Content-Type: multipart/alternative; boundary="----=_nmh-multipart"
352
353 ------=_nmh-multipart
354 Content-Type: text/plain; charset="Windows-1252"
355 Content-Transfer-Encoding: 8bit
356
357 Need to go! Need ... to ... go!
358
359 ------=_nmh-multipart
360 Content-Type: text/html; charset="Windows-1252"
361 Content-Transfer-Encoding: quoted-printable
362
363 <html>
364 <head>
365 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-=
366 1252">
367 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
368 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pa=
369 dding-left: 4pt; border-left: #800000 2px solid; } --></style>
370 </head>
371 <body>
372 <div>
373 <div>Need to go! Need ... to ... go!</div>
374 </body>
375 </html>
376
377 ------=_nmh-multipart--
378 EOF
379
380 cat >"$MH_TEST_DIR"/Mail/inbox/12 <<EOF
381 MIME-Version: 1.0
382 From: sender@example.com
383 To: bonquiqui@example.com
384 Subject: rue
385 Date: Sat, 26 Jan 2013 17:37:53 -0500
386 Content-Type: text/html; charset="Windows-1252"
387 Content-Transfer-Encoding: quoted-printable
388
389 <html>
390 <head>
391 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
392 252">
393 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
394 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
395 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
396 </head>
397 <body>
398 <div>
399 <div>Need to go! Need ... to ... go!</div>
400 </body>
401 </html>
402 EOF
403
404 if [ $can_reformat_texthtml -eq 1 ]; then
405 printf '%s\n' 'mhfixmsg: 12, insert text/plain part' >"$expected.err"
406
407 #### lynx inserts multiple blank lines, so squeeze them.
408 run_prog mhfixmsg last -nodecode -outfile - -verbose 2>"$actual.err" | \
409 squeeze_lines >"$actual"
410 check "$expected" "$actual" 'ignore space'
411 check "$expected.err" "$actual.err"
412 else
413 rm -f "$expected"
414 fi
415
416
417 # check -decode (enabled by default)
418 cat >"$expected" <<EOF
419 To: recipient@example.com
420 From: sender@example.com
421 Subject: mhfixmsg decode test
422 MIME-Version: 1.0
423 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
424
425 ------- =_aaaaaaaaaa0
426 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
427 Content-Disposition: attachment; filename="test4.txt"
428 Content-Transfer-Encoding: 8bit
429
430 This is a text/plain part.
431
432 ------- =_aaaaaaaaaa0--
433 EOF
434
435 cat >`mhpath new` <<EOF
436 To: recipient@example.com
437 From: sender@example.com
438 Subject: mhfixmsg decode test
439 MIME-Version: 1.0
440 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
441
442 ------- =_aaaaaaaaaa0
443 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
444 Content-Disposition: attachment; filename="test4.txt"
445 Content-Transfer-Encoding: base64
446
447 VGhpcyBpcyBhIHRleHQvcGxhaW4gcGFydC4K
448
449 ------- =_aaaaaaaaaa0--
450 EOF
451
452 run_prog mhfixmsg last -outfile "$actual"
453 check "$expected" "$actual"
454
455
456 # check -decode with more complicated content structure
457 cat >$expected <<EOF
458 To: recipient@example.com
459 From: sender@example.com
460 Subject: mhfixmsg decode test 2
461 MIME-Version: 1.0
462 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
463
464 This is additional content before the first subpart of the multipart.
465
466 ------- =_aaaaaaaaaa0
467 Content-Type: multipart/related;
468 type="text/plain"; boundary="subpart__1.1"
469
470 --subpart__1.1
471 Content-Type: text/plain; charset="iso-8859-1"
472 Content-Disposition: attachment; filename="test1.txt"
473
474 This is the first text/plain part, in a subpart.
475
476 --subpart__1.1--
477
478 This is additional content after the last subpart of the multipart.
479
480 ------- =_aaaaaaaaaa0
481 Content-Type: text/plain; charset="iso-8859-1"
482 Content-Disposition: attachment; filename="test2.txt"
483 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
484 Content-Transfer-Encoding: 8bit
485
486 This is the second text/plain part.
487
488 ------- =_aaaaaaaaaa0
489 Content-Type: text/plain; charset="iso-8859-1"
490 Content-Disposition: attachment; filename="test3.txt"
491
492 This is the third text/plain part.
493
494 ------- =_aaaaaaaaaa0
495 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
496 Content-Disposition: attachment; filename="test4.txt"
497 Content-Transfer-Encoding: 8bit
498
499 This is the fourth text/plain part.
500
501 ------- =_aaaaaaaaaa0--
502
503 This is additional content after the last subpart of the multipart.
504 EOF
505
506 cat >`mhpath new` <<EOF
507 To: recipient@example.com
508 From: sender@example.com
509 Subject: mhfixmsg decode test 2
510 MIME-Version: 1.0
511 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
512
513 This is additional content before the first subpart of the multipart.
514
515 ------- =_aaaaaaaaaa0
516 Content-Type: multipart/related;
517 type="text/plain"; boundary="subpart__1.1"
518
519 --subpart__1.1
520 Content-Type: text/plain; charset="iso-8859-1"
521 Content-Disposition: attachment; filename="test1.txt"
522
523 This is the first text/plain part, in a subpart.
524
525 --subpart__1.1--
526
527 This is additional content after the last subpart of the multipart.
528
529 ------- =_aaaaaaaaaa0
530 Content-Type: text/plain; charset="iso-8859-1"
531 Content-Disposition: attachment; filename="test2.txt"
532 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
533 Content-Transfer-Encoding: quoted-printable
534
535 This is the second text/plain part.
536
537 ------- =_aaaaaaaaaa0
538 Content-Type: text/plain; charset="iso-8859-1"
539 Content-Disposition: attachment; filename="test3.txt"
540
541 This is the third text/plain part.
542
543 ------- =_aaaaaaaaaa0
544 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
545 Content-Disposition: attachment; filename="test4.txt"
546 Content-Transfer-Encoding: base64
547
548 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4K
549
550 ------- =_aaaaaaaaaa0--
551
552 This is additional content after the last subpart of the multipart.
553 EOF
554 run_prog mhfixmsg last -outfile "$actual"
555 check "$expected" "$actual"
556
557
558 # check attempted -decode of binary text
559 #### Generated the encoded text below with:
560 #### $ printf '\x0\xbd\xb2=\xbc\n' | base64
561 cat >`mhpath new` <<EOF
562 To: recipient@example.com
563 From: sender@example.com
564 Subject: mhfixmsg attempted binary decode test
565 MIME-Version: 1.0
566 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
567
568 ------- =_aaaaaaaaaa0
569 Content-Type: text/plain; charset="iso-8859-1"; name="nul+square.txt"
570 Content-Transfer-Encoding: base64
571
572 AL2yPbwK
573
574 ------- =_aaaaaaaaaa0--
575 EOF
576
577 cp -p `mhpath last` "$expected"
578 run_prog mhfixmsg last
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=\"nul+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 prepare_space >"$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 squeeze them.
666 #### Truncate to avoid comparing the html portion because it can
667 #### get reformatted.
668 run_prog mhfixmsg last -outfile - | squeeze_lines | 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 -textcharset
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 textcharset 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 textcharset 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 if test "$ICONV_ENABLED" -eq 1; then
716 run_prog mhfixmsg last -textcharset utf-8 -outfile "$actual" 2>&1
717 check "$expected" "$actual"
718 else
719 echo "$0: skipping -textcharset check because nmh was built without iconv"
720 rm -f "$expected"
721 fi
722
723
724 # check -nofixboundary
725 cat >"$expected" <<EOF
726 EOF
727
728 cat >`mhpath new` <<EOF
729 Date: Fri, 13 May 2011 08:21:12 -0500
730 Content-Type: multipart/alternative;
731 boundary="----=_NextPart_000_1781A17_01CC1147.81E9467A"
732 Content-Transfer-Encoding: 8bit
733 MIME-Version: 1.0
734 From: <sender@example.com>
735 To: <recipient@example.com>
736 Subject: mhfixmsg bad boundary test
737
738 This is a multi-part message in MIME format.
739
740 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4
741 Content-Type: text/plain
742
743 The boundaries of this part don't match the header boundary.
744
745 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4--
746 EOF
747
748 cp -p `mhpath last` `mhpath new`
749
750 run_test 'mhfixmsg last -nofixboundary' ''
751 check "$MH_TEST_DIR"/Mail/inbox/17 "$MH_TEST_DIR"/Mail/inbox/18 'keep first'
752
753
754 # check that message is not output when fed through stdin
755 run_prog mhfixmsg -file - -verbose <`mhpath last` >"$actual" 2>"$actual.err"
756 check "$expected" "$actual"
757 if grep "mhfixmsg: $MH_TEST_DIR/Mail/.*, fix multipart boundary" \
758 "$actual.err" >/dev/null; then
759 rm -f "$actual.err"
760 else
761 echo "$0: test failed, output is in $actual.err."
762 failed=`expr ${failed:-0} + 1`
763 fi
764
765
766 # check fixup of erroneous boundary in multipart (-fixboundary,
767 # enabled by default)
768 # check -verbose
769 cat >"$expected" <<EOF
770 Date: Fri, 13 May 2011 08:21:12 -0500
771 Content-Type: multipart/alternative;
772 boundary="----=_NextPart_000_1781A1A_01CC1147.81EBA8D4"
773 Content-Transfer-Encoding: 8bit
774 MIME-Version: 1.0
775 From: <sender@example.com>
776 To: <recipient@example.com>
777 Subject: mhfixmsg bad boundary test
778
779 This is a multi-part message in MIME format.
780
781 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4
782 Content-Type: text/plain
783
784 The boundaries of this part don't match the header boundary.
785
786 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4--
787 EOF
788
789 run_test 'mhfixmsg last -outfile '"$actual"' -verbose' \
790 "mhfixmsg: 17, fix multipart boundary"
791 check "$expected" "$actual"
792
793
794 # check that text/plain part is not added to text/html in multipart/related
795 # when it shouldn't be
796 cat >`mhpath new` <<EOF
797 MIME-Version: 1.0
798 Date: Tue, 26 Feb 2013 18:07:20 -0600
799 Subject: multipart/related, not /alternative
800 Content-Type: multipart/related;
801 type="text/html"; boundary="----=_Part_90310_101292502.1"
802
803 ------=_Part_90310_101292502.1
804 Content-Type: text/html; charset="us-ascii"
805 Content-Transfer-Encoding: 7bit
806
807 <html><head>
808 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
809 <title>HTML Content</title>
810 </head>
811 <body>
812 This is the real content.
813 </body>
814 </html>
815
816 ------=_Part_90310_101292502.1
817 Content-Type: text/plain; charset="us-ascii"
818 Content-Transfer-Encoding: 7bit
819
820 Your email client does not support HTML messages
821
822 ------=_Part_90310_101292502.1--
823 EOF
824
825 cp -p `mhpath last` "$expected"
826
827 if [ $can_reformat_texthtml -eq 1 ]; then
828 #### lynx inserts multiple blank lines, so squeeze them.
829 run_prog mhfixmsg last -outfile - | squeeze_lines >"$actual"
830 check "$expected" "$actual" 'ignore space'
831 else
832 rm -f "$expected"
833 fi
834
835
836 # check handling of rfc822 message type
837 cat >"$expected" <<EOF
838 From: Test <test@example.com>
839 To: Some User <user@example.com>
840 Date: Fri, 29 Sep 2006 00:00:00
841 Message-Id: @test.nmh
842 Subject: message with message/rfc822 attachment
843 MIME-Version: 1.0
844 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
845
846 and some garbage before the attachment
847
848 ------- =_aaaaaaaaaa0
849 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
850 Content-Description: 1552
851 Content-Disposition: attachment; filename="1552"
852
853 From: Test <test@example.com>
854 To: <another_user@example.com>
855 Date: Thu, 28 Sep 2006 00:00:00
856 Message-Id: @test.nmh
857 Subject: message/rfc822 attachment
858
859 This is an RFC-822 message.
860
861 ------- =_aaaaaaaaaa0--
862
863 and some garbage at the end
864 EOF
865
866 cat >`mhpath new` <<EOF
867 From: Test <test@example.com>
868 To: Some User <user@example.com>
869 Date: Fri, 29 Sep 2006 00:00:00
870 Message-Id: @test.nmh
871 Subject: message with message/rfc822 attachment
872 MIME-Version: 1.0
873 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaa0"
874
875 and some garbage before the attachment
876
877 ------- =_aaaaaaaaaa0
878 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
879 Content-Description: 1552
880 Content-Disposition: attachment; filename="1552"
881
882 From: Test <test@example.com>
883 To: <another_user@example.com>
884 Date: Thu, 28 Sep 2006 00:00:00
885 Message-Id: @test.nmh
886 Subject: message/rfc822 attachment
887
888 This is an RFC-822 message.
889
890 ------- =_aaaaaaaaaa0--
891
892 and some garbage at the end
893 EOF
894
895 run_test 'mhfixmsg last -outfile '"$actual" ''
896 check "$expected" "$actual"
897
898
899 # check stripping of CRs from ASCII text context
900 cat >"$expected" <<EOF
901 MIME-Version: 1.0
902 From: sender@example.com
903 To: recipient@example.com
904 Subject: message with CR's
905 Date: Mon, 29 Apr 2013 11:51:45 -0400
906
907 There are two CR-LF pairs at the end of this sentence.
908
909 EOF
910
911 cat >`mhpath new` <<'EOF'
912 MIME-Version: 1.0
913 From: sender@example.com
914 To: recipient@example.com
915 Subject: message with CR's
916 Date: Mon, 29 Apr 2013 11:51:45 -0400
917
918 There are two CR-LF pairs at the end of this sentence.
919
920 EOF
921
922 run_prog mhfixmsg last -outfile "$actual"
923 check "$expected" "$actual"
924
925
926 # check -replacetextplain
927 prepare_space >"$expected" <<EOF
928 To: recipient@example.com
929 From: sender@example.com
930 Subject: mhfixmsg replacement of bad text/plain part test
931 MIME-Version: 1.0
932 Content-Type: multipart/alternative; boundary="----=_Part_876302"
933
934 ------=_Part_876302
935 Content-Type: text/plain; charset="UTF-8"
936 Content-Transfer-Encoding: 8bit
937
938 Yes, the text/plain part really was empty.
939
940 ------=_Part_876302
941 Content-Type: text/html; charset="UTF-8"
942 Content-Transfer-Encoding: 8bit
943 Content-Disposition: inline
944
945 <html><head>
946 <title>eticket</title>
947 </head>
948 <body>
949 Yes, the text/plain part really was empty.
950 </body>
951 </html>
952
953 ------=_Part_876302--
954 EOF
955
956 cat >`mhpath new` <<'EOF'
957 To: recipient@example.com
958 From: sender@example.com
959 Subject: mhfixmsg replacement of bad text/plain part test
960 MIME-Version: 1.0
961 Content-Type: multipart/alternative; boundary="----=_Part_876302"
962
963 ------=_Part_876302
964 Content-Type: text/plain; charset="iso-8859-15"
965 Content-Transfer-Encoding: 7bit
966 Content-Disposition: inline
967
968
969
970 ------=_Part_876302
971 Content-Type: text/html; charset="UTF-8"
972 Content-Transfer-Encoding: 8bit
973 Content-Disposition: inline
974
975 <html><head>
976 <title>eticket</title>
977 </head>
978 <body>
979 Yes, the text/plain part really was empty.
980 </body>
981 </html>
982
983 ------=_Part_876302--
984 EOF
985
986 if [ $can_reformat_texthtml -eq 1 ]; then
987 #### lynx inserts multiple blank lines, so squeeze them.
988 run_prog mhfixmsg last -replacetextplain -outfile - | \
989 squeeze_lines > "$actual"
990 check "$expected" "$actual" 'ignore space'
991 else
992 rm -f "$expected"
993 fi
994
995
996 # check -noreplacetextplain
997 cat >"$expected" <<EOF
998 To: recipient@example.com
999 From: sender@example.com
1000 Subject: mhfixmsg replacement of bad text/plain part test
1001 MIME-Version: 1.0
1002 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1003
1004 ------=_Part_876302
1005 Content-Type: text/plain; charset="iso-8859-15"
1006 Content-Transfer-Encoding: 7bit
1007 Content-Disposition: inline
1008
1009
1010
1011 ------=_Part_876302
1012 Content-Type: text/html; charset="UTF-8"
1013 Content-Transfer-Encoding: 8bit
1014 Content-Disposition: inline
1015
1016 <html><head>
1017 <title>eticket</title>
1018 </head>
1019 <body>
1020 Yes, the text/plain part really was empty.
1021 </body>
1022 </html>
1023
1024 ------=_Part_876302--
1025 EOF
1026
1027 run_prog mhfixmsg last -replacetextplain -noreplacetextplain -outfile "$actual"
1028 check "$expected" "$actual"
1029
1030
1031 # check removal of extraneous trailing semicolon from header parameter list
1032 cat >"$expected" <<EOF
1033 To: recipient@example.com
1034 Subject: test
1035 From: sender@example.com
1036 MIME-Version: 1.0
1037 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1038
1039 ------- =_aaaaaaaaaa0
1040 Content-Type: text/plain; charset="us-ascii"
1041
1042 test
1043
1044 ------- =_aaaaaaaaaa0
1045 Content-Type: text/plain; charset="us-ascii";
1046 name="DATE"
1047 Content-Description: check folded headers, with and without trailing semicolon
1048 Content-Disposition: attachment;
1049 filename="DATE"
1050
1051 14 April 2014
1052
1053 ------- =_aaaaaaaaaa0--
1054 EOF
1055
1056 cat >`mhpath new` <<EOF
1057 To: recipient@example.com
1058 Subject: test
1059 From: sender@example.com
1060 MIME-Version: 1.0
1061 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1062
1063 ------- =_aaaaaaaaaa0
1064 Content-Type: text/plain; charset="us-ascii";
1065
1066 test
1067
1068 ------- =_aaaaaaaaaa0
1069 Content-Type: text/plain; charset="us-ascii";
1070 name="DATE"
1071 Content-Description: check folded headers, with and without trailing semicolon
1072 Content-Disposition: attachment;
1073 filename="DATE";
1074
1075 14 April 2014
1076
1077 ------- =_aaaaaaaaaa0--
1078 EOF
1079 run_test 'mhfixmsg last -outfile '"$actual" ''
1080 check "$expected" "$actual"
1081
1082
1083 # check rmmproc
1084 cat >"$MH_TEST_DIR/Mail/rmmproc" <<'EOF'
1085 mv "$1" "$1.backup"
1086 EOF
1087 chmod a+x "${MH_TEST_DIR}/Mail/rmmproc"
1088 echo "rmmproc: ${MH_TEST_DIR}/Mail/rmmproc" >>"$MH"
1089 cp "${MH_TEST_DIR}/Mail/inbox/15" "${MH_TEST_DIR}/Mail/inbox/15.original"
1090
1091 run_test 'mhfixmsg 15' ''
1092 check "${MH_TEST_DIR}/Mail/inbox/15.backup" \
1093 "${MH_TEST_DIR}/Mail/inbox/15.original"
1094
1095
1096 # check -normmproc
1097 cp "${MH_TEST_DIR}/Mail/inbox/19" "${MH_TEST_DIR}/Mail/inbox/20"
1098
1099 run_test 'mhfixmsg 19 -normmproc'
1100 check "${MH_TEST_DIR}/Mail/inbox/20" \
1101 "${MH_TEST_DIR}/Mail/inbox/,19" 'keep first'
1102
1103
1104 # check -rmmproc
1105 run_test 'mhfixmsg 20 -rmmproc true'
1106 if test -f '${MH_TEST_DIR}/Mail/inbox/20.backup'; then
1107 echo check of mhfixmsg -rmmproc FAILED, should not have created backup file
1108 failed=`expr ${failed:-0} + 1`
1109 fi
1110
1111
1112 # make sure there are no tmp files left over
1113 find "$MH_TEST_DIR/Mail" \( -name 'mhfix*' -o -name ',mhfix*' \) -print \
1114 >"$actual"
1115 cat >"$expected" <<EOF
1116 EOF
1117
1118 check "$expected" "$actual"
1119
1120
1121 exit $failed