]> diplodocus.org Git - nmh/blob - test/mhfixmsg/test-mhfixmsg
Fixed a few very minor issues that cppcheck noticed.
[nmh] / test / mhfixmsg / test-mhfixmsg
1 #!/bin/sh
2 ######################################################
3 #
4 # Test mhfixmsg
5 #
6 ######################################################
7
8 set -e
9
10 if test -z "${MH_OBJ_DIR}"; then
11 srcdir=`dirname $0`/../..
12 MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
13 fi
14
15 . "${srcdir}/test/post/test-post-common.sh"
16
17 expected="$MH_TEST_DIR/test-mhfixmsg$$.expected"
18 expected_err="$MH_TEST_DIR/test-mhfixmsg$$.expected_err"
19 actual="$MH_TEST_DIR/test-mhfixmsg$$.actual"
20 actual_err="$MH_TEST_DIR/test-mhfixmsg$$.actual_err"
21
22 #### Make sure that html-to-text conversion is what we expect.
23 LC_ALL=en_US.UTF-8; export LC_ALL
24
25 if grep mhfixmsg-format-text/html "${MH_TEST_DIR}/Mail/mhn.defaults" \
26 >/dev/null; then
27 can_reformat_texthtml=1
28 if grep 'mhfixmsg-format-text/html.*w3m' "${MH_TEST_DIR}/Mail/mhn.defaults" \
29 >/dev/null; then
30 #### w3m uses $HOME/.w3m/, and creates it if it doesn't exist. To
31 #### support testing with non-writeable $HOME, and to not leave
32 #### relics from this test if it is writeable but doesn't already
33 #### have a .w3m, and to not depend on whatever is in that if it
34 #### does already exist, overwrite $HOME if using w3m.
35 HOME="$MHTMPDIR"; export HOME
36 fi
37 else
38 echo "$0: skipping -reformat check because no text browser was found"
39 can_reformat_texthtml=0
40 fi
41
42
43 # check -help
44 # Verified behavior consistent with compiled sendmail.
45 cat >"$expected" <<EOF
46 Usage: mhfixmsg [+folder] [msgs] [switches]
47 switches are:
48 -decodetext 8bit|7bit
49 -nodecodetext
50 -[no]textcharset
51 -[no]reformat
52 -[no]replacetextplain
53 -[no]fixboundary
54 -[no]fixcte
55 -file file
56 -outfile file
57 -rmmproc program
58 -normmproc
59 -[no]verbose
60 -version
61 -help
62 EOF
63
64 run_prog mhfixmsg -help >"$actual" 2>&1
65 check "$expected" "$actual"
66
67
68 # check -version
69 # Verified same behavior as compiled mhfixmsg.
70 case `mhfixmsg -version` in
71 mhfixmsg\ --*) ;;
72 *) printf '%s: mhfixmsg -version generated unexpected output\n' "$0" >&2
73 failed=`expr ${failed:-0} + 1`;;
74 esac
75
76
77 # check that non-MIME messages aren't modified
78 # check -outfile
79 run_test 'mhfixmsg first -outfile '"$actual" ''
80 check "`mhpath first`" "$actual" 'keep first'
81
82
83 # check that non-MIME messages with no bodies aren't modified
84 # check -outfile
85 cat >`mhpath new` <<EOF
86 From: Test <test@example.com>
87 To: Some User <user@example.com>
88 Date: Fri, 29 Sep 2006 00:00:00
89 Message-Id: @test.nmh
90 Subject: message with no body
91 EOF
92
93 run_test 'mhfixmsg last -outfile '"$actual" ''
94 check "`mhpath last`" "$actual"
95
96
97 # check -nofixcte
98 cat >"$MH_TEST_DIR"/Mail/inbox/11 <<EOF
99 From: Anon
100 To: Mailinglist
101 Subject: =?ISO-8859-15?Q?Re=3A_H=E5lla_linuxsystem_uppdaterade?=
102 User-Agent: Alpine 2.00 (DEB 1167 2008-08-23)
103 MIME-Version: 1.0
104 Content-Type: MULTIPART/MIXED;
105 BOUNDARY="----=_NextPart_000_0000_00000000.00000000"
106 Content-Transfer-Encoding: QUOTED-PRINTABLE
107
108 This message is in MIME format. The first part should be readable
109 text,
110 while the remaining parts are likely unreadable without MIME-aware
111 tools.
112
113 ------=_NextPart_000_0000_00000000.00000000
114 Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-15
115 Content-Transfer-Encoding: 8BIT
116
117 Some text in swedish.
118
119 Varf=C3=B6r inte anv=C3=A4nda...
120
121 ------=_NextPart_000_0000_00000000.00000000--
122
123 And some text after the last part.
124 EOF
125
126 cp -p "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/12
127
128 run_test 'mhfixmsg last -nofixcte' ''
129 check "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/12 'keep first'
130
131
132 # check -fixcte (enabled by default): fixup of erroneous C-T-E in multipart
133 # check -verbose
134 cat >"$expected" <<EOF
135 From: Anon
136 To: Mailinglist
137 Subject: =?ISO-8859-15?Q?Re=3A_H=E5lla_linuxsystem_uppdaterade?=
138 User-Agent: Alpine 2.00 (DEB 1167 2008-08-23)
139 MIME-Version: 1.0
140 Content-Type: MULTIPART/MIXED;
141 BOUNDARY="----=_NextPart_000_0000_00000000.00000000"
142 Nmh-REPLACED-INVALID-Content-Transfer-Encoding: QUOTED-PRINTABLE
143 Content-Transfer-Encoding: 8bit
144
145 This message is in MIME format. The first part should be readable
146 text,
147 while the remaining parts are likely unreadable without MIME-aware
148 tools.
149
150 ------=_NextPart_000_0000_00000000.00000000
151 Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-15
152 Content-Transfer-Encoding: 8BIT
153
154 Some text in swedish.
155
156 Varf=C3=B6r inte anv=C3=A4nda...
157
158 ------=_NextPart_000_0000_00000000.00000000--
159
160 And some text after the last part.
161 EOF
162
163 run_test 'mhfixmsg last -outfile '"$actual"' -verbose' \
164 "mhfixmsg: 11, replace Content-Transfer-Encoding of \
165 QUOTED-PRINTABLE with 8 bit"
166 check "$expected" "$actual" 'keep first'
167
168
169 # check with no options: checks backup
170 cp "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/11.original
171 folder last >/dev/null
172 run_test 'mhfixmsg' ''
173 check "$expected" "$MH_TEST_DIR"/Mail/inbox/11 'keep first'
174 cp "$MH_TEST_DIR"/Mail/inbox/11.original "$MH_TEST_DIR"/Mail/inbox/11
175 check "$MH_TEST_DIR"/Mail/inbox/,11 "$MH_TEST_DIR"/Mail/inbox/11.original
176
177
178 # check backup with -file
179 cp "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/11.original
180 folder last >/dev/null
181 run_test 'mhfixmsg -file '"$MH_TEST_DIR"/Mail/inbox/11 ''
182 check "$MH_TEST_DIR"/Mail/inbox/11 "$expected" 'keep first'
183 check "$MH_TEST_DIR"/Mail/inbox/,11 "$MH_TEST_DIR"/Mail/inbox/11.original
184
185
186 # check -reformat (enabled by default): addition of text/plain part
187 # to solitary text/html part
188 #
189 prepare_space >"$expected" <<EOF
190 MIME-Version: 1.0
191 From: sender@example.com
192 To: bonquiqui@example.com
193 Subject: rue
194 Date: Sat, 26 Jan 2013 17:37:53 -0500
195 Content-Type: multipart/alternative; boundary="----=_nmh-multipart"
196
197 ------=_nmh-multipart
198 Content-Type: text/plain; charset="Windows-1252"
199 Content-Transfer-Encoding: 8bit
200
201 Need to go! Need ... to ... go!
202
203 ------=_nmh-multipart
204 Content-Type: text/html; charset="Windows-1252"
205 Content-Transfer-Encoding: 8bit
206
207 <html>
208 <head>
209 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
210 <meta name="Generator" content="Microsoft Exchange Server">
211 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
212 </head>
213 <body>
214 <div>
215 <div>Need to go! Need ... to ... go!</div>
216 </body>
217 </html>
218
219 ------=_nmh-multipart--
220 EOF
221
222 cat >"$MH_TEST_DIR"/Mail/inbox/12 <<EOF
223 MIME-Version: 1.0
224 From: sender@example.com
225 To: bonquiqui@example.com
226 Subject: rue
227 Date: Sat, 26 Jan 2013 17:37:53 -0500
228 Content-Type: text/html; charset="Windows-1252"
229 Content-Transfer-Encoding: quoted-printable
230
231 <html>
232 <head>
233 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
234 252">
235 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
236 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
237 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
238 </head>
239 <body>
240 <div>
241 <div>Need to go! Need ... to ... go!</div>
242 </body>
243 </html>
244 EOF
245
246 if [ $can_reformat_texthtml -eq 1 ]; then
247 printf '%s\n' "mhfixmsg: 12, insert text/plain part
248 mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
249 >"$expected.err"
250
251 #### lynx inserts multiple blank lines, so squeeze them.
252 run_prog mhfixmsg last -outfile - -verbose 2>"$actual.err" | \
253 squeeze_lines >"$actual"
254 check "$expected" "$actual" 'ignore space'
255 check "$expected.err" "$actual.err"
256 else
257 rm -f "$expected"
258 fi
259
260
261 # check implicit -file with absolute pathname
262 run_test "mhfixmsg `mhpath last` -outfile /dev/null" ''
263
264
265 # check handling of boundary string that appears in message body
266 #
267 prepare_space >"$expected" <<EOF
268 MIME-Version: 1.0
269 From: sender@example.com
270 To: bonquiqui@example.com
271 Subject: rue
272 Date: Sat, 26 Jan 2013 17:37:53 -0500
273 Content-Type: multipart/alternative; boundary="----=_nmh-multipart-3"
274
275 ------=_nmh-multipart-3
276 Content-Type: text/plain; charset="Windows-1252"
277 Content-Transfer-Encoding: 8bit
278
279 ------=_nmh-multipart
280 ------=_nmh-multipart-1
281 ------=_nmh-multipart-2
282
283 ------=_nmh-multipart-3
284 Content-Type: text/html; charset="Windows-1252"
285 Content-Transfer-Encoding: 8bit
286
287 <html>
288 <head>
289 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
290 <meta name="Generator" content="Microsoft Exchange Server">
291 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
292 </head>
293 <body>
294 ------=_nmh-multipart<br>
295 ------=_nmh-multipart-1<br>
296 ------=_nmh-multipart-2<br>
297 </body>
298 </html>
299
300 ------=_nmh-multipart-3--
301 EOF
302
303 cat >"$MH_TEST_DIR"/Mail/inbox/12 <<EOF
304 MIME-Version: 1.0
305 From: sender@example.com
306 To: bonquiqui@example.com
307 Subject: rue
308 Date: Sat, 26 Jan 2013 17:37:53 -0500
309 Content-Type: text/html; charset="Windows-1252"
310 Content-Transfer-Encoding: quoted-printable
311
312 <html>
313 <head>
314 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
315 252">
316 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
317 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
318 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
319 </head>
320 <body>
321 ------=3D_nmh-multipart<br>
322 ------=3D_nmh-multipart-1<br>
323 ------=3D_nmh-multipart-2<br>
324 </body>
325 </html>
326 EOF
327
328 if [ $can_reformat_texthtml -eq 1 ]; then
329 printf '%s\n' "mhfixmsg: 12, insert text/plain part
330 mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
331 >"$expected.err"
332
333 #### lynx inserts multiple blank lines, so squeeze them.
334 run_prog mhfixmsg last -outfile - -verbose 2>"$actual.err" | \
335 squeeze_lines >"$actual"
336 check "$expected" "$actual" 'ignore space'
337 check "$expected.err" "$actual.err"
338 else
339 rm -f "$expected"
340 fi
341
342
343 # check -nodecode
344 prepare_space >"$expected" <<EOF
345 MIME-Version: 1.0
346 From: sender@example.com
347 To: bonquiqui@example.com
348 Subject: rue
349 Date: Sat, 26 Jan 2013 17:37:53 -0500
350 Content-Type: multipart/alternative; boundary="----=_nmh-multipart"
351
352 ------=_nmh-multipart
353 Content-Type: text/plain; charset="Windows-1252"
354 Content-Transfer-Encoding: 8bit
355
356 Need to go! Need ... to ... go!
357
358 ------=_nmh-multipart
359 Content-Type: text/html; charset="Windows-1252"
360 Content-Transfer-Encoding: quoted-printable
361
362 <html>
363 <head>
364 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-=
365 1252">
366 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
367 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pa=
368 dding-left: 4pt; border-left: #800000 2px solid; } --></style>
369 </head>
370 <body>
371 <div>
372 <div>Need to go! Need ... to ... go!</div>
373 </body>
374 </html>
375
376 ------=_nmh-multipart--
377 EOF
378
379 cat >"$MH_TEST_DIR"/Mail/inbox/12 <<EOF
380 MIME-Version: 1.0
381 From: sender@example.com
382 To: bonquiqui@example.com
383 Subject: rue
384 Date: Sat, 26 Jan 2013 17:37:53 -0500
385 Content-Type: text/html; charset="Windows-1252"
386 Content-Transfer-Encoding: quoted-printable
387
388 <html>
389 <head>
390 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
391 252">
392 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
393 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
394 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
395 </head>
396 <body>
397 <div>
398 <div>Need to go! Need ... to ... go!</div>
399 </body>
400 </html>
401 EOF
402
403 if [ $can_reformat_texthtml -eq 1 ]; then
404 printf '%s\n' 'mhfixmsg: 12, insert text/plain part' >"$expected.err"
405
406 #### lynx inserts multiple blank lines, so squeeze them.
407 run_prog mhfixmsg last -nodecode -outfile - -verbose 2>"$actual.err" | \
408 squeeze_lines >"$actual"
409 check "$expected" "$actual" 'ignore space'
410 check "$expected.err" "$actual.err"
411 else
412 rm -f "$expected"
413 fi
414
415
416 # check -decode (enabled by default)
417 cat >"$expected" <<EOF
418 To: recipient@example.com
419 From: sender@example.com
420 Subject: mhfixmsg decode test
421 MIME-Version: 1.0
422 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
423
424 ------- =_aaaaaaaaaa0
425 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
426 Content-Disposition: attachment; filename="test4.txt"
427 Content-Transfer-Encoding: 8bit
428
429 This is a text/plain part.
430
431 ------- =_aaaaaaaaaa0--
432 EOF
433
434 cat >`mhpath new` <<EOF
435 To: recipient@example.com
436 From: sender@example.com
437 Subject: mhfixmsg decode test
438 MIME-Version: 1.0
439 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
440
441 ------- =_aaaaaaaaaa0
442 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
443 Content-Disposition: attachment; filename="test4.txt"
444 Content-Transfer-Encoding: base64
445
446 VGhpcyBpcyBhIHRleHQvcGxhaW4gcGFydC4K
447
448 ------- =_aaaaaaaaaa0--
449 EOF
450
451 run_prog mhfixmsg last -outfile "$actual"
452 check "$expected" "$actual"
453
454
455 # check -decode with more complicated content structure
456 cat >$expected <<EOF
457 To: recipient@example.com
458 From: sender@example.com
459 Subject: mhfixmsg decode test 2
460 MIME-Version: 1.0
461 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
462
463 This is additional content before the first subpart of the multipart.
464
465 ------- =_aaaaaaaaaa0
466 Content-Type: multipart/related;
467 type="multipart/alternative";
468 boundary="subpart__1.1"
469
470 --subpart__1.1
471 Content-Type: text/plain; charset="iso-8859-1"
472 Content-Disposition: attachment; filename="test1.txt"
473
474 This is the first text/plain part, in a subpart.
475
476 --subpart__1.1--
477
478 This is additional content after the last subpart of the multipart.
479
480 ------- =_aaaaaaaaaa0
481 Content-Type: text/plain; charset="iso-8859-1"
482 Content-Disposition: attachment; filename="test2.txt"
483 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
484 Content-Transfer-Encoding: 8bit
485
486 This is the second text/plain part.
487
488 ------- =_aaaaaaaaaa0
489 Content-Type: text/plain; charset="iso-8859-1"
490 Content-Disposition: attachment; filename="test3.txt"
491
492 This is the third text/plain part.
493
494 ------- =_aaaaaaaaaa0
495 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
496 Content-Disposition: attachment; filename="test4.txt"
497 Content-Transfer-Encoding: 8bit
498
499 This is the fourth text/plain part.
500
501 ------- =_aaaaaaaaaa0--
502
503 This is additional content after the last subpart of the multipart.
504 EOF
505
506 cat >`mhpath new` <<EOF
507 To: recipient@example.com
508 From: sender@example.com
509 Subject: mhfixmsg decode test 2
510 MIME-Version: 1.0
511 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
512
513 This is additional content before the first subpart of the multipart.
514
515 ------- =_aaaaaaaaaa0
516 Content-Type: multipart/related;
517 type="multipart/alternative";
518 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 added to lone text/html in multipart/related
796 prepare_space >"$expected" <<EOF
797 MIME-Version: 1.0
798 Date: Tue, 26 Feb 2013 18:07:20 -0600
799 Subject: multipart/related, not /alternative
800 Content-Type: multipart/related;
801 boundary="----=_Part_90310_101292502.1"
802
803 ------=_Part_90310_101292502.1
804 Content-Type: multipart/alternative; boundary="----=_nmh-multipart1"
805
806 ------=_nmh-multipart1
807 Content-Type: text/plain; charset="us-ascii"
808 Content-Transfer-Encoding: 7bit
809
810 This is the real content.
811
812 ------=_nmh-multipart1
813 Content-Type: text/html; charset="us-ascii"
814 Content-Transfer-Encoding: 7bit
815
816 <html><head>
817 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
818 <title>HTML Content</title>
819 </head>
820 <body>
821 This is the real content.
822 </body>
823 </html>
824
825 ------=_nmh-multipart1--
826
827 ------=_Part_90310_101292502.1
828 Content-Type: text/plain; charset="us-ascii"
829 Content-Transfer-Encoding: 7bit
830
831 Your email client does not support HTML messages
832
833 ------=_Part_90310_101292502.1--
834 EOF
835
836 cat >`mhpath new` <<EOF
837 MIME-Version: 1.0
838 Date: Tue, 26 Feb 2013 18:07:20 -0600
839 Subject: multipart/related, not /alternative
840 Content-Type: multipart/related;
841 boundary="----=_Part_90310_101292502.1"
842
843 ------=_Part_90310_101292502.1
844 Content-Type: text/html; charset="us-ascii"
845 Content-Transfer-Encoding: 7bit
846
847 <html><head>
848 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
849 <title>HTML Content</title>
850 </head>
851 <body>
852 This is the real content.
853 </body>
854 </html>
855 ------=_Part_90310_101292502.1
856 Content-Type: text/plain; charset="us-ascii"
857 Content-Transfer-Encoding: 7bit
858
859 Your email client does not support HTML messages
860 ------=_Part_90310_101292502.1--
861 EOF
862
863 if [ $can_reformat_texthtml -eq 1 ]; then
864 #### lynx inserts multiple blank lines, so squeeze them.
865 run_prog mhfixmsg last -outfile - | squeeze_lines >"$actual"
866 check "$expected" "$actual" 'ignore space'
867 else
868 rm -f "$expected"
869 fi
870
871
872 # check handling of rfc822 message type
873 cat >"$expected" <<EOF
874 From: Test <test@example.com>
875 To: Some User <user@example.com>
876 Date: Fri, 29 Sep 2006 00:00:00
877 Message-Id: @test.nmh
878 Subject: message with message/rfc822 attachment
879 MIME-Version: 1.0
880 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
881
882 and some garbage before the attachment
883
884 ------- =_aaaaaaaaaa0
885 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
886 Content-Description: 1552
887 Content-Disposition: attachment; filename="1552"
888
889 From: Test <test@example.com>
890 To: <another_user@example.com>
891 Date: Thu, 28 Sep 2006 00:00:00
892 Message-Id: @test.nmh
893 Subject: message/rfc822 attachment
894
895 This is an RFC-822 message.
896
897 ------- =_aaaaaaaaaa0--
898
899 and some garbage at the end
900 EOF
901
902 cat >`mhpath new` <<EOF
903 From: Test <test@example.com>
904 To: Some User <user@example.com>
905 Date: Fri, 29 Sep 2006 00:00:00
906 Message-Id: @test.nmh
907 Subject: message with message/rfc822 attachment
908 MIME-Version: 1.0
909 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaa0"
910
911 and some garbage before the attachment
912
913 ------- =_aaaaaaaaaa0
914 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
915 Content-Description: 1552
916 Content-Disposition: attachment; filename="1552"
917
918 From: Test <test@example.com>
919 To: <another_user@example.com>
920 Date: Thu, 28 Sep 2006 00:00:00
921 Message-Id: @test.nmh
922 Subject: message/rfc822 attachment
923
924 This is an RFC-822 message.
925
926 ------- =_aaaaaaaaaa0--
927
928 and some garbage at the end
929 EOF
930
931 run_test 'mhfixmsg last -outfile '"$actual" ''
932 check "$expected" "$actual"
933
934
935 # check stripping of CRs from ASCII text context
936 cat >"$expected" <<EOF
937 MIME-Version: 1.0
938 From: sender@example.com
939 To: recipient@example.com
940 Subject: message with CR's
941 Date: Mon, 29 Apr 2013 11:51:45 -0400
942
943 There are two CR-LF pairs at the end of this sentence.
944
945 EOF
946
947 cat >`mhpath new` <<'EOF'
948 MIME-Version: 1.0
949 From: sender@example.com
950 To: recipient@example.com
951 Subject: message with CR's
952 Date: Mon, 29 Apr 2013 11:51:45 -0400
953
954 There are two CR-LF pairs at the end of this sentence.
955
956 EOF
957
958 run_prog mhfixmsg last -outfile "$actual"
959 check "$expected" "$actual"
960
961
962 # check -replacetextplain
963 prepare_space >"$expected" <<EOF
964 To: recipient@example.com
965 From: sender@example.com
966 Subject: mhfixmsg replacement of bad text/plain part test
967 MIME-Version: 1.0
968 Content-Type: multipart/alternative; boundary="----=_Part_876302"
969
970 ------=_Part_876302
971 Content-Type: text/plain; charset="UTF-8"
972 Content-Transfer-Encoding: 8bit
973
974 Yes, the text/plain part really was empty.
975
976 ------=_Part_876302
977 Content-Type: text/html; charset="UTF-8"
978 Content-Transfer-Encoding: 8bit
979 Content-Disposition: inline
980
981 <html><head>
982 <title>eticket</title>
983 </head>
984 <body>
985 Yes, the text/plain part really was empty.
986 </body>
987 </html>
988
989 ------=_Part_876302--
990 EOF
991
992 cat >`mhpath new` <<'EOF'
993 To: recipient@example.com
994 From: sender@example.com
995 Subject: mhfixmsg replacement of bad text/plain part test
996 MIME-Version: 1.0
997 Content-Type: multipart/alternative; boundary="----=_Part_876302"
998
999 ------=_Part_876302
1000 Content-Type: text/plain; charset="iso-8859-15"
1001 Content-Transfer-Encoding: 7bit
1002 Content-Disposition: inline
1003
1004
1005
1006 ------=_Part_876302
1007 Content-Type: text/html; charset="UTF-8"
1008 Content-Transfer-Encoding: 8bit
1009 Content-Disposition: inline
1010
1011 <html><head>
1012 <title>eticket</title>
1013 </head>
1014 <body>
1015 Yes, the text/plain part really was empty.
1016 </body>
1017 </html>
1018
1019 ------=_Part_876302--
1020 EOF
1021
1022 if [ $can_reformat_texthtml -eq 1 ]; then
1023 #### lynx inserts multiple blank lines, so squeeze them.
1024 run_prog mhfixmsg last -replacetextplain -outfile - | \
1025 squeeze_lines > "$actual"
1026 check "$expected" "$actual" 'ignore space'
1027 else
1028 rm -f "$expected"
1029 fi
1030
1031
1032 # check -noreplacetextplain
1033 cat >"$expected" <<EOF
1034 To: recipient@example.com
1035 From: sender@example.com
1036 Subject: mhfixmsg replacement of bad text/plain part test
1037 MIME-Version: 1.0
1038 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1039
1040 ------=_Part_876302
1041 Content-Type: text/plain; charset="iso-8859-15"
1042 Content-Transfer-Encoding: 7bit
1043 Content-Disposition: inline
1044
1045
1046
1047 ------=_Part_876302
1048 Content-Type: text/html; charset="UTF-8"
1049 Content-Transfer-Encoding: 8bit
1050 Content-Disposition: inline
1051
1052 <html><head>
1053 <title>eticket</title>
1054 </head>
1055 <body>
1056 Yes, the text/plain part really was empty.
1057 </body>
1058 </html>
1059
1060 ------=_Part_876302--
1061 EOF
1062
1063 run_prog mhfixmsg last -replacetextplain -noreplacetextplain -outfile "$actual"
1064 check "$expected" "$actual"
1065
1066
1067 # check rmmproc
1068 cat >"$MH_TEST_DIR/Mail/rmmproc" <<'EOF'
1069 mv "$1" "$1.backup"
1070 EOF
1071 chmod a+x "${MH_TEST_DIR}/Mail/rmmproc"
1072 echo "rmmproc: ${MH_TEST_DIR}/Mail/rmmproc" >>"$MH"
1073 cp "${MH_TEST_DIR}/Mail/inbox/15" "${MH_TEST_DIR}/Mail/inbox/15.original"
1074
1075 run_test 'mhfixmsg 15' ''
1076 check "${MH_TEST_DIR}/Mail/inbox/15.backup" \
1077 "${MH_TEST_DIR}/Mail/inbox/15.original"
1078
1079
1080 # check -normmproc
1081 cp "${MH_TEST_DIR}/Mail/inbox/19" "${MH_TEST_DIR}/Mail/inbox/20"
1082
1083 run_test 'mhfixmsg 19 -normmproc'
1084 check "${MH_TEST_DIR}/Mail/inbox/20" \
1085 "${MH_TEST_DIR}/Mail/inbox/,19" 'keep first'
1086
1087
1088 # check -rmmproc
1089 run_test 'mhfixmsg 20 -rmmproc true'
1090 if test -f '${MH_TEST_DIR}/Mail/inbox/20.backup'; then
1091 echo check of mhfixmsg -rmmproc FAILED, should not have created backup file
1092 failed=`expr ${failed:-0} + 1`
1093 fi
1094
1095
1096 # make sure there are no tmp files left over
1097 find "$MH_TEST_DIR/Mail" \( -name 'mhfix*' -o -name ',mhfix*' \) -print \
1098 >"$actual"
1099 cat >"$expected" <<EOF
1100 EOF
1101
1102 check "$expected" "$actual"
1103
1104
1105 exit $failed