]> diplodocus.org Git - nmh/blob - test/mhfixmsg/test-mhfixmsg
Removed color-tests from AM_INIT_AUTOMAKE because the build
[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]fixboundary
45 -[no]fixcte
46 -file file
47 -outfile file
48 -[no]verbose
49 -version
50 -help
51 EOF
52
53 mhfixmsg -help >"$actual" 2>&1
54 check "$expected" "$actual"
55
56
57 # check -version
58 # Verified same behavior as compiled mhfixmsg.
59 case `mhfixmsg -version` in
60 mhfixmsg\ --*) ;;
61 *) printf '%s: mhfixmsg -version generated unexpected output\n' "$0" >&2
62 failed=`expr ${failed:-0} + 1`;;
63 esac
64
65
66 # check that non-MIME messages aren't modified
67 # check -outfile
68 run_test 'mhfixmsg first -outfile '"$actual" ''
69 check "`mhpath first`" "$actual" 'keep first'
70
71
72 # check that non-MIME messages with no bodies aren't modified
73 # check -outfile
74 cat >`mhpath new` <<EOF
75 From: Test <test@example.com>
76 To: Some User <user@example.com>
77 Date: Fri, 29 Sep 2006 00:00:00
78 Message-Id: @test.nmh
79 Subject: message with no body
80 EOF
81
82 run_test 'mhfixmsg last -outfile '"$actual" ''
83 check "`mhpath last`" "$actual"
84
85
86 # check -nofixcte
87 cat >"$MH_TEST_DIR"/Mail/inbox/11 <<EOF
88 From: Anon
89 To: Mailinglist
90 Subject: =?ISO-8859-15?Q?Re=3A_H=E5lla_linuxsystem_uppdaterade?=
91 User-Agent: Alpine 2.00 (DEB 1167 2008-08-23)
92 MIME-Version: 1.0
93 Content-Type: MULTIPART/MIXED;
94 BOUNDARY="----=_NextPart_000_0000_00000000.00000000"
95 Content-Transfer-Encoding: QUOTED-PRINTABLE
96
97 This message is in MIME format. The first part should be readable
98 text,
99 while the remaining parts are likely unreadable without MIME-aware
100 tools.
101
102 ------=_NextPart_000_0000_00000000.00000000
103 Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-15
104 Content-Transfer-Encoding: 8BIT
105
106 Some text in swedish.
107
108 Varf=C3=B6r inte anv=C3=A4nda...
109
110 ------=_NextPart_000_0000_00000000.00000000--
111
112 And some text after the last part.
113 EOF
114
115 cp -p "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/12
116
117 run_test 'mhfixmsg last -nofixcte' ''
118 check "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/12 'keep first'
119
120
121 # check -fixcte (enabled by default): fixup of erroneous C-T-E in multipart
122 # check -verbose
123 cat >"$expected" <<EOF
124 From: Anon
125 To: Mailinglist
126 Subject: =?ISO-8859-15?Q?Re=3A_H=E5lla_linuxsystem_uppdaterade?=
127 User-Agent: Alpine 2.00 (DEB 1167 2008-08-23)
128 MIME-Version: 1.0
129 Content-Type: MULTIPART/MIXED;
130 BOUNDARY="----=_NextPart_000_0000_00000000.00000000"
131 Nmh-REPLACED-INVALID-Content-Transfer-Encoding: QUOTED-PRINTABLE
132 Content-Transfer-Encoding: 8bit
133
134 This message is in MIME format. The first part should be readable
135 text,
136 while the remaining parts are likely unreadable without MIME-aware
137 tools.
138
139 ------=_NextPart_000_0000_00000000.00000000
140 Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-15
141 Content-Transfer-Encoding: 8BIT
142
143 Some text in swedish.
144
145 Varf=C3=B6r inte anv=C3=A4nda...
146
147 ------=_NextPart_000_0000_00000000.00000000--
148
149 And some text after the last part.
150 EOF
151
152 run_test 'mhfixmsg last -outfile '"$actual"' -verbose' \
153 "mhfixmsg: 11, replace Content-Transfer-Encoding of \
154 QUOTED-PRINTABLE with 8 bit"
155 check "$expected" "$actual" 'keep first'
156
157
158 # check with no options: checks backup
159 cp "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/11.original
160 folder last >/dev/null
161 run_test 'mhfixmsg' ''
162 check "$expected" "$MH_TEST_DIR"/Mail/inbox/11 'keep first'
163 cp "$MH_TEST_DIR"/Mail/inbox/11.original "$MH_TEST_DIR"/Mail/inbox/11
164 check "$MH_TEST_DIR"/Mail/inbox/,11 "$MH_TEST_DIR"/Mail/inbox/11.original
165
166
167 # check backup with -file
168 cp "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/11.original
169 folder last >/dev/null
170 run_test 'mhfixmsg -file '"$MH_TEST_DIR"/Mail/inbox/11 ''
171 check "$MH_TEST_DIR"/Mail/inbox/11 "$expected" 'keep first'
172 check "$MH_TEST_DIR"/Mail/inbox/,11 "$MH_TEST_DIR"/Mail/inbox/11.original
173
174
175 # check -reformat (enabled by default): addition of text/plain part
176 # to solitary text/html part
177 #
178 cat >"$expected" <<EOF
179 MIME-Version: 1.0
180 From: sender@example.com
181 To: bonquiqui@example.com
182 Subject: rue
183 Date: Sat, 26 Jan 2013 17:37:53 -0500
184 Content-Type: multipart/alternative; boundary="----=_nmh-multipart"
185
186 ------=_nmh-multipart
187 Content-Type: text/plain; charset="Windows-1252"
188 Content-Transfer-Encoding: 8bit
189
190 Need to go! Need ... to ... go!
191
192 ------=_nmh-multipart
193 Content-Type: text/html; charset="Windows-1252"
194 Content-Transfer-Encoding: 8bit
195
196 <html>
197 <head>
198 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
199 <meta name="Generator" content="Microsoft Exchange Server">
200 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
201 </head>
202 <body>
203 <div>
204 <div>Need to go! Need ... to ... go!</div>
205 </body>
206 </html>
207
208 ------=_nmh-multipart--
209 EOF
210
211 cat >"$MH_TEST_DIR"/Mail/inbox/12 <<EOF
212 MIME-Version: 1.0
213 From: sender@example.com
214 To: bonquiqui@example.com
215 Subject: rue
216 Date: Sat, 26 Jan 2013 17:37:53 -0500
217 Content-Type: text/html; charset="Windows-1252"
218 Content-Transfer-Encoding: quoted-printable
219
220 <html>
221 <head>
222 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
223 252">
224 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
225 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
226 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
227 </head>
228 <body>
229 <div>
230 <div>Need to go! Need ... to ... go!</div>
231 </body>
232 </html>
233 EOF
234
235 if [ $can_reformat_texthtml -eq 1 ]; then
236 printf '%s\n' "mhfixmsg: 12, insert text/plain part
237 mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
238 >"$expected.err"
239
240 #### lynx inserts multiple blank lines, so use uniq to squeeze them.
241 mhfixmsg last -outfile - -verbose 2>"$actual.err" | uniq >"$actual"
242 check "$expected" "$actual"
243 check "$expected.err" "$actual.err"
244 fi
245
246
247 # check handling of boundary string that appears in message body
248 #
249 cat >"$expected" <<EOF
250 MIME-Version: 1.0
251 From: sender@example.com
252 To: bonquiqui@example.com
253 Subject: rue
254 Date: Sat, 26 Jan 2013 17:37:53 -0500
255 Content-Type: multipart/alternative; boundary="----=_nmh-multipart-3"
256
257 ------=_nmh-multipart-3
258 Content-Type: text/plain; charset="Windows-1252"
259 Content-Transfer-Encoding: 8bit
260
261 ------=_nmh-multipart
262 ------=_nmh-multipart-1
263 ------=_nmh-multipart-2
264
265 ------=_nmh-multipart-3
266 Content-Type: text/html; charset="Windows-1252"
267 Content-Transfer-Encoding: 8bit
268
269 <html>
270 <head>
271 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
272 <meta name="Generator" content="Microsoft Exchange Server">
273 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
274 </head>
275 <body>
276 ------=_nmh-multipart<br>
277 ------=_nmh-multipart-1<br>
278 ------=_nmh-multipart-2<br>
279 </body>
280 </html>
281
282 ------=_nmh-multipart-3--
283 EOF
284
285 cat >"$MH_TEST_DIR"/Mail/inbox/12 <<EOF
286 MIME-Version: 1.0
287 From: sender@example.com
288 To: bonquiqui@example.com
289 Subject: rue
290 Date: Sat, 26 Jan 2013 17:37:53 -0500
291 Content-Type: text/html; charset="Windows-1252"
292 Content-Transfer-Encoding: quoted-printable
293
294 <html>
295 <head>
296 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
297 252">
298 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
299 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
300 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
301 </head>
302 <body>
303 ------=3D_nmh-multipart<br>
304 ------=3D_nmh-multipart-1<br>
305 ------=3D_nmh-multipart-2<br>
306 </body>
307 </html>
308 EOF
309
310 if [ $can_reformat_texthtml -eq 1 ]; then
311 printf '%s\n' "mhfixmsg: 12, insert text/plain part
312 mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
313 >"$expected.err"
314
315 #### lynx inserts multiple blank lines, so use uniq to squeeze them.
316 mhfixmsg last -outfile - -verbose 2>"$actual.err" | uniq >"$actual"
317 check "$expected" "$actual"
318 check "$expected.err" "$actual.err"
319 fi
320
321
322 # check -nodecode
323 cat >"$expected" <<EOF
324 MIME-Version: 1.0
325 From: sender@example.com
326 To: bonquiqui@example.com
327 Subject: rue
328 Date: Sat, 26 Jan 2013 17:37:53 -0500
329 Content-Type: multipart/alternative; boundary="----=_nmh-multipart"
330
331 ------=_nmh-multipart
332 Content-Type: text/plain; charset="Windows-1252"
333 Content-Transfer-Encoding: 8bit
334
335 Need to go! Need ... to ... go!
336
337 ------=_nmh-multipart
338 Content-Type: text/html; charset="Windows-1252"
339 Content-Transfer-Encoding: quoted-printable
340
341 <html>
342 <head>
343 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-=
344 1252">
345 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
346 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pa=
347 dding-left: 4pt; border-left: #800000 2px solid; } --></style>
348 </head>
349 <body>
350 <div>
351 <div>Need to go! Need ... to ... go!</div>
352 </body>
353 </html>
354
355 ------=_nmh-multipart--
356 EOF
357
358 cat >"$MH_TEST_DIR"/Mail/inbox/12 <<EOF
359 MIME-Version: 1.0
360 From: sender@example.com
361 To: bonquiqui@example.com
362 Subject: rue
363 Date: Sat, 26 Jan 2013 17:37:53 -0500
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-1=
370 252">
371 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
372 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
373 ding-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 EOF
381
382 if [ $can_reformat_texthtml -eq 1 ]; then
383 printf '%s\n' 'mhfixmsg: 12, insert text/plain part' >"$expected.err"
384
385 #### lynx inserts multiple blank lines, so use uniq to squeeze them.
386 mhfixmsg last -nodecode -outfile - -verbose 2>"$actual.err" | uniq >"$actual"
387 check "$expected" "$actual"
388 check "$expected.err" "$actual.err"
389 fi
390
391
392 # check -decode (enabled by default)
393 cat >"$expected" <<EOF
394 To: recipient@example.com
395 From: sender@example.com
396 Subject: mhfixmsg decode test
397 MIME-Version: 1.0
398 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
399
400 ------- =_aaaaaaaaaa0
401 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
402 Content-Disposition: attachment; filename="test4.txt"
403 Content-Transfer-Encoding: 8bit
404
405 This is a text/plain part.
406
407 ------- =_aaaaaaaaaa0--
408 EOF
409
410 msgfile=`mhpath new`
411 cat >$msgfile <<EOF
412 To: recipient@example.com
413 From: sender@example.com
414 Subject: mhfixmsg decode test
415 MIME-Version: 1.0
416 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
417
418 ------- =_aaaaaaaaaa0
419 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
420 Content-Disposition: attachment; filename="test4.txt"
421 Content-Transfer-Encoding: base64
422
423 VGhpcyBpcyBhIHRleHQvcGxhaW4gcGFydC4K
424
425 ------- =_aaaaaaaaaa0--
426 EOF
427
428 mhfixmsg last -outfile "$actual"
429 check "$expected" "$actual"
430
431
432 # check -decode with more complicated content structure
433 cat >$expected <<EOF
434 To: recipient@example.com
435 From: sender@example.com
436 Subject: mhfixmsg decode test 2
437 MIME-Version: 1.0
438 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
439
440 This is additional content before the first subpart of the multipart.
441
442 ------- =_aaaaaaaaaa0
443 Content-Type: multipart/related;
444 type="multipart/alternative";
445 boundary="subpart__1.1"
446
447 --subpart__1.1
448 Content-Type: text/plain; charset="iso-8859-1"
449 Content-Disposition: attachment; filename="test1.txt"
450
451 This is the first text/plain part, in a subpart.
452
453 --subpart__1.1--
454
455 This is additional content after the last subpart of the multipart.
456
457 ------- =_aaaaaaaaaa0
458 Content-Type: text/plain; charset="iso-8859-1"
459 Content-Disposition: attachment; filename="test2.txt"
460 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
461 Content-Transfer-Encoding: 8bit
462
463 This is the second text/plain part.
464
465 ------- =_aaaaaaaaaa0
466 Content-Type: text/plain; charset="iso-8859-1"
467 Content-Disposition: attachment; filename="test3.txt"
468
469 This is the third text/plain part.
470
471 ------- =_aaaaaaaaaa0
472 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
473 Content-Disposition: attachment; filename="test4.txt"
474 Content-Transfer-Encoding: 8bit
475
476 This is the fourth text/plain part.
477
478 ------- =_aaaaaaaaaa0--
479
480 This is additional content after the last subpart of the multipart.
481 EOF
482
483 msgfile=`mhpath new`
484 cat >$msgfile <<EOF
485 To: recipient@example.com
486 From: sender@example.com
487 Subject: mhfixmsg decode test 2
488 MIME-Version: 1.0
489 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
490
491 This is additional content before the first subpart of the multipart.
492
493 ------- =_aaaaaaaaaa0
494 Content-Type: multipart/related;
495 type="multipart/alternative";
496 boundary="subpart__1.1"
497
498 --subpart__1.1
499 Content-Type: text/plain; charset="iso-8859-1"
500 Content-Disposition: attachment; filename="test1.txt"
501
502 This is the first text/plain part, in a subpart.
503
504 --subpart__1.1--
505
506 This is additional content after the last subpart of the multipart.
507
508 ------- =_aaaaaaaaaa0
509 Content-Type: text/plain; charset="iso-8859-1"
510 Content-Disposition: attachment; filename="test2.txt"
511 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
512 Content-Transfer-Encoding: quoted-printable
513
514 This is the second text/plain part.
515
516 ------- =_aaaaaaaaaa0
517 Content-Type: text/plain; charset="iso-8859-1"
518 Content-Disposition: attachment; filename="test3.txt"
519
520 This is the third text/plain part.
521
522 ------- =_aaaaaaaaaa0
523 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
524 Content-Disposition: attachment; filename="test4.txt"
525 Content-Transfer-Encoding: base64
526
527 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4K
528
529 ------- =_aaaaaaaaaa0--
530
531 This is additional content after the last subpart of the multipart.
532 EOF
533 mhfixmsg last -outfile "$actual"
534 check "$expected" "$actual"
535
536
537 # check attempted -decode of binary text
538 #### Generated the encoded text below with:
539 #### $ printf '\x0d\xbd\xb2=\xbc\n' | base64
540 msgfile=`mhpath new`
541 cat >$msgfile <<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 mhfixmsg last
559 check `mhpath last` "$expected" 'keep first'
560
561
562 # check -decode of binary text
563 printf "%s\x0d\xbd\xb2=\xbc%s" "To: recipient@example.com
564 From: sender@example.com
565 Subject: mhfixmsg binary decode test
566 MIME-Version: 1.0
567 Content-Type: multipart/mixed; boundary=\"----- =_aaaaaaaaaa0\"
568
569 ------- =_aaaaaaaaaa0
570 Content-Type: text/plain; charset=\"iso-8859-1\"; name=\"square.txt\"
571 Content-Transfer-Encoding: binary
572
573 " "
574
575 ------- =_aaaaaaaaaa0--
576 " >"$expected"
577 ## output_content() in mhoutsbr.c can't handle binary content.
578 ## mhfixmsg last -decodetext binary -outfile "$actual"
579 ## check "$expected" "$actual"
580 rm -f "$expected"
581 rmm last
582
583
584 # check -textcodeset
585 # Also checks preservation of attributes after one (charset) that is
586 # modified.
587 cat >"$expected" <<EOF
588 To: recipient@example.com
589 From: sender@example.com
590 Subject: mhfixmsg textcodeset test
591 MIME-Version: 1.0
592 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
593
594 ------- =_aaaaaaaaaa0
595 Content-Type: text/plain; charset="utf-8"; name="square.txt"
596 Content-Disposition: attachment; filename="square.txt"
597 Content-Transfer-Encoding: 8bit
598
599 ½²=¼
600
601 ------- =_aaaaaaaaaa0--
602 EOF
603
604 #### Generated the encoded text below with:
605 #### $ printf '\xbd\xb2=\xbc\n' | base64
606 msgfile=`mhpath new`
607 cat >$msgfile <<EOF
608 To: recipient@example.com
609 From: sender@example.com
610 Subject: mhfixmsg textcodeset test
611 MIME-Version: 1.0
612 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
613
614 ------- =_aaaaaaaaaa0
615 Content-Type: text/plain; charset="iso-8859-1"; name="square.txt"
616 Content-Disposition: attachment; filename="square.txt"
617 Content-Transfer-Encoding: base64
618
619 vbI9vAo=
620
621 ------- =_aaaaaaaaaa0--
622 EOF
623
624 set +e
625 mhfixmsg last -textcodeset utf-8 -outfile "$actual" 2>"$actual.err"
626 if grep "mhfixmsg: Can't convert .* to .* without iconv" "$actual.err" \
627 >/dev/null; then
628 echo skipping -textcodeset check because nmh was built without iconv
629 set +e
630 rm -f "$expected" "$actual" "$actual.err"
631 else
632 set +e
633 check "$expected" "$actual"
634 rm "$actual.err"
635 fi
636
637
638 # check -nofixboundary
639 cat >"$expected" <<EOF
640 EOF
641
642 cat >`mhpath new` <<EOF
643 Date: Fri, 13 May 2011 08:21:12 -0500
644 Content-Type: multipart/alternative;
645 boundary="----=_NextPart_000_1781A17_01CC1147.81E9467A"
646 Content-Transfer-Encoding: 8bit
647 MIME-Version: 1.0
648 From: <sender@example.com>
649 To: <recipient@example.com>
650 Subject: mhfixmsg bad boundary test
651
652 This is a multi-part message in MIME format.
653
654 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4
655 Content-Type: text/plain
656
657 The boundaries of this part don't match the header boundary.
658
659 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4--
660 EOF
661
662 cp -p `mhpath last` `mhpath new`
663
664 run_test 'mhfixmsg last -nofixboundary' ''
665 check "$MH_TEST_DIR"/Mail/inbox/16 "$MH_TEST_DIR"/Mail/inbox/17 'keep first'
666
667
668 # check that message is not output when fed through stdin
669 mhfixmsg -file - -verbose <`mhpath last` >"$actual" 2>"$actual.err"
670 check "$expected" "$actual"
671 if grep "mhfixmsg: $MH_TEST_DIR/Mail/.*, fix multipart boundary" \
672 "$actual.err" >/dev/null; then
673 rm -f "$actual.err"
674 else
675 echo "$0: test failed, output is in $actual.err."
676 failed=`expr ${failed:-0} + 1`
677 fi
678
679
680 # check fixup of erroneous boundary in multipart (-fixboundary,
681 # enabled by default)
682 # check -verbose
683 cat >"$expected" <<EOF
684 Date: Fri, 13 May 2011 08:21:12 -0500
685 Content-Type: multipart/alternative;
686 boundary="----=_NextPart_000_1781A1A_01CC1147.81EBA8D4"
687 Content-Transfer-Encoding: 8bit
688 MIME-Version: 1.0
689 From: <sender@example.com>
690 To: <recipient@example.com>
691 Subject: mhfixmsg bad boundary test
692
693 This is a multi-part message in MIME format.
694
695 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4
696 Content-Type: text/plain
697
698 The boundaries of this part don't match the header boundary.
699
700 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4--
701 EOF
702
703 run_test 'mhfixmsg last -outfile '"$actual"' -verbose' \
704 "mhfixmsg: 16, fix multipart boundary"
705 check "$expected" "$actual"
706
707
708 # check that text/plain part is added to lone text/html in multipart/related
709 cat >"$expected" <<EOF
710 MIME-Version: 1.0
711 Date: Tue, 26 Feb 2013 18:07:20 -0600
712 Subject: multipart/related, not /alternative
713 Content-Type: multipart/related;
714 boundary="----=_Part_90310_101292502.1"
715
716 ------=_Part_90310_101292502.1
717 Content-Type: multipart/alternative; boundary="----=_nmh-multipart1"
718
719 ------=_nmh-multipart1
720 Content-Type: text/plain; charset="us-ascii"
721 Content-Transfer-Encoding: 7bit
722
723 This is the real content.
724
725 ------=_nmh-multipart1
726 Content-Type: text/html; charset="us-ascii"
727 Content-Transfer-Encoding: 7bit
728
729 <html><head>
730 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
731 <title>HTML Content</title>
732 </head>
733 <body>
734 This is the real content.
735 </body>
736 </html>
737
738 ------=_nmh-multipart1--
739
740 ------=_Part_90310_101292502.1
741 Content-Type: text/plain; charset="us-ascii"
742 Content-Transfer-Encoding: 7bit
743
744 Your email client does not support HTML messages
745
746 ------=_Part_90310_101292502.1--
747 EOF
748
749 cat >`mhpath new` <<EOF
750 MIME-Version: 1.0
751 Date: Tue, 26 Feb 2013 18:07:20 -0600
752 Subject: multipart/related, not /alternative
753 Content-Type: multipart/related;
754 boundary="----=_Part_90310_101292502.1"
755
756 ------=_Part_90310_101292502.1
757 Content-Type: text/html; charset="us-ascii"
758 Content-Transfer-Encoding: 7bit
759
760 <html><head>
761 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
762 <title>HTML Content</title>
763 </head>
764 <body>
765 This is the real content.
766 </body>
767 </html>
768 ------=_Part_90310_101292502.1
769 Content-Type: text/plain; charset="us-ascii"
770 Content-Transfer-Encoding: 7bit
771
772 Your email client does not support HTML messages
773 ------=_Part_90310_101292502.1--
774 EOF
775
776 if [ $can_reformat_texthtml -eq 1 ]; then
777 #### lynx inserts multiple blank lines, so use uniq to squeeze them.
778 mhfixmsg last -outfile - | uniq >"$actual"
779 check "$expected" "$actual"
780 else
781 rm -f "$expected"
782 fi
783
784 # check handling of rfc822 message type
785 cat >"$expected" <<EOF
786 From: Test <test@example.com>
787 To: Some User <user@example.com>
788 Date: Fri, 29 Sep 2006 00:00:00
789 Message-Id: @test.nmh
790 Subject: message with message/rfc822 attachment
791 MIME-Version: 1.0
792 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
793
794 and some garbage before the attachment
795
796 ------- =_aaaaaaaaaa0
797 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
798 Content-Description: 1552
799 Content-Disposition: attachment; filename="1552"
800
801 From: Test <test@example.com>
802 To: <another_user@example.com>
803 Date: Thu, 28 Sep 2006 00:00:00
804 Message-Id: @test.nmh
805 Subject: message/rfc822 attachment
806
807 This is an RFC-822 message.
808
809 ------- =_aaaaaaaaaa0--
810
811 and some garbage at the end
812 EOF
813
814 cat >`mhpath new` <<EOF
815 From: Test <test@example.com>
816 To: Some User <user@example.com>
817 Date: Fri, 29 Sep 2006 00:00:00
818 Message-Id: @test.nmh
819 Subject: message with message/rfc822 attachment
820 MIME-Version: 1.0
821 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaa0"
822
823 and some garbage before the attachment
824
825 ------- =_aaaaaaaaaa0
826 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
827 Content-Description: 1552
828 Content-Disposition: attachment; filename="1552"
829
830 From: Test <test@example.com>
831 To: <another_user@example.com>
832 Date: Thu, 28 Sep 2006 00:00:00
833 Message-Id: @test.nmh
834 Subject: message/rfc822 attachment
835
836 This is an RFC-822 message.
837
838 ------- =_aaaaaaaaaa0--
839
840 and some garbage at the end
841 EOF
842
843 run_test 'mhfixmsg last -outfile '"$actual" ''
844 check "$expected" "$actual"
845
846
847 # check rmmproc
848 cat >"$MH_TEST_DIR/Mail/rmmproc" <<'EOF'
849 mv "$1" "$1.backup"
850 EOF
851 chmod a+x "${MH_TEST_DIR}/Mail/rmmproc"
852 echo "rmmproc: ${MH_TEST_DIR}/Mail/rmmproc" >>"$MH"
853 cp "${MH_TEST_DIR}/Mail/inbox/14" "${MH_TEST_DIR}/Mail/inbox/14.original"
854
855 run_test 'mhfixmsg 14' ''
856 check "${MH_TEST_DIR}/Mail/inbox/14.backup" \
857 "${MH_TEST_DIR}/Mail/inbox/14.original"
858
859
860 # make sure there are no tmp files left over
861 find "$MH_TEST_DIR/Mail" \( -name 'mhfix*' -o -name ',mhfix*' \) -print \
862 >"$actual"
863 cat >"$expected" <<EOF
864 EOF
865
866 check "$expected" "$actual"
867
868
869 exit $failed