]> diplodocus.org Git - nmh/blob - test/mhfixmsg/test-mhfixmsg
Add basic support for the STLS command in POP
[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"
870 else
871 echo "$0: skipping -textcharset check because nmh was built without iconv"
872 rm -f "$expected"
873 fi
874
875
876 # check -nofixboundary
877 start_test "-nofixboundary"
878 cat >"$expected" <<EOF
879 EOF
880
881 cat >"`mhpath new`" <<EOF
882 Date: Fri, 13 May 2011 08:21:12 -0500
883 Content-Type: multipart/alternative;
884 boundary="----=_NextPart_000_1781A17_01CC1147.81E9467A"
885 Content-Transfer-Encoding: 8bit
886 MIME-Version: 1.0
887 From: <sender@example.com>
888 To: <recipient@example.com>
889 Subject: mhfixmsg bad boundary test
890
891 This is a multi-part message in MIME format.
892
893 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4
894 Content-Type: text/plain
895
896 The boundaries of this part don't match the header boundary.
897
898 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4--
899 EOF
900
901 cp -p "`mhpath last`" "`mhpath new`"
902
903 run_test 'mhfixmsg last -nofixboundary' ''
904 check "$MH_TEST_DIR"/Mail/inbox/18 "$MH_TEST_DIR"/Mail/inbox/19 'keep first'
905
906
907 # check that message is not output when fed through stdin (without -outfile)
908 start_test "message is not output when fed through stdin"
909 run_prog mhfixmsg -file - -verbose <`mhpath last` >"$actual" 2>"$actual.err"
910 check "$expected" "$actual"
911 if grep "mhfixmsg: $MH_TEST_DIR/Mail/.*, fix multipart boundary" \
912 "$actual.err" >/dev/null; then
913 rm -f "$actual.err"
914 else
915 echo "$0: test failed, output is in $actual.err."
916 failed=`expr ${failed:-0} + 1`
917 fi
918
919
920 # check fixup of erroneous boundary in multipart (-fixboundary,
921 # enabled by default)
922 # check -verbose
923 start_test "fixup of erroneous boundary in multipart (-fixboundary, enabled by default)"
924 cat >"$expected" <<EOF
925 Date: Fri, 13 May 2011 08:21:12 -0500
926 Content-Type: multipart/alternative;
927 boundary="----=_NextPart_000_1781A1A_01CC1147.81EBA8D4"
928 Content-Transfer-Encoding: 8bit
929 MIME-Version: 1.0
930 From: <sender@example.com>
931 To: <recipient@example.com>
932 Subject: mhfixmsg bad boundary test
933
934 This is a multi-part message in MIME format.
935
936 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4
937 Content-Type: text/plain
938
939 The boundaries of this part don't match the header boundary.
940
941 ------=_NextPart_000_1781A1A_01CC1147.81EBA8D4--
942 EOF
943
944 run_test 'mhfixmsg last -outfile '"$actual"' -verbose' \
945 "mhfixmsg: 18, fix multipart boundary"
946 check "$expected" "$actual"
947
948
949 # check that message is not modified when -fixboundary fails
950 start_test "message is not modified when -fixboundary fails"
951 cat >"`mhpath new`" <<EOF
952 Date: Fri, 13 May 2011 08:21:12 -0500
953 Content-Type: multipart/alternative;
954 boundary="----=_ NextPart_000_1781A17_01CC1147.81E9467A"
955 Content-Transfer-Encoding: 8bit
956 MIME-Version: 1.0
957 From: <sender@example.com>
958 To: <recipient@example.com>
959 Subject: mhfixmsg bad boundary test
960
961 This is a multi-part message in MIME format.
962
963 ------=_ NextPart_000_1781A1A_01CC1147.81EBA8D4
964 Content-Type: text/plain
965
966 The boundary below doesn't match the header boundary.
967
968 ------=_
969 NextPart_000_1781A1A_01CC1147.81EBA8D4--
970 EOF
971
972 cp -p "`mhpath last`" "$expected"
973 run_test "mhfixmsg last -outfile $actual" ''
974 check "$expected" "$actual"
975
976
977 # check that text/plain part is not added to text/html in multipart/related
978 # when it shouldn't be
979 start_test "text/plain part is not added to text/html in multipart/related when it shouldn't be"
980 cat >"`mhpath new`" <<EOF
981 MIME-Version: 1.0
982 Date: Tue, 26 Feb 2013 18:07:20 -0600
983 Subject: multipart/related, not /alternative
984 Content-Type: multipart/related;
985 type="text/html"; boundary="----=_Part_90310_101292502.1"
986
987 ------=_Part_90310_101292502.1
988 Content-Type: text/html; charset="us-ascii"
989 Content-Transfer-Encoding: 7bit
990
991 <html><head>
992 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
993 <title>HTML Content</title>
994 </head>
995 <body>
996 This is the real content.
997 </body>
998 </html>
999
1000 ------=_Part_90310_101292502.1
1001 Content-Type: text/plain; charset="us-ascii"
1002 Content-Transfer-Encoding: 7bit
1003
1004 Your email client does not support HTML messages
1005
1006 ------=_Part_90310_101292502.1--
1007 EOF
1008
1009 cp -p "`mhpath last`" "$expected"
1010
1011 if [ $can_reformat_texthtml -eq 1 ]; then
1012 #### lynx inserts multiple blank lines, so squeeze them.
1013 run_prog mhfixmsg last -outfile - | squeeze_lines >"$actual"
1014 check "$expected" "$actual" 'ignore space'
1015 else
1016 rm -f "$expected"
1017 fi
1018
1019
1020 # check that text/plain part is added to text/html in multipart/related
1021 # when it should be
1022 start_test "text/plain part is added to text/html in multipart/related when it should be"
1023 cat >"$expected" <<EOF
1024 MIME-Version: 1.0
1025 Date: Tue, 26 Feb 2013 18:07:20 -0600
1026 Subject: multipart/related, not /alternative
1027 Content-Type: multipart/alternative; boundary="----=_Part_90310_101292502.1"
1028
1029 ------=_Part_90310_101292502.1
1030 Content-Type: text/plain; charset="us-ascii"
1031 Content-Transfer-Encoding: 7bit
1032
1033 This is the real content.
1034
1035 ------=_Part_90310_101292502.1
1036 Content-Type: text/html; charset="us-ascii"
1037 Content-Transfer-Encoding: 7bit
1038
1039 <html><head>
1040 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
1041 <title>HTML Content</title>
1042 </head>
1043 <body>
1044 This is the real content.
1045 </body>
1046 </html>
1047
1048 ------=_Part_90310_101292502.1--
1049 EOF
1050
1051 cat >"`mhpath new`" <<EOF
1052 MIME-Version: 1.0
1053 Date: Tue, 26 Feb 2013 18:07:20 -0600
1054 Subject: multipart/related, not /alternative
1055 Content-Type: multipart/related;
1056 type="text/html"; boundary="----=_Part_90310_101292502.1"
1057
1058 ------=_Part_90310_101292502.1
1059 Content-Type: text/html; charset="us-ascii"
1060 Content-Transfer-Encoding: 7bit
1061
1062 <html><head>
1063 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
1064 <title>HTML Content</title>
1065 </head>
1066 <body>
1067 This is the real content.
1068 </body>
1069 </html>
1070
1071 ------=_Part_90310_101292502.1--
1072 EOF
1073
1074 if [ $can_reformat_texthtml -eq 1 ]; then
1075 #### lynx inserts multiple blank lines, so squeeze them.
1076 run_prog mhfixmsg last -outfile - | squeeze_lines >"$actual"
1077 check "$expected" "$actual" 'ignore space'
1078 else
1079 rm -f "$expected"
1080 fi
1081
1082
1083 # check handling of rfc822 message type
1084 # also, checks -fixboundary
1085 start_test "handling of rfc822 message type"
1086 cat >"$expected" <<EOF
1087 From: Test <test@example.com>
1088 To: Some User <user@example.com>
1089 Date: Fri, 29 Sep 2006 00:00:00
1090 Message-Id: @test.nmh
1091 Subject: message with message/rfc822 attachment
1092 MIME-Version: 1.0
1093 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1094
1095 and some garbage before the attachment
1096
1097 ------- =_aaaaaaaaaa0
1098 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
1099 Content-Description: 1552
1100 Content-Disposition: attachment; filename="1552"
1101
1102 From: Test <test@example.com>
1103 To: <another_user@example.com>
1104 Date: Thu, 28 Sep 2006 00:00:00
1105 Message-Id: @test.nmh
1106 Subject: message/rfc822 attachment
1107
1108 This is an RFC-822 message.
1109
1110 ------- =_aaaaaaaaaa0--
1111
1112 and some garbage at the end
1113 EOF
1114
1115 cat >"`mhpath new`" <<EOF
1116 From: Test <test@example.com>
1117 To: Some User <user@example.com>
1118 Date: Fri, 29 Sep 2006 00:00:00
1119 Message-Id: @test.nmh
1120 Subject: message with message/rfc822 attachment
1121 MIME-Version: 1.0
1122 Content-Type: multipart/mixed; boundary="----- =badboundary"
1123
1124 and some garbage before the attachment
1125
1126 ------- =_aaaaaaaaaa0
1127 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
1128 Content-Description: 1552
1129 Content-Disposition: attachment; filename="1552"
1130
1131 From: Test <test@example.com>
1132 To: <another_user@example.com>
1133 Date: Thu, 28 Sep 2006 00:00:00
1134 Message-Id: @test.nmh
1135 Subject: message/rfc822 attachment
1136
1137 This is an RFC-822 message.
1138
1139 ------- =_aaaaaaaaaa0--
1140
1141 and some garbage at the end
1142 EOF
1143
1144 run_test 'mhfixmsg last -outfile '"$actual" ''
1145 check "$expected" "$actual"
1146
1147
1148 # check not stripping of CRs from ASCII text context (default)
1149 start_test "not stripping of CRs from ASCII text context (default)"
1150 cat >"$expected" <<EOF
1151 MIME-Version: 1.0
1152 From: sender@example.com
1153 To: recipient@example.com
1154 Subject: message with CR's
1155 Date: Mon, 29 Apr 2013 11:51:45 -0400
1156
1157 There are two CR-LF pairs at the end of this sentence.
1158
1159 EOF
1160
1161 cat >"`mhpath new`" <<'EOF'
1162 MIME-Version: 1.0
1163 From: sender@example.com
1164 To: recipient@example.com
1165 Subject: message with CR's
1166 Date: Mon, 29 Apr 2013 11:51:45 -0400
1167
1168 There are two CR-LF pairs at the end of this sentence.
1169
1170 EOF
1171
1172 run_prog mhfixmsg last -outfile "$actual"
1173 check "$expected" "$actual"
1174
1175
1176 # check stripping of CRs from ASCII text context
1177 start_test "stripping of CRs from ASCII text context"
1178 cat >"$expected" <<EOF
1179 MIME-Version: 1.0
1180 From: sender@example.com
1181 To: recipient@example.com
1182 Subject: message with CR's
1183 Date: Mon, 29 Apr 2013 11:51:45 -0400
1184
1185 There were two CR-LF pairs at the end of this sentence.
1186
1187 EOF
1188
1189 cat >"`mhpath new`" <<'EOF'
1190 MIME-Version: 1.0
1191 From: sender@example.com
1192 To: recipient@example.com
1193 Subject: message with CR's
1194 Date: Mon, 29 Apr 2013 11:51:45 -0400
1195
1196 There were two CR-LF pairs at the end of this sentence.
1197
1198 EOF
1199
1200 run_prog mhfixmsg last -outfile "$actual" -nocrlflinebreaks
1201 check "$expected" "$actual"
1202
1203
1204 # check -replacetextplain
1205 start_test "-replacetextplain"
1206 prepare_space >"$expected" <<EOF
1207 To: recipient@example.com
1208 From: sender@example.com
1209 Subject: mhfixmsg replacement of bad text/plain part test
1210 MIME-Version: 1.0
1211 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1212
1213 ------=_Part_876302
1214 Content-Type: text/plain; charset="UTF-8"
1215 Content-Transfer-Encoding: 7bit
1216
1217 Yes, the text/plain part really was empty.
1218
1219 ------=_Part_876302
1220 Content-Type: text/html; charset="UTF-8"
1221 Content-Disposition: inline
1222
1223 <html><head>
1224 <title>eticket</title>
1225 </head>
1226 <body>
1227 Yes, the text/plain part really was empty.
1228 </body>
1229 </html>
1230
1231 ------=_Part_876302--
1232 EOF
1233
1234 cat >"`mhpath new`" <<'EOF'
1235 To: recipient@example.com
1236 From: sender@example.com
1237 Subject: mhfixmsg replacement of bad text/plain part test
1238 MIME-Version: 1.0
1239 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1240
1241 ------=_Part_876302
1242 Content-Type: text/plain; charset="iso-8859-15"
1243 Content-Transfer-Encoding: 7bit
1244 Content-Disposition: inline
1245
1246
1247
1248 ------=_Part_876302
1249 Content-Type: text/html; charset="UTF-8"
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 if [ $can_reformat_texthtml -eq 1 ]; then
1264 #### lynx inserts multiple blank lines, so squeeze them.
1265 run_prog mhfixmsg last -replacetextplain -outfile - | \
1266 squeeze_lines > "$actual"
1267 check "$expected" "$actual" 'ignore space'
1268 else
1269 rm -f "$expected"
1270 fi
1271
1272
1273 # check -noreplacetextplain
1274 start_test "-noreplacetextplain"
1275 cat >"$expected" <<EOF
1276 To: recipient@example.com
1277 From: sender@example.com
1278 Subject: mhfixmsg replacement of bad text/plain part test
1279 MIME-Version: 1.0
1280 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1281
1282 ------=_Part_876302
1283 Content-Type: text/plain; charset="iso-8859-15"
1284 Content-Transfer-Encoding: 7bit
1285 Content-Disposition: inline
1286
1287
1288
1289 ------=_Part_876302
1290 Content-Type: text/html; charset="UTF-8"
1291 Content-Disposition: inline
1292
1293 <html><head>
1294 <title>eticket</title>
1295 </head>
1296 <body>
1297 Yes, the text/plain part really was empty.
1298 </body>
1299 </html>
1300
1301 ------=_Part_876302--
1302 EOF
1303
1304 run_prog mhfixmsg last -replacetextplain -noreplacetextplain -outfile "$actual"
1305 check "$expected" "$actual"
1306
1307
1308 # check removal of extraneous trailing semicolon from header parameter list
1309 start_test "removal of extraneous trailing semicolon from header parameter list"
1310 cat >"$expected" <<EOF
1311 To: recipient@example.com
1312 Subject: test
1313 From: sender@example.com
1314 MIME-Version: 1.0
1315 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1316
1317 ------- =_aaaaaaaaaa0
1318 Content-Type: text/plain; charset="us-ascii"
1319
1320 test
1321
1322 ------- =_aaaaaaaaaa0
1323 Content-Type: text/plain; charset="us-ascii";
1324 name="DATE"
1325 Content-Description: check folded headers, with and without trailing semicolon
1326 Content-Disposition: attachment;
1327 filename="DATE"
1328
1329 14 April 2014
1330
1331 ------- =_aaaaaaaaaa0--
1332 EOF
1333
1334 cat >"`mhpath new`" <<EOF
1335 To: recipient@example.com
1336 Subject: test
1337 From: sender@example.com
1338 MIME-Version: 1.0
1339 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1340
1341 ------- =_aaaaaaaaaa0
1342 Content-Type: text/plain; charset="us-ascii";
1343
1344 test
1345
1346 ------- =_aaaaaaaaaa0
1347 Content-Type: text/plain; charset="us-ascii";
1348 name="DATE"
1349 Content-Description: check folded headers, with and without trailing semicolon
1350 Content-Disposition: attachment;
1351 filename="DATE";
1352
1353 14 April 2014
1354
1355 ------- =_aaaaaaaaaa0--
1356 EOF
1357 run_test 'mhfixmsg last -outfile '"$actual" ''
1358 check "$expected" "$actual"
1359
1360
1361 if [ $can_reformat_texthtml -eq 1 ]; then
1362 # check rmmproc
1363 start_test "rmmproc"
1364 cat >"$MH_TEST_DIR/Mail/rmmproc" <<'EOF'
1365 mv "$1" "$1.backup"
1366 EOF
1367 chmod a+x "${MH_TEST_DIR}/Mail/rmmproc"
1368 echo "rmmproc: ${MH_TEST_DIR}/Mail/rmmproc" >>"$MH"
1369 cp "${MH_TEST_DIR}/Mail/inbox/16" "${MH_TEST_DIR}/Mail/inbox/16.original"
1370
1371 run_test 'mhfixmsg 16' ''
1372 check "${MH_TEST_DIR}/Mail/inbox/16.backup" \
1373 "${MH_TEST_DIR}/Mail/inbox/16.original"
1374
1375
1376 # check -normmproc
1377 start_test "-normmproc"
1378 cp "${MH_TEST_DIR}/Mail/inbox/21" "${MH_TEST_DIR}/Mail/inbox/22"
1379
1380 run_test 'mhfixmsg 21 -normmproc'
1381 check "${MH_TEST_DIR}/Mail/inbox/22" \
1382 "${MH_TEST_DIR}/Mail/inbox/${sbackup}21" 'keep first'
1383 fi
1384
1385
1386 # check -rmmproc
1387 start_test "-rmmproc"
1388 run_test 'mhfixmsg 21 -rmmproc true'
1389 if test -f '${MH_TEST_DIR}/Mail/inbox/22.backup'; then
1390 echo check of mhfixmsg -rmmproc FAILED, should not have created backup file
1391 failed=`expr ${failed:-0} + 1`
1392 fi
1393
1394
1395 # check -fixtype
1396 start_test "-fixtype"
1397 cat >"$expected" <<EOF
1398 To: recipient@example.com
1399 From: sender@example.com
1400 Subject: mhfixmsg with incorrect Content-Type
1401 MIME-Version: 1.0
1402 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1403
1404 ------- =_aaaaaaaaaa0
1405 Content-Type: text/plain; name="plaintext.txt"
1406
1407 this is plain text
1408
1409 ------- =_aaaaaaaaaa0--
1410 EOF
1411
1412 cat >"`mhpath new`" <<EOF
1413 To: recipient@example.com
1414 From: sender@example.com
1415 Subject: mhfixmsg with incorrect Content-Type
1416 MIME-Version: 1.0
1417 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1418
1419 ------- =_aaaaaaaaaa0
1420 Content-Type: application/octet-stream; name="plaintext.txt"
1421
1422 this is plain text
1423
1424 ------- =_aaaaaaaaaa0--
1425 EOF
1426
1427 mhfixmsg -fixtype application/octet-stream last
1428 check "$expected" "`mhpath last`"
1429
1430
1431 # check default -decodetypes
1432 start_test "default -decodetypes"
1433 cat >$expected <<EOF
1434 To: recipient@example.com
1435 From: sender@example.com
1436 Subject: mhfixmsg decode test 3
1437 MIME-Version: 1.0
1438 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1439
1440 ------- =_aaaaaaaaaa0
1441 Content-Type: text/plain; charset="iso-8859-1"
1442 Content-Disposition: attachment; filename="test1.txt"
1443 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1444 Content-Transfer-Encoding: 7bit
1445
1446 This is the text/plain part.
1447
1448 ------- =_aaaaaaaaaa0
1449 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
1450 Content-Disposition: attachment; filename="test2.txt"
1451 Content-Transfer-Encoding: 7bit
1452
1453 <html>
1454 <head>
1455 This was the text/html part.
1456 </head>
1457 </body>
1458 </html>
1459
1460 ------- =_aaaaaaaaaa0--
1461 EOF
1462
1463 cat >"`mhpath new`" <<EOF
1464 To: recipient@example.com
1465 From: sender@example.com
1466 Subject: mhfixmsg decode test 3
1467 MIME-Version: 1.0
1468 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1469
1470 ------- =_aaaaaaaaaa0
1471 Content-Type: text/plain; charset="iso-8859-1"
1472 Content-Disposition: attachment; filename="test1.txt"
1473 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1474 Content-Transfer-Encoding: quoted-printable
1475
1476 This is the text/plain part.
1477
1478 ------- =_aaaaaaaaaa0
1479 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
1480 Content-Disposition: attachment; filename="test2.txt"
1481 Content-Transfer-Encoding: base64
1482
1483 PGh0bWw+CjxoZWFkPgogICAgVGhpcyB3YXMgdGhlIHRleHQvaHRtbCBwYXJ0Lgo8L2hlYWQ+Cjwv
1484 Ym9keT4KPC9odG1sPgo=
1485
1486 ------- =_aaaaaaaaaa0--
1487 EOF
1488 run_prog mhfixmsg last -outfile "$actual" -noreformat
1489 check "$expected" "$actual"
1490
1491
1492 # check -decodetypes text/plain
1493 start_test "-decodetypes text/plain"
1494 cat >$expected <<EOF
1495 To: recipient@example.com
1496 From: sender@example.com
1497 Subject: mhfixmsg decode test 4
1498 MIME-Version: 1.0
1499 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1500
1501 ------- =_aaaaaaaaaa0
1502 Content-Type: text/plain; charset="iso-8859-1"
1503 Content-Disposition: attachment; filename="test1.txt"
1504 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1505 Content-Transfer-Encoding: 7bit
1506
1507 This is the text/plain part.
1508
1509 ------- =_aaaaaaaaaa0
1510 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
1511 Content-Disposition: attachment; filename="test2.txt"
1512 Content-Transfer-Encoding: base64
1513
1514 PGh0bWw+DQo8aGVhZD4NCiAgICBUaGlzIGlzIHRoZSB0ZXh0L2h0bWwgcGFydC4NCjwvaGVhZD4N
1515 CjwvYm9keT4NCjwvaHRtbD4NCg==
1516
1517 ------- =_aaaaaaaaaa0--
1518 EOF
1519
1520 cat >"`mhpath new`" <<EOF
1521 To: recipient@example.com
1522 From: sender@example.com
1523 Subject: mhfixmsg decode test 4
1524 MIME-Version: 1.0
1525 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1526
1527 ------- =_aaaaaaaaaa0
1528 Content-Type: text/plain; charset="iso-8859-1"
1529 Content-Disposition: attachment; filename="test1.txt"
1530 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1531 Content-Transfer-Encoding: quoted-printable
1532
1533 This is the text/plain part.
1534
1535 ------- =_aaaaaaaaaa0
1536 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
1537 Content-Disposition: attachment; filename="test2.txt"
1538 Content-Transfer-Encoding: base64
1539
1540 PGh0bWw+DQo8aGVhZD4NCiAgICBUaGlzIGlzIHRoZSB0ZXh0L2h0bWwgcGFydC4NCjwvaGVhZD4N
1541 CjwvYm9keT4NCjwvaHRtbD4NCg==
1542
1543 ------- =_aaaaaaaaaa0--
1544 EOF
1545 run_prog mhfixmsg last -outfile "$actual" -decodetypes text/plain -noreformat
1546 check "$expected" "$actual"
1547
1548
1549 # check -decodetypes attachment/ics
1550 start_test "-decodetypes attachment/ics"
1551 cat >$expected <<EOF
1552 To: recipient@example.com
1553 From: sender@example.com
1554 Subject: mhfixmsg decode test 5
1555 MIME-Version: 1.0
1556 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1557
1558 ------- =_aaaaaaaaaa0
1559 Content-Type: text/plain; charset="iso-8859-1"
1560 Content-Disposition: attachment; filename="test1.txt"
1561 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1562 Content-Transfer-Encoding: 7bit
1563
1564 This is the text/plain part.
1565
1566 ------- =_aaaaaaaaaa0
1567 Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics"
1568 Content-Disposition: attachment; filename="invite.ics"
1569 Content-Transfer-Encoding: 7bit
1570
1571 BEGIN:VCALENDAR
1572 VERSION:2.0
1573 PRODID:test-mhical
1574 BEGIN:VEVENT
1575 DTSTAMP:20150101T162400Z
1576 DTSTART:20150105T160000
1577 DTEND:20150105T163000
1578 SUMMARY:4 pm meeting
1579 END:VEVENT
1580 END:VCALENDAR
1581
1582 ------- =_aaaaaaaaaa0--
1583 EOF
1584
1585 cat >"`mhpath new`" <<EOF
1586 To: recipient@example.com
1587 From: sender@example.com
1588 Subject: mhfixmsg decode test 5
1589 MIME-Version: 1.0
1590 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1591
1592 ------- =_aaaaaaaaaa0
1593 Content-Type: text/plain; charset="iso-8859-1"
1594 Content-Disposition: attachment; filename="test1.txt"
1595 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1596 Content-Transfer-Encoding: quoted-printable
1597
1598 This is the=
1599 text/plain part.
1600
1601 ------- =_aaaaaaaaaa0
1602 Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics"
1603 Content-Disposition: attachment; filename="invite.ics"
1604 Content-Transfer-Encoding: base64
1605
1606 QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KUFJPRElEOnRlc3QtbWhpY2FsDQpCRUdJTjpW
1607 RVZFTlQNCkRUU1RBTVA6MjAxNTAxMDFUMTYyNDAwWg0KRFRTVEFSVDoyMDE1MDEwNVQxNjAwMDAN
1608 CkRURU5EOjIwMTUwMTA1VDE2MzAwMA0KU1VNTUFSWTo0IHBtIG1lZXRpbmcNCkVORDpWRVZFTlQN
1609 CkVORDpWQ0FMRU5EQVINCg==
1610
1611 ------- =_aaaaaaaaaa0--
1612 EOF
1613 run_prog mhfixmsg last -outfile "$actual" -noreformat
1614 check "$expected" "$actual"
1615
1616
1617 # check -decodetypes attachment/ics and -nocrlflinebreaks
1618 start_test "-decodetypes attachment/ics and -nocrlflinebreaks"
1619 cat >$expected <<EOF
1620 To: recipient@example.com
1621 From: sender@example.com
1622 Subject: mhfixmsg decode test 5
1623 MIME-Version: 1.0
1624 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1625
1626 ------- =_aaaaaaaaaa0
1627 Content-Type: text/plain; charset="iso-8859-1"
1628 Content-Disposition: attachment; filename="test1.txt"
1629 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1630 Content-Transfer-Encoding: 7bit
1631
1632 This is the text/plain part.
1633
1634 ------- =_aaaaaaaaaa0
1635 Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics"
1636 Content-Disposition: attachment; filename="invite.ics"
1637 Content-Transfer-Encoding: 7bit
1638
1639 BEGIN:VCALENDAR
1640 VERSION:2.0
1641 PRODID:test-mhical
1642 BEGIN:VEVENT
1643 DTSTAMP:20150101T162400Z
1644 DTSTART:20150105T160000
1645 DTEND:20150105T163000
1646 SUMMARY:4 pm meeting
1647 END:VEVENT
1648 END:VCALENDAR
1649
1650 ------- =_aaaaaaaaaa0--
1651 EOF
1652
1653 cat >"`mhpath new`" <<EOF
1654 To: recipient@example.com
1655 From: sender@example.com
1656 Subject: mhfixmsg decode test 5
1657 MIME-Version: 1.0
1658 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1659
1660 ------- =_aaaaaaaaaa0
1661 Content-Type: text/plain; charset="iso-8859-1"
1662 Content-Disposition: attachment; filename="test1.txt"
1663 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1664 Content-Transfer-Encoding: quoted-printable
1665
1666 This is the=
1667 text/plain part.
1668
1669 ------- =_aaaaaaaaaa0
1670 Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics"
1671 Content-Disposition: attachment; filename="invite.ics"
1672 Content-Transfer-Encoding: base64
1673
1674 QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KUFJPRElEOnRlc3QtbWhpY2FsDQpCRUdJTjpW
1675 RVZFTlQNCkRUU1RBTVA6MjAxNTAxMDFUMTYyNDAwWg0KRFRTVEFSVDoyMDE1MDEwNVQxNjAwMDAN
1676 CkRURU5EOjIwMTUwMTA1VDE2MzAwMA0KU1VNTUFSWTo0IHBtIG1lZXRpbmcNCkVORDpWRVZFTlQN
1677 CkVORDpWQ0FMRU5EQVINCg==
1678
1679 ------- =_aaaaaaaaaa0--
1680 EOF
1681 run_prog mhfixmsg last -outfile "$actual" -nocrlflinebreaks -noreformat
1682 check "$expected" "$actual"
1683
1684
1685 # check that input is passed through to output when there's a parse error
1686 # (the charset string is missing its closing quote) with -outfile
1687 start_test "input is passed through to output when there's a parse error"
1688 cat >"$expected.err" <<EOF
1689 mhfixmsg: invalid quoted-string in message 31's Content-Type: field
1690 (parameter charset)
1691 mhfixmsg: unable to parse message 31
1692 EOF
1693
1694 cat >"`mhpath new`" <<EOF
1695 To: recipient@example.com
1696 From: sender@example.com
1697 Subject: mhfixmsg pass through on parse error
1698 MIME-Version: 1.0
1699 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1700
1701 ------- =_aaaaaaaaaa0
1702 Content-Type: text/plain; charset="iso-8859-1
1703 Content-Disposition: attachment; filename="test1.txt"
1704 Content-Transfer-Encoding: quoted-printable
1705
1706 This is the=
1707 text/plain part.
1708
1709 ------- =_aaaaaaaaaa0--
1710 EOF
1711 set +e
1712 run_prog mhfixmsg last -outfile "$actual" 2>"$actual.err"
1713 set -e
1714 #### Expected output is identical to the input message.
1715 check "`mhpath last`" "$actual" 'keep first'
1716 check "$expected.err" "$actual.err"
1717
1718
1719 # check that input is passed through to output when there's a parse error
1720 # (the charset string is missing its closing quote) with -outfile, and
1721 # input from stdin. Don't check err output, because it contains the name
1722 # of a tmp file. It's similar to that of the previous check.
1723 start_test "input is passed through to output when there's a parse error"
1724 set +e
1725 run_prog mhfixmsg -file - -outfile - <`mhpath last` >"$actual" 2>/dev/null
1726 set -e
1727 #### Expected output is identical to the input message.
1728 check "`mhpath last`" "$actual" 'keep first'
1729
1730
1731 start_test "pass through message with relative folder path with parse error"
1732 #### Factor out leading portion of current folder path and make it relative.
1733 pwd=`pwd -P`
1734 set +e
1735 run_prog mhfixmsg +./`mhpath | sed "s%^$pwd/%%"` last -out - >"$actual" 2>/dev/null
1736 set -e
1737 folder -f +inbox >/dev/null
1738 #### Expected output is identical to the input message.
1739 check "`mhpath last`" "$actual"
1740
1741
1742 start_test "fix RFC 2047 encoded header parameters"
1743 #### Also, add C-T-E:8bit to the message headers.
1744 cat >"$expected" <<EOF
1745 To: recipient@example.com
1746 From: sender@example.com
1747 Date: Wed, 28 Sep 2016 11:24:28 -0400
1748 Subject: invalid header parameter encoding
1749 MIME-Version: 1.0
1750 Content-Type: multipart/mixed; boundary=001a114dd3e8fe9c56053d92f414
1751 Content-Transfer-Encoding: 8bit
1752
1753 --001a114dd3e8fe9c56053d92f414
1754 Content-Type: text/plain; charset=UTF-8
1755
1756 This is a test.
1757
1758 --001a114dd3e8fe9c56053d92f414
1759 Content-Type: text/plain; charset="UTF-8"; name*=UTF-8''test%C3%B8.txt
1760 Content-Disposition: attachment; filename*=UTF-8''test%C3%B8.txt
1761 Content-Transfer-Encoding: 8bit
1762
1763 This is the first text/plain part, in a subpart. The file name
1764 is testรธ.txt.
1765
1766 --001a114dd3e8fe9c56053d92f414--
1767 EOF
1768
1769 cat >"`mhpath new`" <<EOF
1770 To: recipient@example.com
1771 From: sender@example.com
1772 Date: Wed, 28 Sep 2016 11:24:28 -0400
1773 Subject: invalid header parameter encoding
1774 MIME-Version: 1.0
1775 Content-Type: multipart/mixed; boundary=001a114dd3e8fe9c56053d92f414
1776
1777 --001a114dd3e8fe9c56053d92f414
1778 Content-Type: text/plain; charset=UTF-8
1779
1780 This is a test.
1781
1782 --001a114dd3e8fe9c56053d92f414
1783 Content-Type: text/plain; charset=UTF-8; name="=?UTF-8?B?dGVzdMO4LnR4dA==?="
1784 Content-Disposition: attachment; filename="=?UTF-8?B?dGVzdMO4LnR4dA==?="
1785 Content-Transfer-Encoding: 8bit
1786
1787 This is the first text/plain part, in a subpart. The file name
1788 is testรธ.txt.
1789
1790 --001a114dd3e8fe9c56053d92f414--
1791 EOF
1792 run_prog mhfixmsg -file - -outfile - <`mhpath last` >"$actual" 2>/dev/null
1793 check "$expected" "$actual"
1794
1795
1796 start_test "-nodecodeheaderfieldbodies"
1797 cat >"`mhpath new`" <<EOF
1798 To: recipient@example.com
1799 From: sender@example.com
1800 Date: Wed, 28 Sep 2016 11:24:28 -0400
1801 Subject: =?utf-8?B?dGhpcyBTdWJqZWN0IHdhcyBVVEYtOCBlbmNvZGVk?=
1802 MIME-Version: 1.0
1803 Content-Type: multipart/mixed; boundary=001a114dd3e8fe9c56053d92f414
1804 Content-Transfer-Encoding: 8bit
1805
1806 --001a114dd3e8fe9c56053d92f414
1807 Content-Type: text/plain; charset=UTF-8
1808
1809 This is a test.
1810
1811 --001a114dd3e8fe9c56053d92f414
1812 Content-Type: text/plain; charset=UTF-8; name="test.txt"
1813 Content-Disposition: attachment; filename="test.txt"
1814 Content-Transfer-Encoding: 8bit
1815
1816 This is the first text/plain part, in a subpart. The file name
1817 is test.txt.
1818
1819 --001a114dd3e8fe9c56053d92f414--
1820 EOF
1821 run_prog mhfixmsg -file - -outfile - -decodeheaderfieldbodies utf-8 \
1822 -nodecodeheaderfieldbodies <`mhpath last` >"$actual" 2>/dev/null
1823 check `mhpath last` "$actual" 'keep first'
1824
1825
1826 start_test "test decoding of UTF-8 header value"
1827 cat >"$expected" <<EOF
1828 To: recipient@example.com
1829 From: sender@example.com
1830 Date: Wed, 28 Sep 2016 11:24:28 -0400
1831 Subject: this Subject was UTF-8 encoded
1832 MIME-Version: 1.0
1833 Content-Type: multipart/mixed; boundary=001a114dd3e8fe9c56053d92f414
1834 Content-Transfer-Encoding: 8bit
1835
1836 --001a114dd3e8fe9c56053d92f414
1837 Content-Type: text/plain; charset=UTF-8
1838
1839 This is a test.
1840
1841 --001a114dd3e8fe9c56053d92f414
1842 Content-Type: text/plain; charset=UTF-8; name="test.txt"
1843 Content-Disposition: attachment; filename="test.txt"
1844 Content-Transfer-Encoding: 8bit
1845
1846 This is the first text/plain part, in a subpart. The file name
1847 is test.txt.
1848
1849 --001a114dd3e8fe9c56053d92f414--
1850 EOF
1851
1852 run_prog mhfixmsg -file - -outfile - -decodeheaderfieldbodies utf-8 \
1853 <`mhpath last` >"$actual" 2>/dev/null
1854 check "$expected" "$actual"
1855
1856
1857 start_test "-checkbase64 with base64 code that ends with == plus footer"
1858 cat >"`mhpath new`" <<EOF
1859 From: Test <test@example.com>
1860 Subject: base64 code that ends with ==
1861 MIME-Version: 1.0
1862 Content-Type: text/plain
1863 Content-Transfer-Encoding: base64
1864
1865 VGhpcyBpcyBzb21lIHRleHQuCg==
1866
1867 --
1868 Wait, this shouldn't be here.
1869 EOF
1870
1871 cat >"$expected" <<EOF
1872 From: Test <test@example.com>
1873 Subject: base64 code that ends with ==
1874 MIME-Version: 1.0
1875 Content-Type: multipart/mixed; boundary="----=_nmh-multipart"
1876
1877 ------=_nmh-multipart
1878 Content-Type: text/plain
1879 Content-Transfer-Encoding: 7bit
1880
1881 This is some text.
1882
1883 ------=_nmh-multipart
1884 Content-Type: text/plain
1885 Content-Transfer-Encoding: 7bit
1886
1887 --
1888 Wait, this shouldn't be here.
1889
1890 ------=_nmh-multipart--
1891 EOF
1892 run_prog mhfixmsg last -outfile "$actual"
1893 check "$expected" "$actual"
1894
1895
1896 start_test "-checkbase64 with -nodecodetext"
1897 cat >"`mhpath new`" <<EOF
1898 From: Test <test@example.com>
1899 Subject: base64 code that ends with ==
1900 MIME-Version: 1.0
1901 Content-Type: text/plain
1902 Content-Transfer-Encoding: base64
1903
1904 VGhpcyBpcyBzb21lIHRleHQuCg==
1905
1906 --
1907 Wait, this shouldn't be here.
1908 EOF
1909
1910 cat >"$expected" <<EOF
1911 From: Test <test@example.com>
1912 Subject: base64 code that ends with ==
1913 MIME-Version: 1.0
1914 Content-Type: multipart/mixed; boundary="----=_nmh-multipart"
1915
1916 ------=_nmh-multipart
1917 Content-Type: text/plain
1918 Content-Transfer-Encoding: base64
1919
1920 VGhpcyBpcyBzb21lIHRleHQuCg==
1921
1922 ------=_nmh-multipart
1923 Content-Type: text/plain
1924 Content-Transfer-Encoding: 7bit
1925
1926 --
1927 Wait, this shouldn't be here.
1928
1929 ------=_nmh-multipart--
1930 EOF
1931 run_prog mhfixmsg -nodecodetext last -outfile "$actual"
1932 check "$expected" "$actual"
1933
1934
1935 start_test "-checkbase64 with base64 code that ends with = plus footer"
1936 cat >"`mhpath new`" <<EOF
1937 From: Test <test@example.com>
1938 Subject: base64 code that ends with =
1939 MIME-Version: 1.0
1940 Content-Type: text/plain
1941 Content-Transfer-Encoding: base64
1942
1943 VGhpcyBpcyBwbGFpbiB0ZXh0Lgo=
1944
1945 --
1946 Wait, this shouldn't be here.
1947 EOF
1948
1949 cat >"$expected" <<EOF
1950 From: Test <test@example.com>
1951 Subject: base64 code that ends with =
1952 MIME-Version: 1.0
1953 Content-Type: multipart/mixed; boundary="----=_nmh-multipart"
1954
1955 ------=_nmh-multipart
1956 Content-Type: text/plain
1957 Content-Transfer-Encoding: 7bit
1958
1959 This is plain text.
1960
1961 ------=_nmh-multipart
1962 Content-Type: text/plain
1963 Content-Transfer-Encoding: 7bit
1964
1965 --
1966 Wait, this shouldn't be here.
1967
1968 ------=_nmh-multipart--
1969 EOF
1970 run_prog mhfixmsg last -outfile "$actual"
1971 check "$expected" "$actual"
1972
1973
1974 start_test "-checkbase64 with base64 code that ends without = plus footer"
1975 cat >"`mhpath new`" <<EOF
1976 From: Test <test@example.com>
1977 Subject: base64 code that ends without =
1978 MIME-Version: 1.0
1979 Content-Type: text/plain
1980 Content-Transfer-Encoding: base64
1981
1982 VGhpcyBpcyBzb21lIHRleHQK
1983
1984 --
1985 Wait, this shouldn't be here.
1986 EOF
1987
1988 cat >"$expected" <<EOF
1989 From: Test <test@example.com>
1990 Subject: base64 code that ends without =
1991 MIME-Version: 1.0
1992 Content-Type: multipart/mixed; boundary="----=_nmh-multipart"
1993
1994 ------=_nmh-multipart
1995 Content-Type: text/plain
1996 Content-Transfer-Encoding: 7bit
1997
1998 This is some text
1999
2000 ------=_nmh-multipart
2001 Content-Type: text/plain
2002 Content-Transfer-Encoding: 7bit
2003
2004 --
2005 Wait, this shouldn't be here.
2006
2007 ------=_nmh-multipart--
2008 EOF
2009 run_prog mhfixmsg last -outfile "$actual"
2010 check "$expected" "$actual"
2011
2012
2013 start_test "-checkbase64 with base64 code that contains single invalid character"
2014 cat >"`mhpath new`" <<EOF
2015 From: Test <test@example.com>
2016 Subject: base64 code that ends without =
2017 MIME-Version: 1.0
2018 Content-Type: text/plain
2019 Content-Transfer-Encoding: base64
2020
2021 VGhpcyBpcyBzb21lIHRleHQK
2022
2023 -X-
2024 Wait, this shouldn't be here.
2025 EOF
2026
2027 cat >"$expected" <<EOF
2028 From: Test <test@example.com>
2029 Subject: base64 code that ends without =
2030 MIME-Version: 1.0
2031 Content-Type: text/plain
2032 Content-Transfer-Encoding: base64
2033
2034 VGhpcyBpcyBzb21lIHRleHQK
2035
2036 -X-
2037 Wait, this shouldn't be here.
2038 EOF
2039
2040 cat >"$expected_err" <<EOF
2041 mhfixmsg: invalid base64 byte 0x2d: -X-
2042 Wait, this shouldn't be here.
2043
2044 EOF
2045
2046 run_prog mhfixmsg last -outfile "$actual" 2>"$actual_err" || true
2047 check "$expected" "$actual"
2048 check "$expected_err" "$actual_err"
2049
2050
2051 start_test "-checkbase64 with base64 code in MIME part"
2052 cat >"`mhpath new`" <<EOF
2053 From: Test <test@example.com>
2054 Subject: MIME part with base64 encoded text and unencoded footer
2055 MIME-Version: 1.0
2056 Content-Type: multipart/mixed; boundary="----=_nmh-multipart"
2057
2058 ------=_nmh-multipart
2059 Content-Type: text/plain
2060 Content-Transfer-Encoding: base64
2061
2062 VGhpcyBpcyBzb21lIHRleHQK
2063
2064 --
2065 Wait, this shouldn't be here.
2066
2067 ------=_nmh-multipart
2068 Content-Type: text/plain
2069 Content-Transfer-Encoding: 7bit
2070
2071 This is a second text/plain part.
2072
2073 ------=_nmh-multipart--
2074 EOF
2075
2076 cat >"$expected" <<EOF
2077 From: Test <test@example.com>
2078 Subject: MIME part with base64 encoded text and unencoded footer
2079 MIME-Version: 1.0
2080 Content-Type: multipart/mixed; boundary="----=_nmh-multipart"
2081
2082 ------=_nmh-multipart
2083 Content-Type: multipart/mixed; boundary="----=_nmh-multipart1"
2084
2085 ------=_nmh-multipart1
2086 Content-Type: text/plain
2087 Content-Transfer-Encoding: 7bit
2088
2089 This is some text
2090
2091 ------=_nmh-multipart1
2092 Content-Type: text/plain
2093 Content-Transfer-Encoding: 7bit
2094
2095 --
2096 Wait, this shouldn't be here.
2097
2098 ------=_nmh-multipart1--
2099
2100 ------=_nmh-multipart
2101 Content-Type: text/plain
2102 Content-Transfer-Encoding: 7bit
2103
2104 This is a second text/plain part.
2105
2106 ------=_nmh-multipart--
2107 EOF
2108 run_prog mhfixmsg last -outfile "$actual"
2109 check "$expected" "$actual"
2110
2111
2112 start_test "-checkbase64 with 8-bit encoded base64 code"
2113 cat >"`mhpath new`" <<EOF
2114 From: Test <test@example.com>
2115 Subject: 8-bit encoded base64 code
2116 MIME-Version: 1.0
2117 Content-Type: text/plain
2118 Content-Transfer-Encoding: base64
2119
2120 U2VlIFJGQyAyMDQ1IMKnNi44Lg==
2121
2122 --
2123 Wait, this shouldn't be here.
2124 EOF
2125 cat >"$expected" <<EOF
2126 From: Test <test@example.com>
2127 Subject: 8-bit encoded base64 code
2128 MIME-Version: 1.0
2129 Content-Type: multipart/mixed; boundary="----=_nmh-multipart"
2130 Content-Transfer-Encoding: 8bit
2131
2132 ------=_nmh-multipart
2133 Content-Type: text/plain
2134 Content-Transfer-Encoding: 8bit
2135
2136 See RFC 2045 ยง6.8.
2137
2138 ------=_nmh-multipart
2139 Content-Type: text/plain
2140 Content-Transfer-Encoding: 7bit
2141
2142 --
2143 Wait, this shouldn't be here.
2144
2145 ------=_nmh-multipart--
2146 EOF
2147
2148 run_prog mhfixmsg last -outfile "$actual"
2149 check "$expected" "$actual"
2150
2151
2152 # make sure there are no tmp files left over
2153 find "$MH_TEST_DIR/Mail" -name '*mhfix*' -print \
2154 >"$actual"
2155 cat >"$expected" <<EOF
2156 EOF
2157
2158 check "$expected" "$actual"
2159
2160
2161 finish_test
2162 exit $failed