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