]> diplodocus.org Git - nmh/blob - test/mhfixmsg/test-mhfixmsg
Check return values of system calls in several sbr .c files, found
[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]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="multipart/alternative";
469 boundary="subpart__1.1"
470
471 --subpart__1.1
472 Content-Type: text/plain; charset="iso-8859-1"
473 Content-Disposition: attachment; filename="test1.txt"
474
475 This is the first text/plain part, in a subpart.
476
477 --subpart__1.1--
478
479 This is additional content after the last subpart of the multipart.
480
481 ------- =_aaaaaaaaaa0
482 Content-Type: text/plain; charset="iso-8859-1"
483 Content-Disposition: attachment; filename="test2.txt"
484 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
485 Content-Transfer-Encoding: 8bit
486
487 This is the second text/plain part.
488
489 ------- =_aaaaaaaaaa0
490 Content-Type: text/plain; charset="iso-8859-1"
491 Content-Disposition: attachment; filename="test3.txt"
492
493 This is the third text/plain part.
494
495 ------- =_aaaaaaaaaa0
496 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
497 Content-Disposition: attachment; filename="test4.txt"
498 Content-Transfer-Encoding: 8bit
499
500 This is the fourth text/plain part.
501
502 ------- =_aaaaaaaaaa0--
503
504 This is additional content after the last subpart of the multipart.
505 EOF
506
507 cat >`mhpath new` <<EOF
508 To: recipient@example.com
509 From: sender@example.com
510 Subject: mhfixmsg decode test 2
511 MIME-Version: 1.0
512 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
513
514 This is additional content before the first subpart of the multipart.
515
516 ------- =_aaaaaaaaaa0
517 Content-Type: multipart/related;
518 type="multipart/alternative";
519 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 added to lone text/html in multipart/related
797 prepare_space >"$expected" <<EOF
798 MIME-Version: 1.0
799 Date: Tue, 26 Feb 2013 18:07:20 -0600
800 Subject: multipart/related, not /alternative
801 Content-Type: multipart/related;
802 boundary="----=_Part_90310_101292502.1"
803
804 ------=_Part_90310_101292502.1
805 Content-Type: multipart/alternative; boundary="----=_nmh-multipart1"
806
807 ------=_nmh-multipart1
808 Content-Type: text/plain; charset="us-ascii"
809 Content-Transfer-Encoding: 7bit
810
811 This is the real content.
812
813 ------=_nmh-multipart1
814 Content-Type: text/html; charset="us-ascii"
815 Content-Transfer-Encoding: 7bit
816
817 <html><head>
818 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
819 <title>HTML Content</title>
820 </head>
821 <body>
822 This is the real content.
823 </body>
824 </html>
825
826 ------=_nmh-multipart1--
827
828 ------=_Part_90310_101292502.1
829 Content-Type: text/plain; charset="us-ascii"
830 Content-Transfer-Encoding: 7bit
831
832 Your email client does not support HTML messages
833
834 ------=_Part_90310_101292502.1--
835 EOF
836
837 cat >`mhpath new` <<EOF
838 MIME-Version: 1.0
839 Date: Tue, 26 Feb 2013 18:07:20 -0600
840 Subject: multipart/related, not /alternative
841 Content-Type: multipart/related;
842 boundary="----=_Part_90310_101292502.1"
843
844 ------=_Part_90310_101292502.1
845 Content-Type: text/html; charset="us-ascii"
846 Content-Transfer-Encoding: 7bit
847
848 <html><head>
849 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
850 <title>HTML Content</title>
851 </head>
852 <body>
853 This is the real content.
854 </body>
855 </html>
856 ------=_Part_90310_101292502.1
857 Content-Type: text/plain; charset="us-ascii"
858 Content-Transfer-Encoding: 7bit
859
860 Your email client does not support HTML messages
861 ------=_Part_90310_101292502.1--
862 EOF
863
864 if [ $can_reformat_texthtml -eq 1 ]; then
865 #### lynx inserts multiple blank lines, so squeeze them.
866 run_prog mhfixmsg last -outfile - | squeeze_lines >"$actual"
867 check "$expected" "$actual" 'ignore space'
868 else
869 rm -f "$expected"
870 fi
871
872
873 # check handling of rfc822 message type
874 cat >"$expected" <<EOF
875 From: Test <test@example.com>
876 To: Some User <user@example.com>
877 Date: Fri, 29 Sep 2006 00:00:00
878 Message-Id: @test.nmh
879 Subject: message with message/rfc822 attachment
880 MIME-Version: 1.0
881 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
882
883 and some garbage before the attachment
884
885 ------- =_aaaaaaaaaa0
886 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
887 Content-Description: 1552
888 Content-Disposition: attachment; filename="1552"
889
890 From: Test <test@example.com>
891 To: <another_user@example.com>
892 Date: Thu, 28 Sep 2006 00:00:00
893 Message-Id: @test.nmh
894 Subject: message/rfc822 attachment
895
896 This is an RFC-822 message.
897
898 ------- =_aaaaaaaaaa0--
899
900 and some garbage at the end
901 EOF
902
903 cat >`mhpath new` <<EOF
904 From: Test <test@example.com>
905 To: Some User <user@example.com>
906 Date: Fri, 29 Sep 2006 00:00:00
907 Message-Id: @test.nmh
908 Subject: message with message/rfc822 attachment
909 MIME-Version: 1.0
910 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaa0"
911
912 and some garbage before the attachment
913
914 ------- =_aaaaaaaaaa0
915 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
916 Content-Description: 1552
917 Content-Disposition: attachment; filename="1552"
918
919 From: Test <test@example.com>
920 To: <another_user@example.com>
921 Date: Thu, 28 Sep 2006 00:00:00
922 Message-Id: @test.nmh
923 Subject: message/rfc822 attachment
924
925 This is an RFC-822 message.
926
927 ------- =_aaaaaaaaaa0--
928
929 and some garbage at the end
930 EOF
931
932 run_test 'mhfixmsg last -outfile '"$actual" ''
933 check "$expected" "$actual"
934
935
936 # check stripping of CRs from ASCII text context
937 cat >"$expected" <<EOF
938 MIME-Version: 1.0
939 From: sender@example.com
940 To: recipient@example.com
941 Subject: message with CR's
942 Date: Mon, 29 Apr 2013 11:51:45 -0400
943
944 There are two CR-LF pairs at the end of this sentence.
945
946 EOF
947
948 cat >`mhpath new` <<'EOF'
949 MIME-Version: 1.0
950 From: sender@example.com
951 To: recipient@example.com
952 Subject: message with CR's
953 Date: Mon, 29 Apr 2013 11:51:45 -0400
954
955 There are two CR-LF pairs at the end of this sentence.
956
957 EOF
958
959 run_prog mhfixmsg last -outfile "$actual"
960 check "$expected" "$actual"
961
962
963 # check -replacetextplain
964 prepare_space >"$expected" <<EOF
965 To: recipient@example.com
966 From: sender@example.com
967 Subject: mhfixmsg replacement of bad text/plain part test
968 MIME-Version: 1.0
969 Content-Type: multipart/alternative; boundary="----=_Part_876302"
970
971 ------=_Part_876302
972 Content-Type: text/plain; charset="UTF-8"
973 Content-Transfer-Encoding: 8bit
974
975 Yes, the text/plain part really was empty.
976
977 ------=_Part_876302
978 Content-Type: text/html; charset="UTF-8"
979 Content-Transfer-Encoding: 8bit
980 Content-Disposition: inline
981
982 <html><head>
983 <title>eticket</title>
984 </head>
985 <body>
986 Yes, the text/plain part really was empty.
987 </body>
988 </html>
989
990 ------=_Part_876302--
991 EOF
992
993 cat >`mhpath new` <<'EOF'
994 To: recipient@example.com
995 From: sender@example.com
996 Subject: mhfixmsg replacement of bad text/plain part test
997 MIME-Version: 1.0
998 Content-Type: multipart/alternative; boundary="----=_Part_876302"
999
1000 ------=_Part_876302
1001 Content-Type: text/plain; charset="iso-8859-15"
1002 Content-Transfer-Encoding: 7bit
1003 Content-Disposition: inline
1004
1005
1006
1007 ------=_Part_876302
1008 Content-Type: text/html; charset="UTF-8"
1009 Content-Transfer-Encoding: 8bit
1010 Content-Disposition: inline
1011
1012 <html><head>
1013 <title>eticket</title>
1014 </head>
1015 <body>
1016 Yes, the text/plain part really was empty.
1017 </body>
1018 </html>
1019
1020 ------=_Part_876302--
1021 EOF
1022
1023 if [ $can_reformat_texthtml -eq 1 ]; then
1024 #### lynx inserts multiple blank lines, so squeeze them.
1025 run_prog mhfixmsg last -replacetextplain -outfile - | \
1026 squeeze_lines > "$actual"
1027 check "$expected" "$actual" 'ignore space'
1028 else
1029 rm -f "$expected"
1030 fi
1031
1032
1033 # check -noreplacetextplain
1034 cat >"$expected" <<EOF
1035 To: recipient@example.com
1036 From: sender@example.com
1037 Subject: mhfixmsg replacement of bad text/plain part test
1038 MIME-Version: 1.0
1039 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1040
1041 ------=_Part_876302
1042 Content-Type: text/plain; charset="iso-8859-15"
1043 Content-Transfer-Encoding: 7bit
1044 Content-Disposition: inline
1045
1046
1047
1048 ------=_Part_876302
1049 Content-Type: text/html; charset="UTF-8"
1050 Content-Transfer-Encoding: 8bit
1051 Content-Disposition: inline
1052
1053 <html><head>
1054 <title>eticket</title>
1055 </head>
1056 <body>
1057 Yes, the text/plain part really was empty.
1058 </body>
1059 </html>
1060
1061 ------=_Part_876302--
1062 EOF
1063
1064 run_prog mhfixmsg last -replacetextplain -noreplacetextplain -outfile "$actual"
1065 check "$expected" "$actual"
1066
1067
1068 # check rmmproc
1069 cat >"$MH_TEST_DIR/Mail/rmmproc" <<'EOF'
1070 mv "$1" "$1.backup"
1071 EOF
1072 chmod a+x "${MH_TEST_DIR}/Mail/rmmproc"
1073 echo "rmmproc: ${MH_TEST_DIR}/Mail/rmmproc" >>"$MH"
1074 cp "${MH_TEST_DIR}/Mail/inbox/15" "${MH_TEST_DIR}/Mail/inbox/15.original"
1075
1076 run_test 'mhfixmsg 15' ''
1077 check "${MH_TEST_DIR}/Mail/inbox/15.backup" \
1078 "${MH_TEST_DIR}/Mail/inbox/15.original"
1079
1080
1081 # check -normmproc
1082 cp "${MH_TEST_DIR}/Mail/inbox/19" "${MH_TEST_DIR}/Mail/inbox/20"
1083
1084 run_test 'mhfixmsg 19 -normmproc'
1085 check "${MH_TEST_DIR}/Mail/inbox/20" \
1086 "${MH_TEST_DIR}/Mail/inbox/,19" 'keep first'
1087
1088
1089 # check -rmmproc
1090 run_test 'mhfixmsg 20 -rmmproc true'
1091 if test -f '${MH_TEST_DIR}/Mail/inbox/20.backup'; then
1092 echo check of mhfixmsg -rmmproc FAILED, should not have created backup file
1093 failed=`expr ${failed:-0} + 1`
1094 fi
1095
1096
1097 # make sure there are no tmp files left over
1098 find "$MH_TEST_DIR/Mail" \( -name 'mhfix*' -o -name ',mhfix*' \) -print \
1099 >"$actual"
1100 cat >"$expected" <<EOF
1101 EOF
1102
1103 check "$expected" "$actual"
1104
1105
1106 exit $failed