2 ######################################################
6 ######################################################
10 if test -z "${MH_OBJ_DIR}"; then
11 srcdir
=`dirname $0`/..
/..
12 MH_OBJ_DIR
=`cd $srcdir && pwd`; export MH_OBJ_DIR
15 .
"${MH_OBJ_DIR}/test/common.sh"
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
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"
28 mhn_defaults
="$MH_INST_DIR${nmhetcdir}/mhn.defaults"
30 if grep mhfixmsg-format
-text
/html
"${mhn_defaults}" \
32 can_reformat_texthtml
=1
33 if grep 'mhfixmsg-format-text/html.*w3m' "${mhn_defaults}" \
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
43 echo "$0: skipping -reformat check because no text browser was found"
44 can_reformat_texthtml
=0
49 cat >"$expected" <<EOF
50 Usage: mhfixmsg [+folder] [msgs] [switches]
71 run_prog mhfixmsg
-help >"$actual" 2>&1
72 check
"$expected" "$actual"
76 case `mhfixmsg -version` in
78 *) printf '%s: mhfixmsg -version generated unexpected output\n' "$0" >&2
79 failed
=`expr ${failed:-0} + 1`;;
83 # check that non-MIME messages aren't modified
85 run_test
'mhfixmsg first -outfile '"$actual" ''
86 check
"`mhpath first`" "$actual" 'keep first'
89 # check that non-MIME messages with no bodies aren't modified
91 cat >`mhpath new` <<EOF
92 From: Test <test@example.com>
93 To: Some User <user@example.com>
94 Date: Fri, 29 Sep 2006 00:00:00
96 Subject: message with no body
99 run_test
'mhfixmsg last -outfile '"$actual" ''
100 check
"`mhpath last`" "$actual"
104 cat >"$MH_TEST_DIR"/Mail
/inbox
/11 <<EOF
107 Subject: =?ISO-8859-15?Q?Re=3A_H=E5lla_linuxsystem_uppdaterade?=
108 User-Agent: Alpine 2.00 (DEB 1167 2008-08-23)
110 Content-Type: MULTIPART/MIXED;
111 BOUNDARY="----=_NextPart_000_0000_00000000.00000000"
112 Content-Transfer-Encoding: QUOTED-PRINTABLE
114 This message is in MIME format. The first part should be readable
116 while the remaining parts are likely unreadable without MIME-aware
119 ------=_NextPart_000_0000_00000000.00000000
120 Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-15
121 Content-Transfer-Encoding: 8BIT
123 Some text in swedish.
125 Varf=C3=B6r inte anv=C3=A4nda...
127 ------=_NextPart_000_0000_00000000.00000000--
129 And some text after the last part.
132 cp -p "$MH_TEST_DIR"/Mail
/inbox
/11 "$MH_TEST_DIR"/Mail
/inbox
/12
134 run_test
'mhfixmsg last -nofixcte' ''
135 check
"$MH_TEST_DIR"/Mail
/inbox
/11 "$MH_TEST_DIR"/Mail
/inbox
/12 'keep first'
138 # check -fixcte (enabled by default): fixup of erroneous C-T-E in multipart
140 cat >"$expected" <<EOF
143 Subject: =?ISO-8859-15?Q?Re=3A_H=E5lla_linuxsystem_uppdaterade?=
144 User-Agent: Alpine 2.00 (DEB 1167 2008-08-23)
146 Content-Type: MULTIPART/MIXED;
147 BOUNDARY="----=_NextPart_000_0000_00000000.00000000"
148 Nmh-REPLACED-INVALID-Content-Transfer-Encoding: QUOTED-PRINTABLE
149 Content-Transfer-Encoding: 8bit
151 This message is in MIME format. The first part should be readable
153 while the remaining parts are likely unreadable without MIME-aware
156 ------=_NextPart_000_0000_00000000.00000000
157 Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-15
158 Content-Transfer-Encoding: 8BIT
160 Some text in swedish.
162 Varf=C3=B6r inte anv=C3=A4nda...
164 ------=_NextPart_000_0000_00000000.00000000--
166 And some text after the last part.
169 run_test
'mhfixmsg last -outfile '"$actual"' -verbose' \
170 "mhfixmsg: 11, replace Content-Transfer-Encoding of \
171 QUOTED-PRINTABLE with 8 bit"
172 check
"$expected" "$actual" 'keep first'
175 # check with no options: checks backup
176 cp "$MH_TEST_DIR"/Mail
/inbox
/11 "$MH_TEST_DIR"/Mail
/inbox
/11.original
177 folder last
>/dev
/null
178 run_test
'mhfixmsg' ''
179 check
"$expected" "$MH_TEST_DIR"/Mail
/inbox
/11 'keep first'
180 cp "$MH_TEST_DIR"/Mail
/inbox
/11.original
"$MH_TEST_DIR"/Mail
/inbox
/11
181 check
"$MH_TEST_DIR"/Mail
/inbox
/,11 "$MH_TEST_DIR"/Mail
/inbox
/11.original
184 # check backup with -file
185 cp "$MH_TEST_DIR"/Mail
/inbox
/11 "$MH_TEST_DIR"/Mail
/inbox
/11.original
186 folder last
>/dev
/null
187 run_test
'mhfixmsg -file '"$MH_TEST_DIR"/Mail
/inbox
/11 ''
188 check
"$MH_TEST_DIR"/Mail
/inbox
/11 "$expected" 'keep first'
189 check
"$MH_TEST_DIR"/Mail
/inbox
/,11 "$MH_TEST_DIR"/Mail
/inbox
/11.original
192 # check -reformat (enabled by default): addition of text/plain part
193 # to solitary text/html part
195 prepare_space
>"$expected" <<EOF
197 From: sender@example.com
198 To: bonquiqui@example.com
200 Date: Sat, 26 Jan 2013 17:37:53 -0500
201 Content-Type: multipart/alternative; boundary="----=_nmh-multipart"
203 ------=_nmh-multipart
204 Content-Type: text/plain; charset="Windows-1252"
205 Content-Transfer-Encoding: 8bit
207 Need to go! Need ... to ... go!
209 ------=_nmh-multipart
210 Content-Type: text/html; charset="Windows-1252"
211 Content-Transfer-Encoding: 8bit
215 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
216 <meta name="Generator" content="Microsoft Exchange Server">
217 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
221 <div>Need to go! Need ... to ... go!</div>
225 ------=_nmh-multipart--
228 cat >"$MH_TEST_DIR"/Mail
/inbox
/12 <<EOF
230 From: sender@example.com
231 To: bonquiqui@example.com
233 Date: Sat, 26 Jan 2013 17:37:53 -0500
234 Content-Type: text/html; charset="Windows-1252"
235 Content-Transfer-Encoding: quoted-printable
239 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
241 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
242 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
243 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
247 <div>Need to go! Need ... to ... go!</div>
252 if [ $can_reformat_texthtml -eq 1 ]; then
253 printf '%s\n' "mhfixmsg: 12, insert text/plain part
254 mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
257 #### lynx inserts multiple blank lines, so squeeze them.
258 run_prog mhfixmsg last
-outfile - -verbose 2>"$actual.err" | \
259 squeeze_lines
>"$actual"
260 check
"$expected" "$actual" 'ignore space'
261 check
"$expected.err" "$actual.err"
267 # check implicit -file with absolute pathname
268 run_test
"mhfixmsg `mhpath last` -outfile /dev/null" ''
271 # check handling of boundary string that appears in message body
273 prepare_space
>"$expected" <<EOF
275 From: sender@example.com
276 To: bonquiqui@example.com
278 Date: Sat, 26 Jan 2013 17:37:53 -0500
279 Content-Type: multipart/alternative; boundary="----=_nmh-multipart-3"
281 ------=_nmh-multipart-3
282 Content-Type: text/plain; charset="Windows-1252"
283 Content-Transfer-Encoding: 8bit
285 ------=_nmh-multipart
286 ------=_nmh-multipart-1
287 ------=_nmh-multipart-2
289 ------=_nmh-multipart-3
290 Content-Type: text/html; charset="Windows-1252"
291 Content-Transfer-Encoding: 8bit
295 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
296 <meta name="Generator" content="Microsoft Exchange Server">
297 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
300 ------=_nmh-multipart<br>
301 ------=_nmh-multipart-1<br>
302 ------=_nmh-multipart-2<br>
306 ------=_nmh-multipart-3--
309 cat >"$MH_TEST_DIR"/Mail
/inbox
/12 <<EOF
311 From: sender@example.com
312 To: bonquiqui@example.com
314 Date: Sat, 26 Jan 2013 17:37:53 -0500
315 Content-Type: text/html; charset="Windows-1252"
316 Content-Transfer-Encoding: quoted-printable
320 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
322 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
323 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
324 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
327 ------=3D_nmh-multipart<br>
328 ------=3D_nmh-multipart-1<br>
329 ------=3D_nmh-multipart-2<br>
334 if [ $can_reformat_texthtml -eq 1 ]; then
335 printf '%s\n' "mhfixmsg: 12, insert text/plain part
336 mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
339 #### lynx inserts multiple blank lines, so squeeze them.
340 run_prog mhfixmsg last
-outfile - -verbose 2>"$actual.err" | \
341 squeeze_lines
>"$actual"
342 check
"$expected" "$actual" 'ignore space'
343 check
"$expected.err" "$actual.err"
350 prepare_space
>"$expected" <<EOF
352 From: sender@example.com
353 To: bonquiqui@example.com
355 Date: Sat, 26 Jan 2013 17:37:53 -0500
356 Content-Type: multipart/alternative; boundary="----=_nmh-multipart"
358 ------=_nmh-multipart
359 Content-Type: text/plain; charset="Windows-1252"
360 Content-Transfer-Encoding: 8bit
362 Need to go! Need ... to ... go!
364 ------=_nmh-multipart
365 Content-Type: text/html; charset="Windows-1252"
366 Content-Transfer-Encoding: quoted-printable
370 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-=
372 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
373 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pa=
374 dding-left: 4pt; border-left: #800000 2px solid; } --></style>
378 <div>Need to go! Need ... to ... go!</div>
382 ------=_nmh-multipart--
385 cat >"$MH_TEST_DIR"/Mail
/inbox
/12 <<EOF
387 From: sender@example.com
388 To: bonquiqui@example.com
390 Date: Sat, 26 Jan 2013 17:37:53 -0500
391 Content-Type: text/html; charset="Windows-1252"
392 Content-Transfer-Encoding: quoted-printable
396 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
398 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
399 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
400 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
404 <div>Need to go! Need ... to ... go!</div>
409 if [ $can_reformat_texthtml -eq 1 ]; then
410 printf '%s\n' 'mhfixmsg: 12, insert text/plain part' >"$expected.err"
412 #### lynx inserts multiple blank lines, so squeeze them.
413 run_prog mhfixmsg last
-nodecode -outfile - -verbose 2>"$actual.err" | \
414 squeeze_lines
>"$actual"
415 check
"$expected" "$actual" 'ignore space'
416 check
"$expected.err" "$actual.err"
422 # check -decodetext (enabled by default)
423 cat >"$expected" <<EOF
424 To: recipient@example.com
425 From: sender@example.com
426 Subject: mhfixmsg decode test 1
428 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
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: 8bit
435 This is a text/plain part.
437 ------- =_aaaaaaaaaa0--
440 cat >`mhpath new` <<EOF
441 To: recipient@example.com
442 From: sender@example.com
443 Subject: mhfixmsg decode test 1
445 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
447 ------- =_aaaaaaaaaa0
448 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
449 Content-Disposition: attachment; filename="test4.txt"
450 Content-Transfer-Encoding: base64
452 VGhpcyBpcyBhIHRleHQvcGxhaW4gcGFydC4K
454 ------- =_aaaaaaaaaa0--
457 run_prog mhfixmsg last
-outfile "$actual"
458 check
"$expected" "$actual"
461 # check -decodetext with more complicated content structure
463 To: recipient@example.com
464 From: sender@example.com
465 Subject: mhfixmsg decode test 2
467 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
469 This is additional content before the first subpart of the multipart.
471 ------- =_aaaaaaaaaa0
472 Content-Type: multipart/related;
473 type="text/plain"; boundary="subpart__1.1"
476 Content-Type: text/plain; charset="iso-8859-1"
477 Content-Disposition: attachment; filename="test1.txt"
479 This is the first text/plain part, in a subpart.
483 This is additional content after the last subpart of the multipart.
485 ------- =_aaaaaaaaaa0
486 Content-Type: text/plain; charset="iso-8859-1"
487 Content-Disposition: attachment; filename="test2.txt"
488 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
489 Content-Transfer-Encoding: 8bit
491 This is the second text/plain part.
493 ------- =_aaaaaaaaaa0
494 Content-Type: text/plain; charset="iso-8859-1"
495 Content-Disposition: attachment; filename="test3.txt"
497 This is the third text/plain part.
499 ------- =_aaaaaaaaaa0
500 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
501 Content-Disposition: attachment; filename="test4.txt"
502 Content-Transfer-Encoding: 8bit
504 This is the fourth text/plain part.
506 ------- =_aaaaaaaaaa0--
508 This is additional content after the last subpart of the multipart.
511 cat >`mhpath new` <<EOF
512 To: recipient@example.com
513 From: sender@example.com
514 Subject: mhfixmsg decode test 2
516 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
518 This is additional content before the first subpart of the multipart.
520 ------- =_aaaaaaaaaa0
521 Content-Type: multipart/related;
522 type="text/plain"; boundary="subpart__1.1"
525 Content-Type: text/plain; charset="iso-8859-1"
526 Content-Disposition: attachment; filename="test1.txt"
528 This is the first text/plain part, in a subpart.
532 This is additional content after the last subpart of the multipart.
534 ------- =_aaaaaaaaaa0
535 Content-Type: text/plain; charset="iso-8859-1"
536 Content-Disposition: attachment; filename="test2.txt"
537 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
538 Content-Transfer-Encoding: quoted-printable
540 This is the second text/plain part.
542 ------- =_aaaaaaaaaa0
543 Content-Type: text/plain; charset="iso-8859-1"
544 Content-Disposition: attachment; filename="test3.txt"
546 This is the third text/plain part.
548 ------- =_aaaaaaaaaa0
549 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
550 Content-Disposition: attachment; filename="test4.txt"
551 Content-Transfer-Encoding: base64
553 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4K
555 ------- =_aaaaaaaaaa0--
557 This is additional content after the last subpart of the multipart.
559 run_prog mhfixmsg last
-outfile "$actual"
560 check
"$expected" "$actual"
563 # check attempted -decodetext of binary text
564 #### Generated the encoded text below with:
565 #### $ printf '\x0\xbd\xb2=\xbc\n' | base64
566 cat >`mhpath new` <<EOF
567 To: recipient@example.com
568 From: sender@example.com
569 Subject: mhfixmsg attempted binary decode test
571 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
573 ------- =_aaaaaaaaaa0
574 Content-Type: text/plain; charset="iso-8859-1"; name="nul+square.txt"
575 Content-Transfer-Encoding: base64
579 ------- =_aaaaaaaaaa0--
582 cp -p `mhpath last` "$expected"
583 run_prog mhfixmsg last
584 check
`mhpath last` "$expected" 'keep first'
587 # check -decodetext of binary text
588 printf "%s\x0d\xbd\xb2=\xbc%s" "To: recipient@example.com
589 From: sender@example.com
590 Subject: mhfixmsg binary decode test
592 Content-Type: multipart/mixed; boundary=\"----- =_aaaaaaaaaa0\"
594 ------- =_aaaaaaaaaa0
595 Content-Type: text/plain; charset=\"iso-8859-1\"; name=\"nul+square.txt\"
596 Content-Transfer-Encoding: binary
600 ------- =_aaaaaaaaaa0--
602 ## output_content() in mhoutsbr.c can't handle binary content.
603 ## mhfixmsg last -decodetext binary -outfile "$actual"
604 ## check "$expected" "$actual"
609 # check that -reformat succeeds when decode of binary text fails
610 prepare_space
>"$expected" <<'EOF'
612 Date: Thu, 11 Apr 2013 02:47:08 -0700
614 From: <sender@example.com>
615 Subject: body requires binary encoding
616 Content-Type: multipart/alternative; boundary="----=_nmh-multipart"
618 ------=_nmh-multipart
619 Content-Type: text/plain; charset="ISO-8859-1"
620 Content-Transfer-Encoding: 8bit
625 Vehicle License Fee $1.84
628 ------=_nmh-multipart
629 Content-Type: text/html; charset="ISO-8859-1"
630 Content-Transfer-Encoding: quoted-printable
635 cat >`mhpath new` <<'EOF'
637 Content-Type: text/html; charset="ISO-8859-1"
638 Content-Transfer-Encoding: quoted-printable
639 Date: Thu, 11 Apr 2013 02:47:08 -0700
641 From: <sender@example.com>
642 Subject: body requires binary encoding
645 <table width=3D"325" border=3D"0" cellspacing=3D"0" cellpadding=3D"0">
646 <tr><td><font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" size=
647 =3D"2"><strong>Mile</strong></font></td><td height=3D"3"> </td><td ali=
648 gn=3D"right"><font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" =
649 size=3D"2">$0.00</font></td></tr><tr><td><font face=3D"Arial, Helvetica, sa=
650 ns-serif" color=3D"#333333" size=3D"2"><strong>Time</strong></font></td><td=
651 height=3D"3"> </td><td align=3D"right"><font face=3D"Arial, Helvetica=
652 , sans-serif" color=3D"#333333" size=3D"2">$78.71</font></td></tr><tr><td><=
653 font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" size=3D"2"><st=
654 rong>State Tax</strong></font></td><td height=3D"3"> </td><td align=3D=
655 "right"><font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" size=
656 =3D"2">$5.90</font></td></tr><tr><td><font face=3D"Arial, Helvetica, sans-s=
657 erif" color=3D"#333333" size=3D"2"><strong>Vehicle License Fee</strong></fo=
658 nt></td><td height=3D"3"> </td><td align=3D"right"><font face=3D"Arial=
659 , Helvetica, sans-serif" color=3D"#333333" size=3D"2">$1.84</font></td></tr=
660 ><tr><td><font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" size=
661 =3D"2"><strong>State Txn Tax</strong></font></td><td height=3D"3"> </t=
662 d><td align=3D"right"><font face=3D"Arial, Helvetica, sans-serif" color=3D"=
663 #333333" size=3D"2">$6.00</font></td></tr>
669 if [ $can_reformat_texthtml -eq 1 ]; then
670 #### lynx inserts multiple blank lines, so squeeze them.
671 #### Truncate to avoid comparing the html portion because it can
672 #### get reformatted.
673 run_prog mhfixmsg last
-outfile - | squeeze_lines
| head -22 >"$actual"
674 check
"$expected" "$actual" 'ignore space'
676 cp -p "$MH_TEST_DIR/Mail/inbox/15" "$MH_TEST_DIR/Mail/inbox/15.backup"
682 # Also checks preservation of attributes after one (charset) that is
684 cat >"$expected" <<EOF
685 To: recipient@example.com
686 From: sender@example.com
687 Subject: mhfixmsg textcharset test
689 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
691 ------- =_aaaaaaaaaa0
692 Content-Type: text/plain; charset="utf-8"; name="square.txt"
693 Content-Disposition: attachment; filename="square.txt"
694 Content-Transfer-Encoding: 8bit
698 ------- =_aaaaaaaaaa0--
701 #### Generated the encoded text below with:
702 #### $ printf '\xbd\xb2=\xbc\n' | base64
703 cat >`mhpath new` <<EOF
704 To: recipient@example.com
705 From: sender@example.com
706 Subject: mhfixmsg textcharset test
708 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
710 ------- =_aaaaaaaaaa0
711 Content-Type: text/plain; charset="iso-8859-1"; name="square.txt"
712 Content-Disposition: attachment; filename="square.txt"
713 Content-Transfer-Encoding: base64
717 ------- =_aaaaaaaaaa0--
720 if test "$ICONV_ENABLED" -eq 1; then
721 run_prog mhfixmsg last
-textcharset utf-8
-outfile "$actual" 2>&1
722 check
"$expected" "$actual"
724 echo "$0: skipping -textcharset check because nmh was built without iconv"
729 # check -nofixboundary
730 cat >"$expected" <<EOF
733 cat >`mhpath new` <<EOF
734 Date: Fri, 13 May 2011 08:21:12 -0500
735 Content-Type: multipart/alternative;
736 boundary="----=_NextPart_000_1781A17_01CC1147.81E9467A"
737 Content-Transfer-Encoding: 8bit
739 From: <sender@example.com>
740 To: <recipient@example.com>
741 Subject: mhfixmsg bad boundary test
743 This is a multi-part message in MIME format.
745 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4
746 Content-Type: text/plain
748 The boundaries of this part don't match the header boundary.
750 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4--
753 cp -p `mhpath last` `mhpath new`
755 run_test
'mhfixmsg last -nofixboundary' ''
756 check
"$MH_TEST_DIR"/Mail
/inbox
/17 "$MH_TEST_DIR"/Mail
/inbox
/18 'keep first'
759 # check that message is not output when fed through stdin
760 run_prog mhfixmsg
-file - -verbose <`mhpath last` >"$actual" 2>"$actual.err"
761 check
"$expected" "$actual"
762 if grep "mhfixmsg: $MH_TEST_DIR/Mail/.*, fix multipart boundary" \
763 "$actual.err" >/dev
/null
; then
766 echo "$0: test failed, output is in $actual.err."
767 failed
=`expr ${failed:-0} + 1`
771 # check fixup of erroneous boundary in multipart (-fixboundary,
772 # enabled by default)
774 cat >"$expected" <<EOF
775 Date: Fri, 13 May 2011 08:21:12 -0500
776 Content-Type: multipart/alternative;
777 boundary="----=_NextPart_000_1781A1A_01CC1147.81EBA8D4"
778 Content-Transfer-Encoding: 8bit
780 From: <sender@example.com>
781 To: <recipient@example.com>
782 Subject: mhfixmsg bad boundary test
784 This is a multi-part message in MIME format.
786 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4
787 Content-Type: text/plain
789 The boundaries of this part don't match the header boundary.
791 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4--
794 run_test
'mhfixmsg last -outfile '"$actual"' -verbose' \
795 "mhfixmsg: 17, fix multipart boundary"
796 check
"$expected" "$actual"
799 # check that text/plain part is not added to text/html in multipart/related
800 # when it shouldn't be
801 cat >`mhpath new` <<EOF
803 Date: Tue, 26 Feb 2013 18:07:20 -0600
804 Subject: multipart/related, not /alternative
805 Content-Type: multipart/related;
806 type="text/html"; boundary="----=_Part_90310_101292502.1"
808 ------=_Part_90310_101292502.1
809 Content-Type: text/html; charset="us-ascii"
810 Content-Transfer-Encoding: 7bit
813 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
814 <title>HTML Content</title>
817 This is the real content.
821 ------=_Part_90310_101292502.1
822 Content-Type: text/plain; charset="us-ascii"
823 Content-Transfer-Encoding: 7bit
825 Your email client does not support HTML messages
827 ------=_Part_90310_101292502.1--
830 cp -p `mhpath last` "$expected"
832 if [ $can_reformat_texthtml -eq 1 ]; then
833 #### lynx inserts multiple blank lines, so squeeze them.
834 run_prog mhfixmsg last
-outfile - | squeeze_lines
>"$actual"
835 check
"$expected" "$actual" 'ignore space'
841 # check that text/plain part is added to text/html in multipart/related
843 cat >"$expected" <<EOF
845 Date: Tue, 26 Feb 2013 18:07:20 -0600
846 Subject: multipart/related, not /alternative
847 Content-Type: multipart/alternative; boundary="----=_Part_90310_101292502.1"
849 ------=_Part_90310_101292502.1
850 Content-Type: text/plain; charset="us-ascii"
851 Content-Transfer-Encoding: 7bit
853 This is the real content.
855 ------=_Part_90310_101292502.1
856 Content-Type: text/html; charset="us-ascii"
857 Content-Transfer-Encoding: 7bit
860 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
861 <title>HTML Content</title>
864 This is the real content.
868 ------=_Part_90310_101292502.1--
871 cat >`mhpath new` <<EOF
873 Date: Tue, 26 Feb 2013 18:07:20 -0600
874 Subject: multipart/related, not /alternative
875 Content-Type: multipart/related;
876 type="text/html"; boundary="----=_Part_90310_101292502.1"
878 ------=_Part_90310_101292502.1
879 Content-Type: text/html; charset="us-ascii"
880 Content-Transfer-Encoding: 7bit
883 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
884 <title>HTML Content</title>
887 This is the real content.
891 ------=_Part_90310_101292502.1--
894 if [ $can_reformat_texthtml -eq 1 ]; then
895 #### lynx inserts multiple blank lines, so squeeze them.
896 run_prog mhfixmsg last
-outfile - | squeeze_lines
>"$actual"
897 check
"$expected" "$actual" 'ignore space'
903 # check handling of rfc822 message type
904 cat >"$expected" <<EOF
905 From: Test <test@example.com>
906 To: Some User <user@example.com>
907 Date: Fri, 29 Sep 2006 00:00:00
908 Message-Id: @test.nmh
909 Subject: message with message/rfc822 attachment
911 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
913 and some garbage before the attachment
915 ------- =_aaaaaaaaaa0
916 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
917 Content-Description: 1552
918 Content-Disposition: attachment; filename="1552"
920 From: Test <test@example.com>
921 To: <another_user@example.com>
922 Date: Thu, 28 Sep 2006 00:00:00
923 Message-Id: @test.nmh
924 Subject: message/rfc822 attachment
926 This is an RFC-822 message.
928 ------- =_aaaaaaaaaa0--
930 and some garbage at the end
933 cat >`mhpath new` <<EOF
934 From: Test <test@example.com>
935 To: Some User <user@example.com>
936 Date: Fri, 29 Sep 2006 00:00:00
937 Message-Id: @test.nmh
938 Subject: message with message/rfc822 attachment
940 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaa0"
942 and some garbage before the attachment
944 ------- =_aaaaaaaaaa0
945 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
946 Content-Description: 1552
947 Content-Disposition: attachment; filename="1552"
949 From: Test <test@example.com>
950 To: <another_user@example.com>
951 Date: Thu, 28 Sep 2006 00:00:00
952 Message-Id: @test.nmh
953 Subject: message/rfc822 attachment
955 This is an RFC-822 message.
957 ------- =_aaaaaaaaaa0--
959 and some garbage at the end
962 run_test
'mhfixmsg last -outfile '"$actual" ''
963 check
"$expected" "$actual"
966 # check stripping of CRs from ASCII text context
967 cat >"$expected" <<EOF
969 From: sender@example.com
970 To: recipient@example.com
971 Subject: message with CR's
972 Date: Mon, 29 Apr 2013 11:51:45 -0400
974 There are two CR-LF pairs at the end of this sentence.
978 cat >`mhpath new` <<'EOF'
980 From: sender@example.com
981 To: recipient@example.com
982 Subject: message with CR's
983 Date: Mon, 29 Apr 2013 11:51:45 -0400
985 There are two CR-LF pairs at the end of this sentence.
989 run_prog mhfixmsg last
-outfile "$actual"
990 check
"$expected" "$actual"
993 # check -replacetextplain
994 prepare_space
>"$expected" <<EOF
995 To: recipient@example.com
996 From: sender@example.com
997 Subject: mhfixmsg replacement of bad text/plain part test
999 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1002 Content-Type: text/plain; charset="UTF-8"
1003 Content-Transfer-Encoding: 8bit
1005 Yes, the text/plain part really was empty.
1008 Content-Type: text/html; charset="UTF-8"
1009 Content-Transfer-Encoding: 8bit
1010 Content-Disposition: inline
1013 <title>eticket</title>
1016 Yes, the text/plain part really was empty.
1020 ------=_Part_876302--
1023 cat >`mhpath new` <<'EOF'
1024 To: recipient@example.com
1025 From: sender@example.com
1026 Subject: mhfixmsg replacement of bad text/plain part test
1028 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1031 Content-Type: text/plain; charset="iso-8859-15"
1032 Content-Transfer-Encoding: 7bit
1033 Content-Disposition: inline
1038 Content-Type: text/html; charset="UTF-8"
1039 Content-Transfer-Encoding: 8bit
1040 Content-Disposition: inline
1043 <title>eticket</title>
1046 Yes, the text/plain part really was empty.
1050 ------=_Part_876302--
1053 if [ $can_reformat_texthtml -eq 1 ]; then
1054 #### lynx inserts multiple blank lines, so squeeze them.
1055 run_prog mhfixmsg last
-replacetextplain -outfile - | \
1056 squeeze_lines
> "$actual"
1057 check
"$expected" "$actual" 'ignore space'
1063 # check -noreplacetextplain
1064 cat >"$expected" <<EOF
1065 To: recipient@example.com
1066 From: sender@example.com
1067 Subject: mhfixmsg replacement of bad text/plain part test
1069 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1072 Content-Type: text/plain; charset="iso-8859-15"
1073 Content-Transfer-Encoding: 7bit
1074 Content-Disposition: inline
1079 Content-Type: text/html; charset="UTF-8"
1080 Content-Transfer-Encoding: 8bit
1081 Content-Disposition: inline
1084 <title>eticket</title>
1087 Yes, the text/plain part really was empty.
1091 ------=_Part_876302--
1094 run_prog mhfixmsg last
-replacetextplain -noreplacetextplain -outfile "$actual"
1095 check
"$expected" "$actual"
1098 # check removal of extraneous trailing semicolon from header parameter list
1099 cat >"$expected" <<EOF
1100 To: recipient@example.com
1102 From: sender@example.com
1104 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1106 ------- =_aaaaaaaaaa0
1107 Content-Type: text/plain; charset="us-ascii"
1111 ------- =_aaaaaaaaaa0
1112 Content-Type: text/plain; charset="us-ascii";
1114 Content-Description: check folded headers, with and without trailing semicolon
1115 Content-Disposition: attachment;
1120 ------- =_aaaaaaaaaa0--
1123 cat >`mhpath new` <<EOF
1124 To: recipient@example.com
1126 From: sender@example.com
1128 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1130 ------- =_aaaaaaaaaa0
1131 Content-Type: text/plain; charset="us-ascii";
1135 ------- =_aaaaaaaaaa0
1136 Content-Type: text/plain; charset="us-ascii";
1138 Content-Description: check folded headers, with and without trailing semicolon
1139 Content-Disposition: attachment;
1144 ------- =_aaaaaaaaaa0--
1146 run_test
'mhfixmsg last -outfile '"$actual" ''
1147 check
"$expected" "$actual"
1151 cat >"$MH_TEST_DIR/Mail/rmmproc" <<'EOF'
1154 chmod a
+x
"${MH_TEST_DIR}/Mail/rmmproc"
1155 echo "rmmproc: ${MH_TEST_DIR}/Mail/rmmproc" >>"$MH"
1156 cp "${MH_TEST_DIR}/Mail/inbox/15" "${MH_TEST_DIR}/Mail/inbox/15.original"
1158 run_test
'mhfixmsg 15' ''
1159 check
"${MH_TEST_DIR}/Mail/inbox/15.backup" \
1160 "${MH_TEST_DIR}/Mail/inbox/15.original"
1164 cp "${MH_TEST_DIR}/Mail/inbox/19" "${MH_TEST_DIR}/Mail/inbox/20"
1166 run_test
'mhfixmsg 19 -normmproc'
1167 check
"${MH_TEST_DIR}/Mail/inbox/20" \
1168 "${MH_TEST_DIR}/Mail/inbox/,19" 'keep first'
1172 run_test
'mhfixmsg 20 -rmmproc true'
1173 if test -f '${MH_TEST_DIR}/Mail/inbox/20.backup'; then
1174 echo check of mhfixmsg
-rmmproc FAILED
, should not have created backup
file
1175 failed
=`expr ${failed:-0} + 1`
1180 cat >"$expected" <<EOF
1181 To: recipient@example.com
1182 From: sender@example.com
1183 Subject: mhfixmsg with incorrect Content-Type
1185 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1187 ------- =_aaaaaaaaaa0
1188 Content-Type: text/plain; name="plaintext.txt"
1192 ------- =_aaaaaaaaaa0--
1195 cat >`mhpath new` <<EOF
1196 To: recipient@example.com
1197 From: sender@example.com
1198 Subject: mhfixmsg with incorrect Content-Type
1200 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1202 ------- =_aaaaaaaaaa0
1203 Content-Type: application/octet-stream; name="plaintext.txt"
1207 ------- =_aaaaaaaaaa0--
1210 mhfixmsg
-fixtype application
/octet-stream last
1211 check
"$expected" `mhpath last`
1214 # check default -decodetypes
1215 cat >$expected <<EOF
1216 To: recipient@example.com
1217 From: sender@example.com
1218 Subject: mhfixmsg decode test 3
1220 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1222 ------- =_aaaaaaaaaa0
1223 Content-Type: text/plain; charset="iso-8859-1"
1224 Content-Disposition: attachment; filename="test1.txt"
1225 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1226 Content-Transfer-Encoding: 8bit
1228 This is the text/plain part.
1230 ------- =_aaaaaaaaaa0
1231 Content-Type: text/plain; charset="iso-8859-1"; name="test2.txt"
1232 Content-Disposition: attachment; filename="test2.txt"
1233 Content-Transfer-Encoding: 8bit
1237 This is the text/html part.
1242 ------- =_aaaaaaaaaa0--
1245 cat >`mhpath new` <<EOF
1246 To: recipient@example.com
1247 From: sender@example.com
1248 Subject: mhfixmsg decode test 3
1250 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1252 ------- =_aaaaaaaaaa0
1253 Content-Type: text/plain; charset="iso-8859-1"
1254 Content-Disposition: attachment; filename="test1.txt"
1255 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1256 Content-Transfer-Encoding: quoted-printable
1258 This is the text/plain part.
1260 ------- =_aaaaaaaaaa0
1261 Content-Type: text/plain; charset="iso-8859-1"; name="test2.txt"
1262 Content-Disposition: attachment; filename="test2.txt"
1263 Content-Transfer-Encoding: base64
1265 PGh0bWw+CjxoZWFkPgogICAgVGhpcyBpcyB0aGUgdGV4dC9odG1sIHBhcnQuCjwvaGVhZD4KPC9i
1266 b2R5Pgo8L2h0bWw+Cg==
1268 ------- =_aaaaaaaaaa0--
1270 run_prog mhfixmsg last
-outfile "$actual"
1271 check
"$expected" "$actual"
1274 # check -decodetypes text/plain
1275 cat >$expected <<EOF
1276 To: recipient@example.com
1277 From: sender@example.com
1278 Subject: mhfixmsg decode test 4
1280 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1282 ------- =_aaaaaaaaaa0
1283 Content-Type: text/plain; charset="iso-8859-1"
1284 Content-Disposition: attachment; filename="test1.txt"
1285 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1286 Content-Transfer-Encoding: 8bit
1288 This is the text/plain part.
1290 ------- =_aaaaaaaaaa0
1291 Content-Type: multipart/alternative; boundary="----=_nmh-multipart2"
1293 ------=_nmh-multipart2
1294 Content-Type: text/plain; charset="iso-8859-1"; name="test2.txt"
1295 Content-Transfer-Encoding: 8bit
1297 This is the text/html part.
1299 ------=_nmh-multipart2
1300 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
1301 Content-Disposition: attachment; filename="test2.txt"
1302 Content-Transfer-Encoding: base64
1304 PGh0bWw+DQo8aGVhZD4NCiAgICBUaGlzIGlzIHRoZSB0ZXh0L2h0bWwgcGFydC4NCjwvaGVhZD4N
1305 CjwvYm9keT4NCjwvaHRtbD4NCg==
1307 ------=_nmh-multipart2--
1309 ------- =_aaaaaaaaaa0--
1312 cat >`mhpath new` <<EOF
1313 To: recipient@example.com
1314 From: sender@example.com
1315 Subject: mhfixmsg decode test 4
1317 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1319 ------- =_aaaaaaaaaa0
1320 Content-Type: text/plain; charset="iso-8859-1"
1321 Content-Disposition: attachment; filename="test1.txt"
1322 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1323 Content-Transfer-Encoding: quoted-printable
1325 This is the text/plain part.
1327 ------- =_aaaaaaaaaa0
1328 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
1329 Content-Disposition: attachment; filename="test2.txt"
1330 Content-Transfer-Encoding: base64
1332 PGh0bWw+CjxoZWFkPgogICAgVGhpcyBpcyB0aGUgdGV4dC9odG1sIHBhcnQuCjwvaGVhZD4KPC9i
1333 b2R5Pgo8L2h0bWw+Cg==
1335 ------- =_aaaaaaaaaa0--
1337 run_prog mhfixmsg last
-outfile "$actual" -decodetypes text
/plain
1338 check
"$expected" "$actual"
1341 # make sure there are no tmp files left over
1342 find "$MH_TEST_DIR/Mail" \
( -name 'mhfix*' -o -name ',mhfix*' \
) -print \
1344 cat >"$expected" <<EOF
1347 check
"$expected" "$actual"