]> diplodocus.org Git - nmh/blob - test/mhfixmsg/test-mhfixmsg
Added oauth support to whatnow.
[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 text/plain part is not added to text/html in multipart/related
891 # when it shouldn't be
892 cat >`mhpath new` <<EOF
893 MIME-Version: 1.0
894 Date: Tue, 26 Feb 2013 18:07:20 -0600
895 Subject: multipart/related, not /alternative
896 Content-Type: multipart/related;
897 type="text/html"; boundary="----=_Part_90310_101292502.1"
898
899 ------=_Part_90310_101292502.1
900 Content-Type: text/html; charset="us-ascii"
901 Content-Transfer-Encoding: 7bit
902
903 <html><head>
904 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
905 <title>HTML Content</title>
906 </head>
907 <body>
908 This is the real content.
909 </body>
910 </html>
911
912 ------=_Part_90310_101292502.1
913 Content-Type: text/plain; charset="us-ascii"
914 Content-Transfer-Encoding: 7bit
915
916 Your email client does not support HTML messages
917
918 ------=_Part_90310_101292502.1--
919 EOF
920
921 cp -p `mhpath last` "$expected"
922
923 if [ $can_reformat_texthtml -eq 1 ]; then
924 #### lynx inserts multiple blank lines, so squeeze them.
925 run_prog mhfixmsg last -outfile - | squeeze_lines >"$actual"
926 check "$expected" "$actual" 'ignore space'
927 else
928 rm -f "$expected"
929 fi
930
931
932 # check that text/plain part is added to text/html in multipart/related
933 # when it should be
934 cat >"$expected" <<EOF
935 MIME-Version: 1.0
936 Date: Tue, 26 Feb 2013 18:07:20 -0600
937 Subject: multipart/related, not /alternative
938 Content-Type: multipart/alternative; boundary="----=_Part_90310_101292502.1"
939
940 ------=_Part_90310_101292502.1
941 Content-Type: text/plain; charset="us-ascii"
942 Content-Transfer-Encoding: 7bit
943
944 This is the real content.
945
946 ------=_Part_90310_101292502.1
947 Content-Type: text/html; charset="us-ascii"
948 Content-Transfer-Encoding: 7bit
949
950 <html><head>
951 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
952 <title>HTML Content</title>
953 </head>
954 <body>
955 This is the real content.
956 </body>
957 </html>
958
959 ------=_Part_90310_101292502.1--
960 EOF
961
962 cat >`mhpath new` <<EOF
963 MIME-Version: 1.0
964 Date: Tue, 26 Feb 2013 18:07:20 -0600
965 Subject: multipart/related, not /alternative
966 Content-Type: multipart/related;
967 type="text/html"; boundary="----=_Part_90310_101292502.1"
968
969 ------=_Part_90310_101292502.1
970 Content-Type: text/html; charset="us-ascii"
971 Content-Transfer-Encoding: 7bit
972
973 <html><head>
974 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
975 <title>HTML Content</title>
976 </head>
977 <body>
978 This is the real content.
979 </body>
980 </html>
981
982 ------=_Part_90310_101292502.1--
983 EOF
984
985 if [ $can_reformat_texthtml -eq 1 ]; then
986 #### lynx inserts multiple blank lines, so squeeze them.
987 run_prog mhfixmsg last -outfile - | squeeze_lines >"$actual"
988 check "$expected" "$actual" 'ignore space'
989 else
990 rm -f "$expected"
991 fi
992
993
994 # check handling of rfc822 message type
995 cat >"$expected" <<EOF
996 From: Test <test@example.com>
997 To: Some User <user@example.com>
998 Date: Fri, 29 Sep 2006 00:00:00
999 Message-Id: @test.nmh
1000 Subject: message with message/rfc822 attachment
1001 MIME-Version: 1.0
1002 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1003
1004 and some garbage before the attachment
1005
1006 ------- =_aaaaaaaaaa0
1007 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
1008 Content-Description: 1552
1009 Content-Disposition: attachment; filename="1552"
1010
1011 From: Test <test@example.com>
1012 To: <another_user@example.com>
1013 Date: Thu, 28 Sep 2006 00:00:00
1014 Message-Id: @test.nmh
1015 Subject: message/rfc822 attachment
1016
1017 This is an RFC-822 message.
1018
1019 ------- =_aaaaaaaaaa0--
1020
1021 and some garbage at the end
1022 EOF
1023
1024 cat >`mhpath new` <<EOF
1025 From: Test <test@example.com>
1026 To: Some User <user@example.com>
1027 Date: Fri, 29 Sep 2006 00:00:00
1028 Message-Id: @test.nmh
1029 Subject: message with message/rfc822 attachment
1030 MIME-Version: 1.0
1031 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaa0"
1032
1033 and some garbage before the attachment
1034
1035 ------- =_aaaaaaaaaa0
1036 Content-Type: message/rfc822; name="1552"; charset="us-ascii"
1037 Content-Description: 1552
1038 Content-Disposition: attachment; filename="1552"
1039
1040 From: Test <test@example.com>
1041 To: <another_user@example.com>
1042 Date: Thu, 28 Sep 2006 00:00:00
1043 Message-Id: @test.nmh
1044 Subject: message/rfc822 attachment
1045
1046 This is an RFC-822 message.
1047
1048 ------- =_aaaaaaaaaa0--
1049
1050 and some garbage at the end
1051 EOF
1052
1053 run_test 'mhfixmsg last -outfile '"$actual" ''
1054 check "$expected" "$actual"
1055
1056
1057 # check not stripping of CRs from ASCII text context (default)
1058 cat >"$expected" <<EOF
1059 MIME-Version: 1.0
1060 From: sender@example.com
1061 To: recipient@example.com
1062 Subject: message with CR's
1063 Date: Mon, 29 Apr 2013 11:51:45 -0400
1064
1065 There are two CR-LF pairs at the end of this sentence.
1066
1067 EOF
1068
1069 cat >`mhpath new` <<'EOF'
1070 MIME-Version: 1.0
1071 From: sender@example.com
1072 To: recipient@example.com
1073 Subject: message with CR's
1074 Date: Mon, 29 Apr 2013 11:51:45 -0400
1075
1076 There are two CR-LF pairs at the end of this sentence.
1077
1078 EOF
1079
1080 run_prog mhfixmsg last -outfile "$actual"
1081 check "$expected" "$actual"
1082
1083
1084 # check stripping of CRs from ASCII text context
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 were 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 were two CR-LF pairs at the end of this sentence.
1104
1105 EOF
1106
1107 run_prog mhfixmsg last -outfile "$actual" -nocrlflinebreaks
1108 check "$expected" "$actual"
1109
1110
1111 # check -replacetextplain
1112 prepare_space >"$expected" <<EOF
1113 To: recipient@example.com
1114 From: sender@example.com
1115 Subject: mhfixmsg replacement of bad text/plain part test
1116 MIME-Version: 1.0
1117 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1118
1119 ------=_Part_876302
1120 Content-Type: text/plain; charset="UTF-8"
1121 Content-Transfer-Encoding: 8bit
1122
1123 Yes, the text/plain part really was empty.
1124
1125 ------=_Part_876302
1126 Content-Type: text/html; charset="UTF-8"
1127 Content-Transfer-Encoding: 8bit
1128 Content-Disposition: inline
1129
1130 <html><head>
1131 <title>eticket</title>
1132 </head>
1133 <body>
1134 Yes, the text/plain part really was empty.
1135 </body>
1136 </html>
1137
1138 ------=_Part_876302--
1139 EOF
1140
1141 cat >`mhpath new` <<'EOF'
1142 To: recipient@example.com
1143 From: sender@example.com
1144 Subject: mhfixmsg replacement of bad text/plain part test
1145 MIME-Version: 1.0
1146 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1147
1148 ------=_Part_876302
1149 Content-Type: text/plain; charset="iso-8859-15"
1150 Content-Transfer-Encoding: 7bit
1151 Content-Disposition: inline
1152
1153
1154
1155 ------=_Part_876302
1156 Content-Type: text/html; charset="UTF-8"
1157 Content-Transfer-Encoding: 8bit
1158 Content-Disposition: inline
1159
1160 <html><head>
1161 <title>eticket</title>
1162 </head>
1163 <body>
1164 Yes, the text/plain part really was empty.
1165 </body>
1166 </html>
1167
1168 ------=_Part_876302--
1169 EOF
1170
1171 if [ $can_reformat_texthtml -eq 1 ]; then
1172 #### lynx inserts multiple blank lines, so squeeze them.
1173 run_prog mhfixmsg last -replacetextplain -outfile - | \
1174 squeeze_lines > "$actual"
1175 check "$expected" "$actual" 'ignore space'
1176 else
1177 rm -f "$expected"
1178 fi
1179
1180
1181 # check -noreplacetextplain
1182 cat >"$expected" <<EOF
1183 To: recipient@example.com
1184 From: sender@example.com
1185 Subject: mhfixmsg replacement of bad text/plain part test
1186 MIME-Version: 1.0
1187 Content-Type: multipart/alternative; boundary="----=_Part_876302"
1188
1189 ------=_Part_876302
1190 Content-Type: text/plain; charset="iso-8859-15"
1191 Content-Transfer-Encoding: 7bit
1192 Content-Disposition: inline
1193
1194
1195
1196 ------=_Part_876302
1197 Content-Type: text/html; charset="UTF-8"
1198 Content-Transfer-Encoding: 8bit
1199 Content-Disposition: inline
1200
1201 <html><head>
1202 <title>eticket</title>
1203 </head>
1204 <body>
1205 Yes, the text/plain part really was empty.
1206 </body>
1207 </html>
1208
1209 ------=_Part_876302--
1210 EOF
1211
1212 run_prog mhfixmsg last -replacetextplain -noreplacetextplain -outfile "$actual"
1213 check "$expected" "$actual"
1214
1215
1216 # check removal of extraneous trailing semicolon from header parameter list
1217 cat >"$expected" <<EOF
1218 To: recipient@example.com
1219 Subject: test
1220 From: sender@example.com
1221 MIME-Version: 1.0
1222 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1223
1224 ------- =_aaaaaaaaaa0
1225 Content-Type: text/plain; charset="us-ascii"
1226
1227 test
1228
1229 ------- =_aaaaaaaaaa0
1230 Content-Type: text/plain; charset="us-ascii";
1231 name="DATE"
1232 Content-Description: check folded headers, with and without trailing semicolon
1233 Content-Disposition: attachment;
1234 filename="DATE"
1235
1236 14 April 2014
1237
1238 ------- =_aaaaaaaaaa0--
1239 EOF
1240
1241 cat >`mhpath new` <<EOF
1242 To: recipient@example.com
1243 Subject: test
1244 From: sender@example.com
1245 MIME-Version: 1.0
1246 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1247
1248 ------- =_aaaaaaaaaa0
1249 Content-Type: text/plain; charset="us-ascii";
1250
1251 test
1252
1253 ------- =_aaaaaaaaaa0
1254 Content-Type: text/plain; charset="us-ascii";
1255 name="DATE"
1256 Content-Description: check folded headers, with and without trailing semicolon
1257 Content-Disposition: attachment;
1258 filename="DATE";
1259
1260 14 April 2014
1261
1262 ------- =_aaaaaaaaaa0--
1263 EOF
1264 run_test 'mhfixmsg last -outfile '"$actual" ''
1265 check "$expected" "$actual"
1266
1267
1268 # check rmmproc
1269 cat >"$MH_TEST_DIR/Mail/rmmproc" <<'EOF'
1270 mv "$1" "$1.backup"
1271 EOF
1272 chmod a+x "${MH_TEST_DIR}/Mail/rmmproc"
1273 echo "rmmproc: ${MH_TEST_DIR}/Mail/rmmproc" >>"$MH"
1274 cp "${MH_TEST_DIR}/Mail/inbox/15" "${MH_TEST_DIR}/Mail/inbox/15.original"
1275
1276 run_test 'mhfixmsg 15' ''
1277 check "${MH_TEST_DIR}/Mail/inbox/15.backup" \
1278 "${MH_TEST_DIR}/Mail/inbox/15.original"
1279
1280
1281 # check -normmproc
1282 cp "${MH_TEST_DIR}/Mail/inbox/19" "${MH_TEST_DIR}/Mail/inbox/20"
1283
1284 run_test 'mhfixmsg 19 -normmproc'
1285 check "${MH_TEST_DIR}/Mail/inbox/20" \
1286 "${MH_TEST_DIR}/Mail/inbox/,19" 'keep first'
1287
1288
1289 # check -rmmproc
1290 run_test 'mhfixmsg 20 -rmmproc true'
1291 if test -f '${MH_TEST_DIR}/Mail/inbox/20.backup'; then
1292 echo check of mhfixmsg -rmmproc FAILED, should not have created backup file
1293 failed=`expr ${failed:-0} + 1`
1294 fi
1295
1296
1297 # check -fixtype
1298 cat >"$expected" <<EOF
1299 To: recipient@example.com
1300 From: sender@example.com
1301 Subject: mhfixmsg with incorrect Content-Type
1302 MIME-Version: 1.0
1303 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1304
1305 ------- =_aaaaaaaaaa0
1306 Content-Type: text/plain; name="plaintext.txt"
1307
1308 this is plain text
1309
1310 ------- =_aaaaaaaaaa0--
1311 EOF
1312
1313 cat >`mhpath new` <<EOF
1314 To: recipient@example.com
1315 From: sender@example.com
1316 Subject: mhfixmsg with incorrect Content-Type
1317 MIME-Version: 1.0
1318 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1319
1320 ------- =_aaaaaaaaaa0
1321 Content-Type: application/octet-stream; name="plaintext.txt"
1322
1323 this is plain text
1324
1325 ------- =_aaaaaaaaaa0--
1326 EOF
1327
1328 mhfixmsg -fixtype application/octet-stream last
1329 check "$expected" `mhpath last`
1330
1331
1332 # check default -decodetypes
1333 cat >$expected <<EOF
1334 To: recipient@example.com
1335 From: sender@example.com
1336 Subject: mhfixmsg decode test 3
1337 MIME-Version: 1.0
1338 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1339
1340 ------- =_aaaaaaaaaa0
1341 Content-Type: text/plain; charset="iso-8859-1"
1342 Content-Disposition: attachment; filename="test1.txt"
1343 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1344 Content-Transfer-Encoding: 8bit
1345
1346 This is the text/plain part.
1347
1348 ------- =_aaaaaaaaaa0
1349 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
1350 Content-Disposition: attachment; filename="test2.txt"
1351 Content-Transfer-Encoding: 8bit
1352
1353 <html>
1354 <head>
1355 This was the text/html part.
1356 </head>
1357 </body>
1358 </html>
1359
1360 ------- =_aaaaaaaaaa0--
1361 EOF
1362
1363 cat >`mhpath new` <<EOF
1364 To: recipient@example.com
1365 From: sender@example.com
1366 Subject: mhfixmsg decode test 3
1367 MIME-Version: 1.0
1368 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1369
1370 ------- =_aaaaaaaaaa0
1371 Content-Type: text/plain; charset="iso-8859-1"
1372 Content-Disposition: attachment; filename="test1.txt"
1373 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1374 Content-Transfer-Encoding: quoted-printable
1375
1376 This is the text/plain part.
1377
1378 ------- =_aaaaaaaaaa0
1379 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
1380 Content-Disposition: attachment; filename="test2.txt"
1381 Content-Transfer-Encoding: base64
1382
1383 PGh0bWw+CjxoZWFkPgogICAgVGhpcyB3YXMgdGhlIHRleHQvaHRtbCBwYXJ0Lgo8L2hlYWQ+Cjwv
1384 Ym9keT4KPC9odG1sPgo=
1385
1386 ------- =_aaaaaaaaaa0--
1387 EOF
1388 run_prog mhfixmsg last -outfile "$actual" -noreformat
1389 check "$expected" "$actual"
1390
1391
1392 # check -decodetypes text/plain
1393 cat >$expected <<EOF
1394 To: recipient@example.com
1395 From: sender@example.com
1396 Subject: mhfixmsg decode test 4
1397 MIME-Version: 1.0
1398 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1399
1400 ------- =_aaaaaaaaaa0
1401 Content-Type: text/plain; charset="iso-8859-1"
1402 Content-Disposition: attachment; filename="test1.txt"
1403 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1404 Content-Transfer-Encoding: 8bit
1405
1406 This is the text/plain part.
1407
1408 ------- =_aaaaaaaaaa0
1409 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
1410 Content-Disposition: attachment; filename="test2.txt"
1411 Content-Transfer-Encoding: base64
1412
1413 PGh0bWw+DQo8aGVhZD4NCiAgICBUaGlzIGlzIHRoZSB0ZXh0L2h0bWwgcGFydC4NCjwvaGVhZD4N
1414 CjwvYm9keT4NCjwvaHRtbD4NCg==
1415
1416 ------- =_aaaaaaaaaa0--
1417 EOF
1418
1419 cat >`mhpath new` <<EOF
1420 To: recipient@example.com
1421 From: sender@example.com
1422 Subject: mhfixmsg decode test 4
1423 MIME-Version: 1.0
1424 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1425
1426 ------- =_aaaaaaaaaa0
1427 Content-Type: text/plain; charset="iso-8859-1"
1428 Content-Disposition: attachment; filename="test1.txt"
1429 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1430 Content-Transfer-Encoding: quoted-printable
1431
1432 This is the text/plain part.
1433
1434 ------- =_aaaaaaaaaa0
1435 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
1436 Content-Disposition: attachment; filename="test2.txt"
1437 Content-Transfer-Encoding: base64
1438
1439 PGh0bWw+DQo8aGVhZD4NCiAgICBUaGlzIGlzIHRoZSB0ZXh0L2h0bWwgcGFydC4NCjwvaGVhZD4N
1440 CjwvYm9keT4NCjwvaHRtbD4NCg==
1441
1442 ------- =_aaaaaaaaaa0--
1443 EOF
1444 run_prog mhfixmsg last -outfile "$actual" -decodetypes text/plain -noreformat
1445 check "$expected" "$actual"
1446
1447
1448 # check -decodetypes attachment/ics
1449 cat >$expected <<EOF
1450 To: recipient@example.com
1451 From: sender@example.com
1452 Subject: mhfixmsg decode test 5
1453 MIME-Version: 1.0
1454 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1455
1456 ------- =_aaaaaaaaaa0
1457 Content-Type: text/plain; charset="iso-8859-1"
1458 Content-Disposition: attachment; filename="test1.txt"
1459 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1460 Content-Transfer-Encoding: 8bit
1461
1462 This is the text/plain part.
1463
1464 ------- =_aaaaaaaaaa0
1465 Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics"
1466 Content-Disposition: attachment; filename="invite.ics"
1467 Content-Transfer-Encoding: 8bit
1468
1469 BEGIN:VCALENDAR
1470 VERSION:2.0
1471 PRODID:test-mhical
1472 BEGIN:VEVENT
1473 DTSTAMP:20150101T162400Z
1474 DTSTART:20150105T160000
1475 DTEND:20150105T163000
1476 SUMMARY:4 pm meeting
1477 END:VEVENT
1478 END:VCALENDAR
1479
1480 ------- =_aaaaaaaaaa0--
1481 EOF
1482
1483 cat >`mhpath new` <<EOF
1484 To: recipient@example.com
1485 From: sender@example.com
1486 Subject: mhfixmsg decode test 5
1487 MIME-Version: 1.0
1488 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1489
1490 ------- =_aaaaaaaaaa0
1491 Content-Type: text/plain; charset="iso-8859-1"
1492 Content-Disposition: attachment; filename="test1.txt"
1493 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1494 Content-Transfer-Encoding: quoted-printable
1495
1496 This is the=
1497 text/plain part.
1498
1499 ------- =_aaaaaaaaaa0
1500 Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics"
1501 Content-Disposition: attachment; filename="invite.ics"
1502 Content-Transfer-Encoding: base64
1503
1504 QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KUFJPRElEOnRlc3QtbWhpY2FsDQpCRUdJTjpW
1505 RVZFTlQNCkRUU1RBTVA6MjAxNTAxMDFUMTYyNDAwWg0KRFRTVEFSVDoyMDE1MDEwNVQxNjAwMDAN
1506 CkRURU5EOjIwMTUwMTA1VDE2MzAwMA0KU1VNTUFSWTo0IHBtIG1lZXRpbmcNCkVORDpWRVZFTlQN
1507 CkVORDpWQ0FMRU5EQVINCg==
1508
1509 ------- =_aaaaaaaaaa0--
1510 EOF
1511 run_prog mhfixmsg last -outfile "$actual" -noreformat
1512 check "$expected" "$actual"
1513
1514
1515 # check -decodetypes attachment/ics and -nocrlflinebreaks
1516 cat >$expected <<EOF
1517 To: recipient@example.com
1518 From: sender@example.com
1519 Subject: mhfixmsg decode test 5
1520 MIME-Version: 1.0
1521 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1522
1523 ------- =_aaaaaaaaaa0
1524 Content-Type: text/plain; charset="iso-8859-1"
1525 Content-Disposition: attachment; filename="test1.txt"
1526 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1527 Content-Transfer-Encoding: 8bit
1528
1529 This is the text/plain part.
1530
1531 ------- =_aaaaaaaaaa0
1532 Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics"
1533 Content-Disposition: attachment; filename="invite.ics"
1534 Content-Transfer-Encoding: 8bit
1535
1536 BEGIN:VCALENDAR
1537 VERSION:2.0
1538 PRODID:test-mhical
1539 BEGIN:VEVENT
1540 DTSTAMP:20150101T162400Z
1541 DTSTART:20150105T160000
1542 DTEND:20150105T163000
1543 SUMMARY:4 pm meeting
1544 END:VEVENT
1545 END:VCALENDAR
1546
1547 ------- =_aaaaaaaaaa0--
1548 EOF
1549
1550 cat >`mhpath new` <<EOF
1551 To: recipient@example.com
1552 From: sender@example.com
1553 Subject: mhfixmsg decode test 5
1554 MIME-Version: 1.0
1555 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
1556
1557 ------- =_aaaaaaaaaa0
1558 Content-Type: text/plain; charset="iso-8859-1"
1559 Content-Disposition: attachment; filename="test1.txt"
1560 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
1561 Content-Transfer-Encoding: quoted-printable
1562
1563 This is the=
1564 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: base64
1570
1571 QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KUFJPRElEOnRlc3QtbWhpY2FsDQpCRUdJTjpW
1572 RVZFTlQNCkRUU1RBTVA6MjAxNTAxMDFUMTYyNDAwWg0KRFRTVEFSVDoyMDE1MDEwNVQxNjAwMDAN
1573 CkRURU5EOjIwMTUwMTA1VDE2MzAwMA0KU1VNTUFSWTo0IHBtIG1lZXRpbmcNCkVORDpWRVZFTlQN
1574 CkVORDpWQ0FMRU5EQVINCg==
1575
1576 ------- =_aaaaaaaaaa0--
1577 EOF
1578 run_prog mhfixmsg last -outfile "$actual" -nocrlflinebreaks -noreformat
1579 check "$expected" "$actual"
1580
1581
1582 # make sure there are no tmp files left over
1583 find "$MH_TEST_DIR/Mail" \( -name 'mhfix*' -o -name ',mhfix*' \) -print \
1584 >"$actual"
1585 cat >"$expected" <<EOF
1586 EOF
1587
1588 check "$expected" "$actual"
1589
1590
1591 exit $failed