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