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