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