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