]> diplodocus.org Git - nmh/blob - test/mhfixmsg/test-mhfixmsg
Move things around so you can still initialize netsec with SASL
[nmh] / test / mhfixmsg / test-mhfixmsg
1 #!/bin/sh
2 ######################################################
3 #
4 # Test mhfixmsg
5 #
6 ######################################################
7
8 set -e
9
10 if test -z "${MH_OBJ_DIR}"; then
11 srcdir=`dirname $0`/../..
12 MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
13 fi
14
15 . "${MH_OBJ_DIR}/test/common.sh"
16
17 setup_test
18
19 #### Make sure that html-to-text conversion is what we expect.
20 require_locale en_US.utf-8 en_US.utf8
21 LC_ALL=en_US.UTF-8; export LC_ALL
22
23 expected="$MH_TEST_DIR/test-mhfixmsg$$.expected"
24 expected_err="$MH_TEST_DIR/test-mhfixmsg$$.expected_err"
25 actual="$MH_TEST_DIR/test-mhfixmsg$$.actual"
26 actual_err="$MH_TEST_DIR/test-mhfixmsg$$.actual_err"
27
28 mhn_defaults="$MH_INST_DIR${nmhetcdir}/mhn.defaults"
29
30 if grep mhfixmsg-format-text/html "${mhn_defaults}" \
31 >/dev/null; then
32 can_reformat_texthtml=1
33 if grep 'mhfixmsg-format-text/html.*w3m' "${mhn_defaults}" \
34 >/dev/null; then
35 #### w3m uses $HOME/.w3m/, and creates it if it doesn't exist. To
36 #### support testing with non-writeable $HOME, and to not leave
37 #### relics from this test if it is writeable but doesn't already
38 #### have a .w3m, and to not depend on whatever is in that if it
39 #### does already exist, overwrite $HOME if using w3m.
40 HOME="$MHTMPDIR"; export HOME
41 fi
42 else
43 echo "$0: skipping -reformat check because no text browser was found"
44 can_reformat_texthtml=0
45 fi
46
47
48 # check -help
49 start_test "-help"
50 cat >"$expected" <<EOF
51 Usage: mhfixmsg [+folder] [msgs] [switches]
52 switches are:
53 -decodetext 8bit|7bit|binary
54 -nodecodetext
55 -decodetypes
56 -[no]crlflinebreaks
57 -[no]textcharset
58 -[no]reformat
59 -[no]replacetextplain
60 -[no]fixboundary
61 -[no]fixcte
62 -fixtype mimetype
63 -file file
64 -outfile file
65 -rmmproc program
66 -normmproc
67 -[no]changecur
68 -[no]verbose
69 -version
70 -help
71 EOF
72
73 run_prog mhfixmsg -help >"$actual" 2>&1
74 check "$expected" "$actual"
75
76
77 # check -version
78 start_test "-version"
79 case `mhfixmsg -version` in
80 mhfixmsg\ --*) ;;
81 *) printf '%s: mhfixmsg -version generated unexpected output\n' "$0" >&2
82 failed=`expr ${failed:-0} + 1`;;
83 esac
84
85
86 # check that non-MIME messages aren't modified
87 # check -outfile
88 start_test "that non-MIME messages aren't modified, and -outfile"
89 run_test 'mhfixmsg first -outfile '"$actual" ''
90 check "`mhpath first`" "$actual" 'keep first'
91
92
93 # check that non-MIME messages with no bodies aren't modified
94 # check -outfile
95 start_test "that non-MIME messages with no bodies aren't modified, and -outfile"
96 cat >`mhpath new` <<EOF
97 From: Test <test@example.com>
98 To: Some User <user@example.com>
99 Date: Fri, 29 Sep 2006 00:00:00
100 Message-Id: @test.nmh
101 Subject: message with no body
102 EOF
103
104 run_test 'mhfixmsg last -outfile '"$actual" ''
105 check "`mhpath last`" "$actual"
106
107
108 # check -nofixcte
109 start_test "-nofixcte"
110 cat >"$MH_TEST_DIR"/Mail/inbox/11 <<EOF
111 From: Anon
112 To: Mailinglist
113 Subject: =?ISO-8859-15?Q?Re=3A_H=E5lla_linuxsystem_uppdaterade?=
114 User-Agent: Alpine 2.00 (DEB 1167 2008-08-23)
115 MIME-Version: 1.0
116 Content-Type: MULTIPART/MIXED;
117 BOUNDARY="----=_NextPart_000_0000_00000000.00000000"
118 Content-Transfer-Encoding: QUOTED-PRINTABLE
119
120 This message is in MIME format. The first part should be readable
121 text,
122 while the remaining parts are likely unreadable without MIME-aware
123 tools.
124
125 ------=_NextPart_000_0000_00000000.00000000
126 Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-15
127 Content-Transfer-Encoding: 8BIT
128
129 Some text in swedish.
130
131 Varf=C3=B6r inte anv=C3=A4nda...
132
133 ------=_NextPart_000_0000_00000000.00000000--
134
135 And some text after the last part.
136 EOF
137
138 cp -p "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/12
139
140 run_test 'mhfixmsg last -nofixcte' ''
141 check "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/12 'keep first'
142
143
144 # check -fixcte (enabled by default): fixup of erroneous C-T-E in multipart
145 # check -verbose
146 start_test "-fixcte (enabled by default): fixup of erroneous C-T-E in multipart, and -verbose"
147 cat >"$expected" <<EOF
148 From: Anon
149 To: Mailinglist
150 Subject: =?ISO-8859-15?Q?Re=3A_H=E5lla_linuxsystem_uppdaterade?=
151 User-Agent: Alpine 2.00 (DEB 1167 2008-08-23)
152 MIME-Version: 1.0
153 Content-Type: MULTIPART/MIXED;
154 BOUNDARY="----=_NextPart_000_0000_00000000.00000000"
155 Nmh-REPLACED-INVALID-Content-Transfer-Encoding: QUOTED-PRINTABLE
156 Content-Transfer-Encoding: 8bit
157
158 This message is in MIME format. The first part should be readable
159 text,
160 while the remaining parts are likely unreadable without MIME-aware
161 tools.
162
163 ------=_NextPart_000_0000_00000000.00000000
164 Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-15
165 Content-Transfer-Encoding: 8BIT
166
167 Some text in swedish.
168
169 Varf=C3=B6r inte anv=C3=A4nda...
170
171 ------=_NextPart_000_0000_00000000.00000000--
172
173 And some text after the last part.
174 EOF
175
176 run_test 'mhfixmsg last -outfile '"$actual"' -verbose' \
177 "mhfixmsg: 11, replace Content-Transfer-Encoding of \
178 QUOTED-PRINTABLE with 8 bit"
179 check "$expected" "$actual" 'keep first'
180
181
182 # check with no options: checks backup
183 start_test "with no options: checks backup"
184 cp "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/11.original
185 folder last >/dev/null
186 run_test 'mhfixmsg' ''
187 check "$expected" "$MH_TEST_DIR"/Mail/inbox/11 'keep first'
188 cp "$MH_TEST_DIR"/Mail/inbox/11.original "$MH_TEST_DIR"/Mail/inbox/11
189 check "$MH_TEST_DIR"/Mail/inbox/,11 "$MH_TEST_DIR"/Mail/inbox/11.original
190
191
192 # check backup with -file
193 start_test "backup with -file"
194 cp "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/11.original
195 folder last >/dev/null
196 run_test 'mhfixmsg -file '"$MH_TEST_DIR"/Mail/inbox/11 ''
197 check "$MH_TEST_DIR"/Mail/inbox/11 "$expected" 'keep first'
198 check "$MH_TEST_DIR"/Mail/inbox/,11 "$MH_TEST_DIR"/Mail/inbox/11.original
199
200
201 # check -reformat (enabled by default): addition of text/plain part
202 # to solitary text/html part
203 start_test "-reformat (enabled by default): addition of text/plain part"
204 prepare_space >"$expected" <<EOF
205 MIME-Version: 1.0
206 From: sender@example.com
207 To: bonquiqui@example.com
208 Subject: rue
209 Date: Sat, 26 Jan 2013 17:37:53 -0500
210 Content-Type: multipart/alternative; boundary="----=_nmh-multipart"
211
212 ------=_nmh-multipart
213 Content-Type: text/plain; charset="Windows-1252"
214 Content-Transfer-Encoding: 8bit
215
216 Need to go! Need ... to ... go!
217
218 ------=_nmh-multipart
219 Content-Type: text/html; charset="Windows-1252"
220 Content-Transfer-Encoding: 8bit
221
222 <html>
223 <head>
224 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
225 <meta name="Generator" content="Microsoft Exchange Server">
226 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-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
234 ------=_nmh-multipart--
235 EOF
236
237 cat >"$MH_TEST_DIR"/Mail/inbox/12 <<EOF
238 MIME-Version: 1.0
239 From: sender@example.com
240 To: bonquiqui@example.com
241 Subject: rue
242 Date: Sat, 26 Jan 2013 17:37:53 -0500
243 Content-Type: text/html; charset="Windows-1252"
244 Content-Transfer-Encoding: quoted-printable
245
246 <html>
247 <head>
248 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
249 252">
250 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
251 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
252 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
253 </head>
254 <body>
255 <div>
256 <div>Need to go! Need ... to ... go!</div>
257 </body>
258 </html>
259 EOF
260
261 if [ $can_reformat_texthtml -eq 1 ]; then
262 printf '%s\n' "mhfixmsg: 12, insert text/plain part
263 mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
264 >"$expected.err"
265
266 #### lynx inserts multiple blank lines, so squeeze them.
267 run_prog mhfixmsg last -outfile - -verbose 2>"$actual.err" | \
268 squeeze_lines >"$actual"
269 check "$expected" "$actual" 'ignore space'
270 check "$expected.err" "$actual.err"
271 else
272 rm -f "$expected"
273 fi
274
275
276 # check implicit -file with absolute pathname
277 start_test "implicit -file with absolute pathname"
278 run_test "mhfixmsg `mhpath last` -outfile /dev/null" ''
279
280
281 # check handling of boundary string that appears in message body
282 start_test "handling of boundary string that appears in message body"
283 prepare_space >"$expected" <<EOF
284 MIME-Version: 1.0
285 From: sender@example.com
286 To: bonquiqui@example.com
287 Subject: rue
288 Date: Sat, 26 Jan 2013 17:37:53 -0500
289 Content-Type: multipart/alternative; boundary="----=_nmh-multipart-3"
290
291 ------=_nmh-multipart-3
292 Content-Type: text/plain; charset="Windows-1252"
293 Content-Transfer-Encoding: 8bit
294
295 ------=_nmh-multipart
296 ------=_nmh-multipart-1
297 ------=_nmh-multipart-2
298
299 ------=_nmh-multipart-3
300 Content-Type: text/html; charset="Windows-1252"
301 Content-Transfer-Encoding: 8bit
302
303 <html>
304 <head>
305 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
306 <meta name="Generator" content="Microsoft Exchange Server">
307 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
308 </head>
309 <body>
310 ------=_nmh-multipart<br>
311 ------=_nmh-multipart-1<br>
312 ------=_nmh-multipart-2<br>
313 </body>
314 </html>
315
316 ------=_nmh-multipart-3--
317 EOF
318
319 cat >"$MH_TEST_DIR"/Mail/inbox/12 <<EOF
320 MIME-Version: 1.0
321 From: sender@example.com
322 To: bonquiqui@example.com
323 Subject: rue
324 Date: Sat, 26 Jan 2013 17:37:53 -0500
325 Content-Type: text/html; charset="Windows-1252"
326 Content-Transfer-Encoding: quoted-printable
327
328 <html>
329 <head>
330 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
331 252">
332 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
333 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
334 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
335 </head>
336 <body>
337 ------=3D_nmh-multipart<br>
338 ------=3D_nmh-multipart-1<br>
339 ------=3D_nmh-multipart-2<br>
340 </body>
341 </html>
342 EOF
343
344 if [ $can_reformat_texthtml -eq 1 ]; then
345 printf '%s\n' "mhfixmsg: 12, insert text/plain part
346 mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
347 >"$expected.err"
348
349 #### lynx inserts multiple blank lines, so squeeze them.
350 run_prog mhfixmsg last -outfile - -verbose 2>"$actual.err" | \
351 squeeze_lines >"$actual"
352 check "$expected" "$actual" 'ignore space'
353 check "$expected.err" "$actual.err"
354 else
355 rm -f "$expected"
356 fi
357
358
359 # check -nodecode
360 start_test "-nodecode"
361 prepare_space >"$expected" <<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: multipart/alternative; boundary="----=_nmh-multipart"
368
369 ------=_nmh-multipart
370 Content-Type: text/plain; charset="Windows-1252"
371 Content-Transfer-Encoding: 8bit
372
373 Need to go! Need ... to ... go!
374
375 ------=_nmh-multipart
376 Content-Type: text/html; charset="Windows-1252"
377 Content-Transfer-Encoding: quoted-printable
378
379 <html>
380 <head>
381 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-=
382 1252">
383 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
384 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pa=
385 dding-left: 4pt; border-left: #800000 2px solid; } --></style>
386 </head>
387 <body>
388 <div>
389 <div>Need to go! Need ... to ... go!</div>
390 </body>
391 </html>
392
393 ------=_nmh-multipart--
394 EOF
395
396 cat >"$MH_TEST_DIR"/Mail/inbox/12 <<EOF
397 MIME-Version: 1.0
398 From: sender@example.com
399 To: bonquiqui@example.com
400 Subject: rue
401 Date: Sat, 26 Jan 2013 17:37:53 -0500
402 Content-Type: text/html; charset="Windows-1252"
403 Content-Transfer-Encoding: quoted-printable
404
405 <html>
406 <head>
407 <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
408 252">
409 <meta name=3D"Generator" content=3D"Microsoft Exchange Server">
410 <!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; pad=
411 ding-left: 4pt; border-left: #800000 2px solid; } --></style>
412 </head>
413 <body>
414 <div>
415 <div>Need to go! Need ... to ... go!</div>
416 </body>
417 </html>
418 EOF
419
420 if [ $can_reformat_texthtml -eq 1 ]; then
421 printf '%s\n' 'mhfixmsg: 12, insert text/plain part' >"$expected.err"
422
423 #### lynx inserts multiple blank lines, so squeeze them.
424 run_prog mhfixmsg last -nodecode -outfile - -verbose 2>"$actual.err" | \
425 squeeze_lines >"$actual"
426 check "$expected" "$actual" 'ignore space'
427 check "$expected.err" "$actual.err"
428 else
429 rm -f "$expected"
430 fi
431
432
433 # check -decodetext (enabled by default)
434 start_test "-decodetext (enabled by default)"
435 cat >"$expected" <<EOF
436 To: recipient@example.com
437 From: sender@example.com
438 Subject: mhfixmsg decode test 1
439 MIME-Version: 1.0
440 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
441
442 ------- =_aaaaaaaaaa0
443 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
444 Content-Disposition: attachment; filename="test4.txt"
445 Content-Transfer-Encoding: 8bit
446
447 This is a text/plain part.
448
449 ------- =_aaaaaaaaaa0--
450 EOF
451
452 cat >`mhpath new` <<EOF
453 To: recipient@example.com
454 From: sender@example.com
455 Subject: mhfixmsg decode test 1
456 MIME-Version: 1.0
457 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
458
459 ------- =_aaaaaaaaaa0
460 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
461 Content-Disposition: attachment; filename="test4.txt"
462 Content-Transfer-Encoding: base64
463
464 VGhpcyBpcyBhIHRleHQvcGxhaW4gcGFydC4K
465
466 ------- =_aaaaaaaaaa0--
467 EOF
468
469 run_prog mhfixmsg last -outfile "$actual"
470 check "$expected" "$actual"
471
472
473 # check -decodetext with more complicated content structure
474 start_test "-decodetext with more complicated content structure"
475 cat >$expected <<EOF
476 To: recipient@example.com
477 From: sender@example.com
478 Subject: mhfixmsg decode test 2
479 MIME-Version: 1.0
480 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
481
482 This is additional content before the first subpart of the multipart.
483
484 ------- =_aaaaaaaaaa0
485 Content-Type: multipart/related;
486 type="text/plain"; boundary="subpart__1.1"
487
488 --subpart__1.1
489 Content-Type: text/plain; charset="iso-8859-1"
490 Content-Disposition: attachment; filename="test1.txt"
491
492 This is the first text/plain part, in a subpart.
493
494 --subpart__1.1--
495
496 This is additional content after the last subpart of the multipart.
497
498 ------- =_aaaaaaaaaa0
499 Content-Type: text/plain; charset="iso-8859-1"
500 Content-Disposition: attachment; filename="test2.txt"
501 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
502 Content-Transfer-Encoding: 8bit
503
504 This is the second text/plain part.
505
506 ------- =_aaaaaaaaaa0
507 Content-Type: text/plain; charset="iso-8859-1"
508 Content-Disposition: attachment; filename="test3.txt"
509
510 This is the third text/plain part.
511
512 ------- =_aaaaaaaaaa0
513 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
514 Content-Disposition: attachment; filename="test4.txt"
515 Content-Transfer-Encoding: 8bit
516
517 This is the fourth text/plain part.
518
519 ------- =_aaaaaaaaaa0--
520
521 This is additional content after the last subpart of the multipart.
522 EOF
523
524 cat >`mhpath new` <<EOF
525 To: recipient@example.com
526 From: sender@example.com
527 Subject: mhfixmsg decode test 2
528 MIME-Version: 1.0
529 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
530
531 This is additional content before the first subpart of the multipart.
532
533 ------- =_aaaaaaaaaa0
534 Content-Type: multipart/related;
535 type="text/plain"; boundary="subpart__1.1"
536
537 --subpart__1.1
538 Content-Type: text/plain; charset="iso-8859-1"
539 Content-Disposition: attachment; filename="test1.txt"
540
541 This is the first text/plain part, in a subpart.
542
543 --subpart__1.1--
544
545 This is additional content after the last subpart of the multipart.
546
547 ------- =_aaaaaaaaaa0
548 Content-Type: text/plain; charset="iso-8859-1"
549 Content-Disposition: attachment; filename="test2.txt"
550 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
551 Content-Transfer-Encoding: quoted-printable
552
553 This is the second text/plain part.
554
555 ------- =_aaaaaaaaaa0
556 Content-Type: text/plain; charset="iso-8859-1"
557 Content-Disposition: attachment; filename="test3.txt"
558
559 This is the third text/plain part.
560
561 ------- =_aaaaaaaaaa0
562 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
563 Content-Disposition: attachment; filename="test4.txt"
564 Content-Transfer-Encoding: base64
565
566 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4K
567
568 ------- =_aaaaaaaaaa0--
569
570 This is additional content after the last subpart of the multipart.
571 EOF
572 run_prog mhfixmsg last -outfile "$actual"
573 check "$expected" "$actual"
574
575
576 # check attempted (default, 8 bit) -decodetext of binary text
577 #### Generated the encoded text below with:
578 #### $ printf '\275\262=\274\000\n' | base64
579 start_test "attempted (default, 8 bit) -decodetext of binary text"
580 cat >`mhpath new` <<EOF
581 To: recipient@example.com
582 From: sender@example.com
583 Subject: mhfixmsg binary decode test
584 MIME-Version: 1.0
585 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
586
587 ------- =_aaaaaaaaaa0
588 Content-Type: text/plain; charset=UTF-8; name="nul+square.txt"
589 Content-Transfer-Encoding: base64
590
591 vbI9vAAK
592
593 ------- =_aaaaaaaaaa0--
594 EOF
595
596 cp -p `mhpath last` "$expected"
597 run_prog mhfixmsg last
598 check `mhpath last` "$expected" 'keep first'
599
600
601 # check for successful decode of a different part with attempted -decodetext
602 # of binary (>998 characters) text
603 start_test "for successful decode of a different part with attempted -decodetext"
604 cat >$expected <<EOF
605 To: recipient@example.com
606 From: sender@example.com
607 Subject: mhfixmsg successful decode of text/plain with failed binary decode
608 MIME-Version: 1.0
609 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
610
611 ------- =_aaaaaaaaaa0
612 Content-Type: text/plain; charset="iso-8859-1"
613 Content-Transfer-Encoding: 8bit
614
615 This is a text plain part
616
617 ------- =_aaaaaaaaaa0
618 Content-Type: text/html; charset="ascii"
619 Content-Transfer-Encoding: base64
620 Content-Disposition: inline
621
622 PGh0bWw+PGhlYWQ+PHRpdGxlPmxvbmcgbGluZTwvdGl0bGU+PC9oZWFkPjxib2R5PlRoaXMgbGlu
623 ZSBpcyBncmVhdGVyIHRoYW4gOTk4IGNoYXJhY3RlcnMgaW4gbGVuZ3RoLCBzbyB0aGlzIHBhcnQg
624 c2hvdWxkIG5vdCBiZSBkZWNvZGVkLiAgVGhpcyBsaW5lIGlzIGdyZWF0ZXIgdGhhbiA5OTggY2hh
625 cmFjdGVycyBpbiBsZW5ndGgsIHNvIHRoaXMgcGFydCBzaG91bGQgbm90IGJlIGRlY29kZWQuICBU
626 aGlzIGxpbmUgaXMgZ3JlYXRlciB0aGFuIDk5OCBjaGFyYWN0ZXJzIGluIGxlbmd0aCwgc28gdGhp
627 cyBwYXJ0IHNob3VsZCBub3QgYmUgZGVjb2RlZC4gIFRoaXMgbGluZSBpcyBncmVhdGVyIHRoYW4g
628 OTk4IGNoYXJhY3RlcnMgaW4gbGVuZ3RoLCBzbyB0aGlzIHBhcnQgc2hvdWxkIG5vdCBiZSBkZWNv
629 ZGVkLiAgVGhpcyBsaW5lIGlzIGdyZWF0ZXIgdGhhbiA5OTggY2hhcmFjdGVycyBpbiBsZW5ndGgs
630 IHNvIHRoaXMgcGFydCBzaG91bGQgbm90IGJlIGRlY29kZWQuICBUaGlzIGxpbmUgaXMgZ3JlYXRl
631 ciB0aGFuIDk5OCBjaGFyYWN0ZXJzIGluIGxlbmd0aCwgc28gdGhpcyBwYXJ0IHNob3VsZCBub3Qg
632 YmUgZGVjb2RlZC4gIFRoaXMgbGluZSBpcyBncmVhdGVyIHRoYW4gOTk4IGNoYXJhY3RlcnMgaW4g
633 bGVuZ3RoLCBzbyB0aGlzIHBhcnQgc2hvdWxkIG5vdCBiZSBkZWNvZGVkLiAgVGhpcyBsaW5lIGlz
634 IGdyZWF0ZXIgdGhhbiA5OTggY2hhcmFjdGVycyBpbiBsZW5ndGgsIHNvIHRoaXMgcGFydCBzaG91
635 bGQgbm90IGJlIGRlY29kZWQuICBUaGlzIGxpbmUgaXMgZ3JlYXRlciB0aGFuIDk5OCBjaGFyYWN0
636 ZXJzIGluIGxlbmd0aCwgc28gdGhpcyBwYXJ0IHNob3VsZCBub3QgYmUgZGVjb2RlZC4gIFRoaXMg
637 bGluZSBpcyBncmVhdGVyIHRoYW4gOTk4IGNoYXJhY3RlcnMgaW4gbGVuZ3RoLCBzbyB0aGlzIHBh
638 cnQgc2hvdWxkIG5vdCBiZSBkZWNvZGVkLiAgVGhpcyBsaW5lIGlzIGdyZWF0ZXIgdGhhbiA5OTgg
639 Y2hhcmFjdGVycyBpbiBsZW5ndGgsIHNvIHRoaXMgcGFydCBzaG91bGQgbm90IGJlIGRlY29kZWQu
640 ICA8L2JvZHk+PC9odG1sPg==
641
642 ------- =_aaaaaaaaaa0--
643 EOF
644
645 cat >`mhpath new` <<EOF
646 To: recipient@example.com
647 From: sender@example.com
648 Subject: mhfixmsg successful decode of text/plain with failed binary decode
649 MIME-Version: 1.0
650 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
651
652 ------- =_aaaaaaaaaa0
653 Content-Type: text/plain; charset="iso-8859-1"
654 Content-Transfer-Encoding: base64
655
656 VGhpcyBpcyBhIHRleHQgcGxhaW4gcGFydAo=
657
658 ------- =_aaaaaaaaaa0
659 Content-Type: text/html; charset="ascii"
660 Content-Transfer-Encoding: base64
661 Content-Disposition: inline
662
663 PGh0bWw+PGhlYWQ+PHRpdGxlPmxvbmcgbGluZTwvdGl0bGU+PC9oZWFkPjxib2R5PlRoaXMgbGlu
664 ZSBpcyBncmVhdGVyIHRoYW4gOTk4IGNoYXJhY3RlcnMgaW4gbGVuZ3RoLCBzbyB0aGlzIHBhcnQg
665 c2hvdWxkIG5vdCBiZSBkZWNvZGVkLiAgVGhpcyBsaW5lIGlzIGdyZWF0ZXIgdGhhbiA5OTggY2hh
666 cmFjdGVycyBpbiBsZW5ndGgsIHNvIHRoaXMgcGFydCBzaG91bGQgbm90IGJlIGRlY29kZWQuICBU
667 aGlzIGxpbmUgaXMgZ3JlYXRlciB0aGFuIDk5OCBjaGFyYWN0ZXJzIGluIGxlbmd0aCwgc28gdGhp
668 cyBwYXJ0IHNob3VsZCBub3QgYmUgZGVjb2RlZC4gIFRoaXMgbGluZSBpcyBncmVhdGVyIHRoYW4g
669 OTk4IGNoYXJhY3RlcnMgaW4gbGVuZ3RoLCBzbyB0aGlzIHBhcnQgc2hvdWxkIG5vdCBiZSBkZWNv
670 ZGVkLiAgVGhpcyBsaW5lIGlzIGdyZWF0ZXIgdGhhbiA5OTggY2hhcmFjdGVycyBpbiBsZW5ndGgs
671 IHNvIHRoaXMgcGFydCBzaG91bGQgbm90IGJlIGRlY29kZWQuICBUaGlzIGxpbmUgaXMgZ3JlYXRl
672 ciB0aGFuIDk5OCBjaGFyYWN0ZXJzIGluIGxlbmd0aCwgc28gdGhpcyBwYXJ0IHNob3VsZCBub3Qg
673 YmUgZGVjb2RlZC4gIFRoaXMgbGluZSBpcyBncmVhdGVyIHRoYW4gOTk4IGNoYXJhY3RlcnMgaW4g
674 bGVuZ3RoLCBzbyB0aGlzIHBhcnQgc2hvdWxkIG5vdCBiZSBkZWNvZGVkLiAgVGhpcyBsaW5lIGlz
675 IGdyZWF0ZXIgdGhhbiA5OTggY2hhcmFjdGVycyBpbiBsZW5ndGgsIHNvIHRoaXMgcGFydCBzaG91
676 bGQgbm90IGJlIGRlY29kZWQuICBUaGlzIGxpbmUgaXMgZ3JlYXRlciB0aGFuIDk5OCBjaGFyYWN0
677 ZXJzIGluIGxlbmd0aCwgc28gdGhpcyBwYXJ0IHNob3VsZCBub3QgYmUgZGVjb2RlZC4gIFRoaXMg
678 bGluZSBpcyBncmVhdGVyIHRoYW4gOTk4IGNoYXJhY3RlcnMgaW4gbGVuZ3RoLCBzbyB0aGlzIHBh
679 cnQgc2hvdWxkIG5vdCBiZSBkZWNvZGVkLiAgVGhpcyBsaW5lIGlzIGdyZWF0ZXIgdGhhbiA5OTgg
680 Y2hhcmFjdGVycyBpbiBsZW5ndGgsIHNvIHRoaXMgcGFydCBzaG91bGQgbm90IGJlIGRlY29kZWQu
681 ICA8L2JvZHk+PC9odG1sPg==
682
683 ------- =_aaaaaaaaaa0--
684 EOF
685
686 run_prog mhfixmsg -noreformat last
687 check `mhpath last` "$expected" 'keep first'
688
689
690 # check for successful decode of a different part with -decodetext of binary
691 # (>998 characters) text
692 start_test "for successful decode of a different part with -decodetext of binary"
693 cat >$expected <<EOF
694 To: recipient@example.com
695 From: sender@example.com
696 Subject: mhfixmsg successful decode of text/plain with failed binary decode
697 MIME-Version: 1.0
698 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
699
700 ------- =_aaaaaaaaaa0
701 Content-Type: text/plain; charset="iso-8859-1"
702 Content-Transfer-Encoding: 8bit
703
704 This is a text plain part
705
706 ------- =_aaaaaaaaaa0
707 Content-Type: text/html; charset="ascii"
708 Content-Transfer-Encoding: binary
709 Content-Disposition: inline
710
711 <html><head><title>long line</title></head><body>This line is greater than 998 characters in length, so this part should not be decoded. This line is greater than 998 characters in length, so this part should not be decoded. This line is greater than 998 characters in length, so this part should not be decoded. This line is greater than 998 characters in length, so this part should not be decoded. This line is greater than 998 characters in length, so this part should not be decoded. This line is greater than 998 characters in length, so this part should not be decoded. This line is greater than 998 characters in length, so this part should not be decoded. This line is greater than 998 characters in length, so this part should not be decoded. This line is greater than 998 characters in length, so this part should not be decoded. This line is greater than 998 characters in length, so this part should not be decoded. This line is greater than 998 characters in length, so this part should not be decoded. </body></html>
712
713 ------- =_aaaaaaaaaa0--
714 EOF
715
716 run_prog mhfixmsg -noreformat -decodetext binary last
717 check `mhpath last` "$expected"
718
719
720 # check -decodetext of binary (containing ASCII NUL) text
721 start_test "-decodetext of binary (containing ASCII NUL) text"
722 printf "%s\275\262=\274\000%s" "To: recipient@example.com
723 From: sender@example.com
724 Subject: mhfixmsg binary decode test
725 MIME-Version: 1.0
726 Content-Type: multipart/mixed; boundary=\"----- =_aaaaaaaaaa0\"
727
728 ------- =_aaaaaaaaaa0
729 Content-Type: text/plain; charset=UTF-8; name=\"nul+square.txt\"
730 Content-Transfer-Encoding: binary
731
732 " "
733
734 ------- =_aaaaaaaaaa0--
735 " >"$expected"
736 mhfixmsg last -decodetext binary -outfile "$actual"
737 check "$expected" "$actual"
738
739
740 # check that -reformat succeeds when decode of binary text fails
741 start_test "that -reformat succeeds when decode of binary text fails"
742 prepare_space >"$expected" <<'EOF'
743 MIME-Version: 1.0
744 Date: Thu, 11 Apr 2013 02:47:08 -0700
745 To: <me@example.com>
746 From: <sender@example.com>
747 Subject: body requires binary encoding
748 Content-Type: multipart/alternative; boundary="----=_nmh-multipart"
749
750 ------=_nmh-multipart
751 Content-Type: text/plain; charset="ISO-8859-1"
752 Content-Transfer-Encoding: 8bit
753
754 Mile $0.00
755 Time $78.71
756 State Tax $5.90
757 Vehicle License Fee $1.84
758 State Txn Tax $6.00
759
760 ------=_nmh-multipart
761 Content-Type: text/html; charset="ISO-8859-1"
762 Content-Transfer-Encoding: quoted-printable
763
764 <body>
765 EOF
766
767 cat >`mhpath new` <<'EOF'
768 MIME-Version: 1.0
769 Content-Type: text/html; charset="ISO-8859-1"
770 Content-Transfer-Encoding: quoted-printable
771 Date: Thu, 11 Apr 2013 02:47:08 -0700
772 To: <me@example.com>
773 From: <sender@example.com>
774 Subject: body requires binary encoding
775
776 <body>
777 <table width=3D"325" border=3D"0" cellspacing=3D"0" cellpadding=3D"0">
778 <tr><td><font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" size=
779 =3D"2"><strong>Mile</strong></font></td><td height=3D"3">&nbsp;</td><td ali=
780 gn=3D"right"><font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" =
781 size=3D"2">$0.00</font></td></tr><tr><td><font face=3D"Arial, Helvetica, sa=
782 ns-serif" color=3D"#333333" size=3D"2"><strong>Time</strong></font></td><td=
783 height=3D"3">&nbsp;</td><td align=3D"right"><font face=3D"Arial, Helvetica=
784 , sans-serif" color=3D"#333333" size=3D"2">$78.71</font></td></tr><tr><td><=
785 font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" size=3D"2"><st=
786 rong>State Tax</strong></font></td><td height=3D"3">&nbsp;</td><td align=3D=
787 "right"><font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" size=
788 =3D"2">$5.90</font></td></tr><tr><td><font face=3D"Arial, Helvetica, sans-s=
789 erif" color=3D"#333333" size=3D"2"><strong>Vehicle License Fee</strong></fo=
790 nt></td><td height=3D"3">&nbsp;</td><td align=3D"right"><font face=3D"Arial=
791 , Helvetica, sans-serif" color=3D"#333333" size=3D"2">$1.84</font></td></tr=
792 ><tr><td><font face=3D"Arial, Helvetica, sans-serif" color=3D"#333333" size=
793 =3D"2"><strong>State Txn Tax</strong></font></td><td height=3D"3">&nbsp;</t=
794 d><td align=3D"right"><font face=3D"Arial, Helvetica, sans-serif" color=3D"=
795 #333333" size=3D"2">$6.00</font></td></tr>
796
797 </body>
798 </html>
799 EOF
800
801 if [ $can_reformat_texthtml -eq 1 ]; then
802 #### lynx inserts multiple blank lines, so squeeze them.
803 #### Truncate to avoid comparing the html portion because it can
804 #### get reformatted.
805 run_prog mhfixmsg last -outfile - | squeeze_lines | head -22 >"$actual"
806 check "$expected" "$actual" 'ignore space'
807 else
808 cp -p "$MH_TEST_DIR/Mail/inbox/15" "$MH_TEST_DIR/Mail/inbox/15.backup"
809 rm -f "$expected"
810 fi
811
812
813 # check -textcharset
814 # Also checks preservation of attributes after one (charset) that is
815 # modified.
816 start_test "-textcharset"
817 cat >"$expected" <<EOF
818 To: recipient@example.com
819 From: sender@example.com
820 Subject: mhfixmsg textcharset test
821 MIME-Version: 1.0
822 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
823
824 ------- =_aaaaaaaaaa0
825 Content-Type: text/plain; charset="utf-8"; name="square.txt"
826 Content-Disposition: attachment; filename="square.txt"
827 Content-Transfer-Encoding: 8bit
828
829 ½²=¼
830
831 ------- =_aaaaaaaaaa0--
832 EOF
833
834 #### Generated the encoded text below with:
835 #### $ printf '\275\262=\274\n' | base64
836 cat >`mhpath new` <<EOF
837 To: recipient@example.com
838 From: sender@example.com
839 Subject: mhfixmsg textcharset test
840 MIME-Version: 1.0
841 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
842
843 ------- =_aaaaaaaaaa0
844 Content-Type: text/plain; charset="iso-8859-1"; name="square.txt"
845 Content-Disposition: attachment; filename="square.txt"
846 Content-Transfer-Encoding: base64
847
848 vbI9vAo=
849
850 ------- =_aaaaaaaaaa0--
851 EOF
852
853 if test "$ICONV_ENABLED" -eq 1; then
854 run_prog mhfixmsg last -textcharset utf-8 -outfile "$actual" 2>&1
855 check "$expected" "$actual"
856 else
857 echo "$0: skipping -textcharset check because nmh was built without iconv"
858 rm -f "$expected"
859 fi
860
861
862 # check -nofixboundary
863 start_test "-nofixboundary"
864 cat >"$expected" <<EOF
865 EOF
866
867 cat >`mhpath new` <<EOF
868 Date: Fri, 13 May 2011 08:21:12 -0500
869 Content-Type: multipart/alternative;
870 boundary="----=_NextPart_000_1781A17_01CC1147.81E9467A"
871 Content-Transfer-Encoding: 8bit
872 MIME-Version: 1.0
873 From: <sender@example.com>
874 To: <recipient@example.com>
875 Subject: mhfixmsg bad boundary test
876
877 This is a multi-part message in MIME format.
878
879 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4
880 Content-Type: text/plain
881
882 The boundaries of this part don't match the header boundary.
883
884 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4--
885 EOF
886
887 cp -p `mhpath last` `mhpath new`
888
889 run_test 'mhfixmsg last -nofixboundary' ''
890 check "$MH_TEST_DIR"/Mail/inbox/18 "$MH_TEST_DIR"/Mail/inbox/19 'keep first'
891
892
893 # check that message is not output when fed through stdin
894 start_test "that message is not output when fed through stdin"
895 run_prog mhfixmsg -file - -verbose <`mhpath last` >"$actual" 2>"$actual.err"
896 check "$expected" "$actual"
897 if grep "mhfixmsg: $MH_TEST_DIR/Mail/.*, fix multipart boundary" \
898 "$actual.err" >/dev/null; then
899 rm -f "$actual.err"
900 else
901 echo "$0: test failed, output is in $actual.err."
902 failed=`expr ${failed:-0} + 1`
903 fi
904
905
906 # check fixup of erroneous boundary in multipart (-fixboundary,
907 # enabled by default)
908 # check -verbose
909 start_test "fixup of erroneous boundary in multipart (-fixboundary, enabled by default)"
910 cat >"$expected" <<EOF
911 Date: Fri, 13 May 2011 08:21:12 -0500
912 Content-Type: multipart/alternative;
913 boundary="----=_NextPart_000_1781A1A_01CC1147.81EBA8D4"
914 Content-Transfer-Encoding: 8bit
915 MIME-Version: 1.0
916 From: <sender@example.com>
917 To: <recipient@example.com>
918 Subject: mhfixmsg bad boundary test
919
920 This is a multi-part message in MIME format.
921
922 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4
923 Content-Type: text/plain
924
925 The boundaries of this part don't match the header boundary.
926
927 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4--
928 EOF
929
930 run_test 'mhfixmsg last -outfile '"$actual"' -verbose' \
931 "mhfixmsg: 18, fix multipart boundary"
932 check "$expected" "$actual"
933
934
935 # check that message is not modified when -fixboundary fails
936 start_test "that message is not modified when -fixboundary fails"
937 cat >`mhpath new` <<EOF
938 Date: Fri, 13 May 2011 08:21:12 -0500
939 Content-Type: multipart/alternative;
940 boundary="----=_ NextPart_000_1781A17_01CC1147.81E9467A"
941 Content-Transfer-Encoding: 8bit
942 MIME-Version: 1.0
943 From: <sender@example.com>
944 To: <recipient@example.com>
945 Subject: mhfixmsg bad boundary test
946
947 This is a multi-part message in MIME format.
948
949 ------=_ NextPart_000_1781A1A_01CC1147.81EBA8D4
950 Content-Type: text/plain
951
952 The boundary below doesn't match the header boundary.
953
954 ------=_
955 NextPart_000_1781A1A_01CC1147.81EBA8D4--
956 EOF
957
958 cp -p `mhpath last` "$expected"
959 run_test "mhfixmsg last -outfile $actual" ''
960 check "$expected" "$actual"
961
962
963 # check that text/plain part is not added to text/html in multipart/related
964 # when it shouldn't be
965 start_test "that text/plain part is not added to text/html in multipart/related when it shouldn't be"
966 cat >`mhpath new` <<EOF
967 MIME-Version: 1.0
968 Date: Tue, 26 Feb 2013 18:07:20 -0600
969 Subject: multipart/related, not /alternative
970 Content-Type: multipart/related;
971 type="text/html"; boundary="----=_Part_90310_101292502.1"
972
973 ------=_Part_90310_101292502.1
974 Content-Type: text/html; charset="us-ascii"
975 Content-Transfer-Encoding: 7bit
976
977 <html><head>
978 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
979 <title>HTML Content</title>
980 </head>
981 <body>
982 This is the real content.
983 </body>
984 </html>
985
986 ------=_Part_90310_101292502.1
987 Content-Type: text/plain; charset="us-ascii"
988 Content-Transfer-Encoding: 7bit
989
990 Your email client does not support HTML messages
991
992 ------=_Part_90310_101292502.1--
993 EOF
994
995 cp -p `mhpath last` "$expected"
996
997 if [ $can_reformat_texthtml -eq 1 ]; then
998 #### lynx inserts multiple blank lines, so squeeze them.
999 run_prog mhfixmsg last -outfile - | squeeze_lines >"$actual"
1000 check "$expected" "$actual" 'ignore space'
1001 else
1002 rm -f "$expected"
1003 fi
1004
1005
1006 # check that text/plain part is added to text/html in multipart/related
1007 # when it should be
1008 start_test "that text/plain part is added to text/html in multipart/related when it should be"
1009 cat >"$expected" <<EOF
1010 MIME-Version: 1.0
1011 Date: Tue, 26 Feb 2013 18:07:20 -0600
1012 Subject: multipart/related, not /alternative
1013 Content-Type: multipart/alternative; boundary="----=_Part_90310_101292502.1"
1014
1015 ------=_Part_90310_101292502.1
1016 Content-Type: text/plain; charset="us-ascii"
1017 Content-Transfer-Encoding: 7bit
1018
1019 This is the real content.
1020
1021 ------=_Part_90310_101292502.1
1022 Content-Type: text/html; charset="us-ascii"
1023 Content-Transfer-Encoding: 7bit
1024
1025 <html><head>
1026 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
1027 <title>HTML Content</title>
1028 </head>
1029 <body>
1030 This is the real content.
1031 </body>
1032 </html>
1033
1034 ------=_Part_90310_101292502.1--
1035 EOF
1036
1037 cat >`mhpath new` <<EOF
1038 MIME-Version: 1.0
1039 Date: Tue, 26 Feb 2013 18:07:20 -0600
1040 Subject: multipart/related, not /alternative
1041 Content-Type: multipart/related;
1042 type="text/html"; boundary="----=_Part_90310_101292502.1"
1043
1044 ------=_Part_90310_101292502.1
1045 Content-Type: text/html; charset="us-ascii"
1046 Content-Transfer-Encoding: 7bit
1047
1048 <html><head>
1049 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
1050 <title>HTML Content</title>
1051 </head>
1052 <body>
1053 This is the real content.
1054 </body>
1055 </html>
1056
1057 ------=_Part_90310_101292502.1--
1058 EOF
1059
1060 if [ $can_reformat_texthtml -eq 1 ]; then
1061 #### lynx inserts multiple blank lines, so squeeze them.
1062 run_prog mhfixmsg last -outfile - | squeeze_lines >"$actual"
1063 check "$expected" "$actual" 'ignore space'
1064 else
1065 rm -f "$expected"
1066 fi
1067
1068
1069 # check handling of rfc822 message type
1070 start_test "handling of rfc822 message type"
1071 cat >"$expected" <<EOF
1072 From: Test <test@example.com>
1073 To: Some User <user@example.com>
1074 Date: Fri, 29 Sep 2006 00:00:00
1075 Message-Id: @test.nmh
1076 Subject: message with message/rfc822 attachment
1077 MIME-Version: 1.0
1078 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1079
1080 and some garbage before the attachment
1081
1082 ------- =_aaaaaaaaaa0
1083 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
1084 Content-Description: 1552
1085 Content-Disposition: attachment; filename="1552"
1086
1087 From: Test <test@example.com>
1088 To: <another_user@example.com>
1089 Date: Thu, 28 Sep 2006 00:00:00
1090 Message-Id: @test.nmh
1091 Subject: message/rfc822 attachment
1092
1093 This is an RFC-822 message.
1094
1095 ------- =_aaaaaaaaaa0--
1096
1097 and some garbage at the end
1098 EOF
1099
1100 cat >`mhpath new` <<EOF
1101 From: Test <test@example.com>
1102 To: Some User <user@example.com>
1103 Date: Fri, 29 Sep 2006 00:00:00
1104 Message-Id: @test.nmh
1105 Subject: message with message/rfc822 attachment
1106 MIME-Version: 1.0
1107 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaa0"
1108
1109 and some garbage before the attachment
1110
1111 ------- =_aaaaaaaaaa0
1112 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
1113 Content-Description: 1552
1114 Content-Disposition: attachment; filename="1552"
1115
1116 From: Test <test@example.com>
1117 To: <another_user@example.com>
1118 Date: Thu, 28 Sep 2006 00:00:00
1119 Message-Id: @test.nmh
1120 Subject: message/rfc822 attachment
1121
1122 This is an RFC-822 message.
1123
1124 ------- =_aaaaaaaaaa0--
1125
1126 and some garbage at the end
1127 EOF
1128
1129 run_test 'mhfixmsg last -outfile '"$actual" ''
1130 check "$expected" "$actual"
1131
1132
1133 # check not stripping of CRs from ASCII text context (default)
1134 start_test "not stripping of CRs from ASCII text context (default)"
1135 cat >"$expected" <<EOF
1136 MIME-Version: 1.0
1137 From: sender@example.com
1138 To: recipient@example.com
1139 Subject: message with CR's
1140 Date: Mon, 29 Apr 2013 11:51:45 -0400
1141
1142 There are two CR-LF pairs at the end of this sentence.
1143
1144 EOF
1145
1146 cat >`mhpath new` <<'EOF'
1147 MIME-Version: 1.0
1148 From: sender@example.com
1149 To: recipient@example.com
1150 Subject: message with CR's
1151 Date: Mon, 29 Apr 2013 11:51:45 -0400
1152
1153 There are two CR-LF pairs at the end of this sentence.
1154
1155 EOF
1156
1157 run_prog mhfixmsg last -outfile "$actual"
1158 check "$expected" "$actual"
1159
1160
1161 # check stripping of CRs from ASCII text context
1162 start_test "stripping of CRs from ASCII text context"
1163 cat >"$expected" <<EOF
1164 MIME-Version: 1.0
1165 From: sender@example.com
1166 To: recipient@example.com
1167 Subject: message with CR's
1168 Date: Mon, 29 Apr 2013 11:51:45 -0400
1169
1170 There were two CR-LF pairs at the end of this sentence.
1171
1172 EOF
1173
1174 cat >`mhpath new` <<'EOF'
1175 MIME-Version: 1.0
1176 From: sender@example.com
1177 To: recipient@example.com
1178 Subject: message with CR's
1179 Date: Mon, 29 Apr 2013 11:51:45 -0400
1180
1181 There were two CR-LF pairs at the end of this sentence.
1182
1183 EOF
1184
1185 run_prog mhfixmsg last -outfile "$actual" -nocrlflinebreaks
1186 check "$expected" "$actual"
1187
1188
1189 # check -replacetextplain
1190 start_test "-replacetextplain"
1191 prepare_space >"$expected" <<EOF
1192 To: recipient@example.com
1193 From: sender@example.com
1194 Subject: mhfixmsg replacement of bad text/plain part test
1195 MIME-Version: 1.0
1196 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1197
1198 ------=_Part_876302
1199 Content-Type: text/plain; charset="UTF-8"
1200 Content-Transfer-Encoding: 8bit
1201
1202 Yes, the text/plain part really was empty.
1203
1204 ------=_Part_876302
1205 Content-Type: text/html; charset="UTF-8"
1206 Content-Transfer-Encoding: 8bit
1207 Content-Disposition: inline
1208
1209 <html><head>
1210 <title>eticket</title>
1211 </head>
1212 <body>
1213 Yes, the text/plain part really was empty.
1214 </body>
1215 </html>
1216
1217 ------=_Part_876302--
1218 EOF
1219
1220 cat >`mhpath new` <<'EOF'
1221 To: recipient@example.com
1222 From: sender@example.com
1223 Subject: mhfixmsg replacement of bad text/plain part test
1224 MIME-Version: 1.0
1225 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1226
1227 ------=_Part_876302
1228 Content-Type: text/plain; charset="iso-8859-15"
1229 Content-Transfer-Encoding: 7bit
1230 Content-Disposition: inline
1231
1232
1233
1234 ------=_Part_876302
1235 Content-Type: text/html; charset="UTF-8"
1236 Content-Transfer-Encoding: 8bit
1237 Content-Disposition: inline
1238
1239 <html><head>
1240 <title>eticket</title>
1241 </head>
1242 <body>
1243 Yes, the text/plain part really was empty.
1244 </body>
1245 </html>
1246
1247 ------=_Part_876302--
1248 EOF
1249
1250 if [ $can_reformat_texthtml -eq 1 ]; then
1251 #### lynx inserts multiple blank lines, so squeeze them.
1252 run_prog mhfixmsg last -replacetextplain -outfile - | \
1253 squeeze_lines > "$actual"
1254 check "$expected" "$actual" 'ignore space'
1255 else
1256 rm -f "$expected"
1257 fi
1258
1259
1260 # check -noreplacetextplain
1261 start_test "-noreplacetextplain"
1262 cat >"$expected" <<EOF
1263 To: recipient@example.com
1264 From: sender@example.com
1265 Subject: mhfixmsg replacement of bad text/plain part test
1266 MIME-Version: 1.0
1267 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1268
1269 ------=_Part_876302
1270 Content-Type: text/plain; charset="iso-8859-15"
1271 Content-Transfer-Encoding: 7bit
1272 Content-Disposition: inline
1273
1274
1275
1276 ------=_Part_876302
1277 Content-Type: text/html; charset="UTF-8"
1278 Content-Transfer-Encoding: 8bit
1279 Content-Disposition: inline
1280
1281 <html><head>
1282 <title>eticket</title>
1283 </head>
1284 <body>
1285 Yes, the text/plain part really was empty.
1286 </body>
1287 </html>
1288
1289 ------=_Part_876302--
1290 EOF
1291
1292 run_prog mhfixmsg last -replacetextplain -noreplacetextplain -outfile "$actual"
1293 check "$expected" "$actual"
1294
1295
1296 # check removal of extraneous trailing semicolon from header parameter list
1297 start_test "removal of extraneous trailing semicolon from header parameter list"
1298 cat >"$expected" <<EOF
1299 To: recipient@example.com
1300 Subject: test
1301 From: sender@example.com
1302 MIME-Version: 1.0
1303 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1304
1305 ------- =_aaaaaaaaaa0
1306 Content-Type: text/plain; charset="us-ascii"
1307
1308 test
1309
1310 ------- =_aaaaaaaaaa0
1311 Content-Type: text/plain; charset="us-ascii";
1312 name="DATE"
1313 Content-Description: check folded headers, with and without trailing semicolon
1314 Content-Disposition: attachment;
1315 filename="DATE"
1316
1317 14 April 2014
1318
1319 ------- =_aaaaaaaaaa0--
1320 EOF
1321
1322 cat >`mhpath new` <<EOF
1323 To: recipient@example.com
1324 Subject: test
1325 From: sender@example.com
1326 MIME-Version: 1.0
1327 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1328
1329 ------- =_aaaaaaaaaa0
1330 Content-Type: text/plain; charset="us-ascii";
1331
1332 test
1333
1334 ------- =_aaaaaaaaaa0
1335 Content-Type: text/plain; charset="us-ascii";
1336 name="DATE"
1337 Content-Description: check folded headers, with and without trailing semicolon
1338 Content-Disposition: attachment;
1339 filename="DATE";
1340
1341 14 April 2014
1342
1343 ------- =_aaaaaaaaaa0--
1344 EOF
1345 run_test 'mhfixmsg last -outfile '"$actual" ''
1346 check "$expected" "$actual"
1347
1348
1349 # check rmmproc
1350 start_test "rmmproc"
1351 cat >"$MH_TEST_DIR/Mail/rmmproc" <<'EOF'
1352 mv "$1" "$1.backup"
1353 EOF
1354 chmod a+x "${MH_TEST_DIR}/Mail/rmmproc"
1355 echo "rmmproc: ${MH_TEST_DIR}/Mail/rmmproc" >>"$MH"
1356 cp "${MH_TEST_DIR}/Mail/inbox/16" "${MH_TEST_DIR}/Mail/inbox/16.original"
1357
1358 run_test 'mhfixmsg 16' ''
1359 check "${MH_TEST_DIR}/Mail/inbox/16.backup" \
1360 "${MH_TEST_DIR}/Mail/inbox/16.original"
1361
1362
1363 # check -normmproc
1364 start_test "-normmproc"
1365 cp "${MH_TEST_DIR}/Mail/inbox/21" "${MH_TEST_DIR}/Mail/inbox/22"
1366
1367 run_test 'mhfixmsg 21 -normmproc'
1368 check "${MH_TEST_DIR}/Mail/inbox/22" \
1369 "${MH_TEST_DIR}/Mail/inbox/,21" 'keep first'
1370
1371
1372 # check -rmmproc
1373 start_test "-rmmproc"
1374 run_test 'mhfixmsg 21 -rmmproc true'
1375 if test -f '${MH_TEST_DIR}/Mail/inbox/22.backup'; then
1376 echo check of mhfixmsg -rmmproc FAILED, should not have created backup file
1377 failed=`expr ${failed:-0} + 1`
1378 fi
1379
1380
1381 # check -fixtype
1382 start_test "-fixtype"
1383 cat >"$expected" <<EOF
1384 To: recipient@example.com
1385 From: sender@example.com
1386 Subject: mhfixmsg with incorrect Content-Type
1387 MIME-Version: 1.0
1388 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1389
1390 ------- =_aaaaaaaaaa0
1391 Content-Type: text/plain; name="plaintext.txt"
1392
1393 this is plain text
1394
1395 ------- =_aaaaaaaaaa0--
1396 EOF
1397
1398 cat >`mhpath new` <<EOF
1399 To: recipient@example.com
1400 From: sender@example.com
1401 Subject: mhfixmsg with incorrect Content-Type
1402 MIME-Version: 1.0
1403 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1404
1405 ------- =_aaaaaaaaaa0
1406 Content-Type: application/octet-stream; name="plaintext.txt"
1407
1408 this is plain text
1409
1410 ------- =_aaaaaaaaaa0--
1411 EOF
1412
1413 mhfixmsg -fixtype application/octet-stream last
1414 check "$expected" `mhpath last`
1415
1416
1417 # check default -decodetypes
1418 start_test "default -decodetypes"
1419 cat >$expected <<EOF
1420 To: recipient@example.com
1421 From: sender@example.com
1422 Subject: mhfixmsg decode test 3
1423 MIME-Version: 1.0
1424 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1425
1426 ------- =_aaaaaaaaaa0
1427 Content-Type: text/plain; charset="iso-8859-1"
1428 Content-Disposition: attachment; filename="test1.txt"
1429 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1430 Content-Transfer-Encoding: 8bit
1431
1432 This is the text/plain part.
1433
1434 ------- =_aaaaaaaaaa0
1435 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
1436 Content-Disposition: attachment; filename="test2.txt"
1437 Content-Transfer-Encoding: 8bit
1438
1439 <html>
1440 <head>
1441 This was the text/html part.
1442 </head>
1443 </body>
1444 </html>
1445
1446 ------- =_aaaaaaaaaa0--
1447 EOF
1448
1449 cat >`mhpath new` <<EOF
1450 To: recipient@example.com
1451 From: sender@example.com
1452 Subject: mhfixmsg decode test 3
1453 MIME-Version: 1.0
1454 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1455
1456 ------- =_aaaaaaaaaa0
1457 Content-Type: text/plain; charset="iso-8859-1"
1458 Content-Disposition: attachment; filename="test1.txt"
1459 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1460 Content-Transfer-Encoding: quoted-printable
1461
1462 This is the text/plain part.
1463
1464 ------- =_aaaaaaaaaa0
1465 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
1466 Content-Disposition: attachment; filename="test2.txt"
1467 Content-Transfer-Encoding: base64
1468
1469 PGh0bWw+CjxoZWFkPgogICAgVGhpcyB3YXMgdGhlIHRleHQvaHRtbCBwYXJ0Lgo8L2hlYWQ+Cjwv
1470 Ym9keT4KPC9odG1sPgo=
1471
1472 ------- =_aaaaaaaaaa0--
1473 EOF
1474 run_prog mhfixmsg last -outfile "$actual" -noreformat
1475 check "$expected" "$actual"
1476
1477
1478 # check -decodetypes text/plain
1479 start_test "-decodetypes text/plain"
1480 cat >$expected <<EOF
1481 To: recipient@example.com
1482 From: sender@example.com
1483 Subject: mhfixmsg decode test 4
1484 MIME-Version: 1.0
1485 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1486
1487 ------- =_aaaaaaaaaa0
1488 Content-Type: text/plain; charset="iso-8859-1"
1489 Content-Disposition: attachment; filename="test1.txt"
1490 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1491 Content-Transfer-Encoding: 8bit
1492
1493 This is the text/plain part.
1494
1495 ------- =_aaaaaaaaaa0
1496 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
1497 Content-Disposition: attachment; filename="test2.txt"
1498 Content-Transfer-Encoding: base64
1499
1500 PGh0bWw+DQo8aGVhZD4NCiAgICBUaGlzIGlzIHRoZSB0ZXh0L2h0bWwgcGFydC4NCjwvaGVhZD4N
1501 CjwvYm9keT4NCjwvaHRtbD4NCg==
1502
1503 ------- =_aaaaaaaaaa0--
1504 EOF
1505
1506 cat >`mhpath new` <<EOF
1507 To: recipient@example.com
1508 From: sender@example.com
1509 Subject: mhfixmsg decode test 4
1510 MIME-Version: 1.0
1511 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1512
1513 ------- =_aaaaaaaaaa0
1514 Content-Type: text/plain; charset="iso-8859-1"
1515 Content-Disposition: attachment; filename="test1.txt"
1516 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1517 Content-Transfer-Encoding: quoted-printable
1518
1519 This is the text/plain part.
1520
1521 ------- =_aaaaaaaaaa0
1522 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
1523 Content-Disposition: attachment; filename="test2.txt"
1524 Content-Transfer-Encoding: base64
1525
1526 PGh0bWw+DQo8aGVhZD4NCiAgICBUaGlzIGlzIHRoZSB0ZXh0L2h0bWwgcGFydC4NCjwvaGVhZD4N
1527 CjwvYm9keT4NCjwvaHRtbD4NCg==
1528
1529 ------- =_aaaaaaaaaa0--
1530 EOF
1531 run_prog mhfixmsg last -outfile "$actual" -decodetypes text/plain -noreformat
1532 check "$expected" "$actual"
1533
1534
1535 # check -decodetypes attachment/ics
1536 start_test "-decodetypes attachment/ics"
1537 cat >$expected <<EOF
1538 To: recipient@example.com
1539 From: sender@example.com
1540 Subject: mhfixmsg decode test 5
1541 MIME-Version: 1.0
1542 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1543
1544 ------- =_aaaaaaaaaa0
1545 Content-Type: text/plain; charset="iso-8859-1"
1546 Content-Disposition: attachment; filename="test1.txt"
1547 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1548 Content-Transfer-Encoding: 8bit
1549
1550 This is the text/plain part.
1551
1552 ------- =_aaaaaaaaaa0
1553 Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics"
1554 Content-Disposition: attachment; filename="invite.ics"
1555 Content-Transfer-Encoding: 8bit
1556
1557 BEGIN:VCALENDAR
1558 VERSION:2.0
1559 PRODID:test-mhical
1560 BEGIN:VEVENT
1561 DTSTAMP:20150101T162400Z
1562 DTSTART:20150105T160000
1563 DTEND:20150105T163000
1564 SUMMARY:4 pm meeting
1565 END:VEVENT
1566 END:VCALENDAR
1567
1568 ------- =_aaaaaaaaaa0--
1569 EOF
1570
1571 cat >`mhpath new` <<EOF
1572 To: recipient@example.com
1573 From: sender@example.com
1574 Subject: mhfixmsg decode test 5
1575 MIME-Version: 1.0
1576 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1577
1578 ------- =_aaaaaaaaaa0
1579 Content-Type: text/plain; charset="iso-8859-1"
1580 Content-Disposition: attachment; filename="test1.txt"
1581 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1582 Content-Transfer-Encoding: quoted-printable
1583
1584 This is the=
1585 text/plain part.
1586
1587 ------- =_aaaaaaaaaa0
1588 Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics"
1589 Content-Disposition: attachment; filename="invite.ics"
1590 Content-Transfer-Encoding: base64
1591
1592 QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KUFJPRElEOnRlc3QtbWhpY2FsDQpCRUdJTjpW
1593 RVZFTlQNCkRUU1RBTVA6MjAxNTAxMDFUMTYyNDAwWg0KRFRTVEFSVDoyMDE1MDEwNVQxNjAwMDAN
1594 CkRURU5EOjIwMTUwMTA1VDE2MzAwMA0KU1VNTUFSWTo0IHBtIG1lZXRpbmcNCkVORDpWRVZFTlQN
1595 CkVORDpWQ0FMRU5EQVINCg==
1596
1597 ------- =_aaaaaaaaaa0--
1598 EOF
1599 run_prog mhfixmsg last -outfile "$actual" -noreformat
1600 check "$expected" "$actual"
1601
1602
1603 # check -decodetypes attachment/ics and -nocrlflinebreaks
1604 start_test "-decodetypes attachment/ics and -nocrlflinebreaks"
1605 cat >$expected <<EOF
1606 To: recipient@example.com
1607 From: sender@example.com
1608 Subject: mhfixmsg decode test 5
1609 MIME-Version: 1.0
1610 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1611
1612 ------- =_aaaaaaaaaa0
1613 Content-Type: text/plain; charset="iso-8859-1"
1614 Content-Disposition: attachment; filename="test1.txt"
1615 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1616 Content-Transfer-Encoding: 8bit
1617
1618 This is the text/plain part.
1619
1620 ------- =_aaaaaaaaaa0
1621 Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics"
1622 Content-Disposition: attachment; filename="invite.ics"
1623 Content-Transfer-Encoding: 8bit
1624
1625 BEGIN:VCALENDAR
1626 VERSION:2.0
1627 PRODID:test-mhical
1628 BEGIN:VEVENT
1629 DTSTAMP:20150101T162400Z
1630 DTSTART:20150105T160000
1631 DTEND:20150105T163000
1632 SUMMARY:4 pm meeting
1633 END:VEVENT
1634 END:VCALENDAR
1635
1636 ------- =_aaaaaaaaaa0--
1637 EOF
1638
1639 cat >`mhpath new` <<EOF
1640 To: recipient@example.com
1641 From: sender@example.com
1642 Subject: mhfixmsg decode test 5
1643 MIME-Version: 1.0
1644 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1645
1646 ------- =_aaaaaaaaaa0
1647 Content-Type: text/plain; charset="iso-8859-1"
1648 Content-Disposition: attachment; filename="test1.txt"
1649 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1650 Content-Transfer-Encoding: quoted-printable
1651
1652 This is the=
1653 text/plain part.
1654
1655 ------- =_aaaaaaaaaa0
1656 Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics"
1657 Content-Disposition: attachment; filename="invite.ics"
1658 Content-Transfer-Encoding: base64
1659
1660 QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KUFJPRElEOnRlc3QtbWhpY2FsDQpCRUdJTjpW
1661 RVZFTlQNCkRUU1RBTVA6MjAxNTAxMDFUMTYyNDAwWg0KRFRTVEFSVDoyMDE1MDEwNVQxNjAwMDAN
1662 CkRURU5EOjIwMTUwMTA1VDE2MzAwMA0KU1VNTUFSWTo0IHBtIG1lZXRpbmcNCkVORDpWRVZFTlQN
1663 CkVORDpWQ0FMRU5EQVINCg==
1664
1665 ------- =_aaaaaaaaaa0--
1666 EOF
1667 run_prog mhfixmsg last -outfile "$actual" -nocrlflinebreaks -noreformat
1668 check "$expected" "$actual"
1669
1670
1671 # check that input is passed through to output when there's a parse error
1672 # (the charset string is missing its closing quote) with -outfile
1673 start_test "that input is passed through to output when there's a parse error"
1674 cat >"$expected.err" <<EOF
1675 mhfixmsg: invalid quoted-string in message 31's Content-Type: field
1676 (parameter charset)
1677 mhfixmsg: unable to parse message 31
1678 EOF
1679
1680 cat >`mhpath new` <<EOF
1681 To: recipient@example.com
1682 From: sender@example.com
1683 Subject: mhfixmsg pass through on parse error
1684 MIME-Version: 1.0
1685 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1686
1687 ------- =_aaaaaaaaaa0
1688 Content-Type: text/plain; charset="iso-8859-1
1689 Content-Disposition: attachment; filename="test1.txt"
1690 Content-Transfer-Encoding: quoted-printable
1691
1692 This is the=
1693 text/plain part.
1694
1695 ------- =_aaaaaaaaaa0--
1696 EOF
1697 set +e
1698 run_prog mhfixmsg last -outfile "$actual" 2>"$actual.err"
1699 set -e
1700 #### Expected output is identical to the input message.
1701 check `mhpath last` "$actual" 'keep first'
1702 check "$expected.err" "$actual.err"
1703
1704
1705 # check that input is passed through to output when there's a parse error
1706 # (the charset string is missing its closing quote) with -outfile, and
1707 # input from stdin. Don't check err output, because it contains the name
1708 # of a tmp file. It's similar to that of the previous check.
1709 start_test "that input is passed through to output when there's a parse error"
1710 set +e
1711 run_prog mhfixmsg -file - -outfile - <`mhpath last` >"$actual" 2>/dev/null
1712 set -e
1713 #### Expected output is identical to the input message.
1714 check `mhpath last` "$actual"
1715
1716
1717 # make sure there are no tmp files left over
1718 find "$MH_TEST_DIR/Mail" \( -name 'mhfix*' -o -name ',mhfix*' \) -print \
1719 >"$actual"
1720 cat >"$expected" <<EOF
1721 EOF
1722
1723 check "$expected" "$actual"
1724
1725 finish_test
1726 exit $failed