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