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