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