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