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