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