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