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