]> diplodocus.org Git - nmh/blob - test/mhmail/test-mhmail
Try this test-mhmail probe.
[nmh] / test / mhmail / test-mhmail
1 #!/bin/sh
2 ######################################################
3 #
4 # Test mhmail
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 . "${srcdir}/test/post/test-post-common.sh"
16
17 # Customize test_post () for use with mhmail.
18 # $1 is expected output file, provided by caller
19 # $2 is mhmail switches, except for -body
20 # $3 of -b signifies use -body switch, | signifies provide body on stdin
21 # $4 contains the message body.
22 test_mhmail ()
23 {
24 pid=`"${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport`
25
26 if [ $3 = '|' ]; then
27 printf '%s' "$4" | mhmail recipient@example.com $2 \
28 -server 127.0.0.1 -port $localport
29 else
30 mhmail recipient@example.com $2 -body "$4" \
31 -server 127.0.0.1 -port $localport
32 fi
33
34 #
35 # It's hard to calculate the exact Date: header post is going to
36 # use, so we'll just use sed to remove the actual date so we can easily
37 # compare it against our "correct" output. And same for
38 # Message-ID.
39 #
40
41 ls -l $actual >&2 # ???? temporary
42 echo actual:
43 cat $actual
44 echo end of actual
45
46 sed -e 's/^Date:.*/Date:/' \
47 -e 's/^Resent-Date:.*/Resent-Date:/' \
48 -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate
49 rm -f "$actual"
50
51 check "$actual".nodate "$1"
52 }
53
54 expected=$MH_TEST_DIR/test-mhmail$$.expected
55 expected_err=$MH_TEST_DIR/test-mhmail$$.expected_err
56 actual=$MH_TEST_DIR/test-mhmail$$.actual
57 actual_err=$MH_TEST_DIR/test-mhmail$$.actual_err
58
59
60 # check -help
61 # Verified behavior consistent with compiled sendmail.
62 cat >$expected <<EOF
63 Usage: mhmail [-t(o)] addrs ... [switches]
64 switches are:
65 -at(tach) file [-at(tach) file] ...
66 -b(ody) text
67 -c(c) addrs ...
68 -f(rom) addr
69 -hea(derfield) name:value [-hea(derfield) name:value] ...
70 -su(bject) text
71 -r(esent)
72 -pr(ofile)
73 -se(nd)
74 -nose(nd)
75 -v(ersion)
76 -hel(p)
77 and all post(8)/send(1) switches
78 mhmail with no arguments is equivalent to inc
79 EOF
80
81 mhmail -help >$actual 2>&1
82 check $expected $actual
83
84
85 # check -version
86 # Verified same behavior as compiled mhmail.
87 case `mhmail -v` in
88 mhmail\ --*) ;;
89 * ) printf '%s: mhmail -v generated unexpected output\n' "$0" >&2
90 failed=`expr ${failed:-0} + 1`;;
91 esac
92
93 # check for missing argument to switches that require them
94 for switch in attach body cc from headerfield subject to; do
95 run_test "mhmail recipient -$switch" \
96 "mhmail: missing argument to -$switch"
97 done
98 for switch in attach body cc from headerfield subject to; do
99 run_test "mhmail recipient -$switch -nosend" \
100 "mhmail: missing argument to -$switch"
101 done
102 for switch in attach body cc from headerfield subject to; do
103 run_test "mhmail recipient -$switch -server 127.0.0.1" \
104 "mhmail: missing argument to -$switch"
105 done
106
107
108 # check with no switches
109 # That will just run inc, which we don't want to do anything,
110 # so tell inc to just display its version.
111 # Verified same behavior as compiled mhmail.
112 printf 'inc: -version\n' >> $MH
113 case `mhmail` in
114 inc\ --*) ;;
115 * ) echo "$0: mhmail generated unexpected output" >&2
116 failed=`expr ${failed:-0} + 1`;;
117 esac
118
119
120 # check -nosend
121 # Not supported by compiled mhmail.
122 mhmail -nosend recipient@example.com -from sender@localhost \
123 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
124
125 cat > "$expected" <<EOF
126 To: recipient@example.com
127 From: sender@localhost
128
129
130 EOF
131
132 cat > "$expected_err" <<EOF
133 EOF
134
135 check "$expected" "$actual"
136 check "$expected_err" "$actual_err"
137 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
138
139
140 # check -send
141 # Not supported by compiled mhmail.
142 cat > "$expected" <<EOF
143 EHLO nosuchhost.example.com
144 MAIL FROM:<sender@localhost>
145 RCPT TO:<recipient@example.com>
146 DATA
147 To: recipient@example.com
148 From: sender@localhost
149 Date:
150
151 message
152 .
153 QUIT
154 EOF
155
156 test_mhmail "$expected" "-from sender@localhost -nosend -send" '|' message
157 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
158
159
160 # check -from
161 # Verified same behavior as compiled mhmail.
162 cat > "$expected" <<EOF
163 EHLO nosuchhost.example.com
164 MAIL FROM:<sender@localhost>
165 RCPT TO:<recipient@example.com>
166 DATA
167 To: recipient@example.com
168 From: sender@localhost
169 Date:
170
171 message
172 .
173 QUIT
174 EOF
175
176 test_mhmail "$expected" "-from sender@localhost" '|' message
177 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
178
179
180 # check -from and -body
181 # Verified same behavior as compiled mhmail.
182 cat > "$expected" <<EOF
183 EHLO nosuchhost.example.com
184 MAIL FROM:<sender@localhost>
185 RCPT TO:<recipient@example.com>
186 DATA
187 To: recipient@example.com
188 From: sender@localhost
189 Date:
190
191 body
192 .
193 QUIT
194 EOF
195
196 test_mhmail "$expected" "-from sender@localhost" -b body
197 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
198
199
200 # check -from and -cc
201 # Verified same behavior as compiled mhmail.
202 cat > "$expected" <<EOF
203 EHLO nosuchhost.example.com
204 MAIL FROM:<sender@localhost>
205 RCPT TO:<recipient@example.com>
206 RCPT TO:<recipient2@example.com>
207 DATA
208 To: recipient@example.com
209 Cc: recipient2@example.com
210 From: sender@localhost
211 Date:
212
213 message
214 .
215 QUIT
216 EOF
217
218 test_mhmail "$expected" \
219 "-from sender@localhost -cc recipient2@example.com" '|' message
220 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
221
222
223 # check -from and multiple -cc addresses
224 # Verified same behavior as compiled mhmail.
225 cat > "$expected" <<EOF
226 EHLO nosuchhost.example.com
227 MAIL FROM:<sender@localhost>
228 RCPT TO:<recipient@example.com>
229 RCPT TO:<recipient2@example.com>
230 RCPT TO:<recipient3@example.com>
231 RCPT TO:<recipient4@example.com>
232 DATA
233 To: recipient@example.com
234 Cc: recipient2@example.com, recipient3@example.com,
235 recipient4@example.com
236 From: sender@localhost
237 Date:
238
239 message
240 .
241 QUIT
242 EOF
243
244 test_mhmail "$expected" \
245 '-from sender@localhost -cc recipient2@example.com recipient3@example.com '\
246 'recipient4@example.com' '|' message
247 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
248
249
250 # check -from and -subject
251 # Verified same behavior as compiled mhmail.
252 cat > "$expected" <<EOF
253 EHLO nosuchhost.example.com
254 MAIL FROM:<sender@localhost>
255 RCPT TO:<recipient@example.com>
256 DATA
257 To: recipient@example.com
258 Subject: Test
259 From: sender@localhost
260 Date:
261
262 message
263 .
264 QUIT
265 EOF
266
267 test_mhmail "$expected" '-from sender@localhost -subject Test' '|' message
268 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
269
270
271 # check -from and -profile
272 # Show that -profile causes mhmail to 1) read the profile and
273 # 2) use send(1) by added a send switch to the profile and
274 # verifying that it gets used.
275 # Not supported by compiled mhmail.
276 printf 'send: -msgid\n' >> $MH
277
278 cat > "$expected" <<EOF
279 EHLO nosuchhost.example.com
280 MAIL FROM:<sender@localhost>
281 RCPT TO:<recipient@example.com>
282 DATA
283 To: recipient@example.com
284 From: sender@localhost
285 Date:
286 Message-ID:
287
288 message
289 .
290 QUIT
291 EOF
292
293 test_mhmail "$expected" '-from sender@localhost -profile' '|' message
294 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
295
296
297 # check repeated -from and -subject switches
298 # Verified same behavior as compiled mhmail.
299 cat > "$expected" <<EOF
300 EHLO nosuchhost.example.com
301 MAIL FROM:<sender2@localhost>
302 RCPT TO:<recipient@example.com>
303 DATA
304 To: recipient@example.com
305 Subject: Subject2
306 From: sender2@localhost
307 Date:
308
309 message
310 .
311 QUIT
312 EOF
313
314 test_mhmail "$expected" '-from sender@localhost -from sender2@localhost '\
315 '-subject Subject1 -subject Subject2' -b message
316 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
317
318 # check repeated -body switches
319 # Verified same behavior as compiled mhmail.
320 cat > "$expected" <<EOF
321 EHLO nosuchhost.example.com
322 MAIL FROM:<sender@localhost>
323 RCPT TO:<recipient@example.com>
324 DATA
325 To: recipient@example.com
326 From: sender@localhost
327 Date:
328
329 body2
330 .
331 QUIT
332 EOF
333
334 test_mhmail "$expected" "-from sender@localhost -body body1" -b body2
335 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
336
337
338 # check multiple -cc switches
339 # Verified same behavior as compiled mhmail.
340 cat > "$expected" <<EOF
341 EHLO nosuchhost.example.com
342 MAIL FROM:<sender@localhost>
343 RCPT TO:<recipient@example.com>
344 RCPT TO:<cc1@example.com>
345 RCPT TO:<cc2@example.com>
346 DATA
347 To: recipient@example.com
348 Cc: cc1@example.com, cc2@example.com
349 From: sender@localhost
350 Date:
351
352 message
353 .
354 QUIT
355 EOF
356
357 test_mhmail "$expected" \
358 '-from sender@localhost -cc cc1@example.com -cc cc2@example.com' -b message
359 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
360
361
362 # check separated -cc arguments
363 # Verified same behavior as compiled mhmail.
364 cat > "$expected" <<EOF
365 EHLO nosuchhost.example.com
366 MAIL FROM:<sender@localhost>
367 RCPT TO:<recipient@example.com>
368 RCPT TO:<cc1@example.com>
369 RCPT TO:<cc2@example.com>
370 DATA
371 To: recipient@example.com
372 Cc: cc1@example.com, cc2@example.com
373 Subject: Test
374 From: sender@localhost
375 Date:
376
377 message
378 .
379 QUIT
380 EOF
381
382 test_mhmail "$expected" \
383 '-from sender@localhost -cc cc1@example.com -subject Test cc2@example.com' \
384 -b message
385 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
386
387
388 # check -cc switch followed by -to switch
389 # Verified same behavior as compiled mhmail.
390 cat > "$expected" <<EOF
391 EHLO nosuchhost.example.com
392 MAIL FROM:<sender@localhost>
393 RCPT TO:<recipient@example.com>
394 RCPT TO:<recipient2@example.com>
395 RCPT TO:<cc1@example.com>
396 DATA
397 To: recipient@example.com, recipient2@example.com
398 Cc: cc1@example.com
399 Subject: Test
400 From: sender@localhost
401 Date:
402
403 message
404 .
405 QUIT
406 EOF
407
408 test_mhmail "$expected" \
409 "-from sender@localhost -cc cc1@example.com -subject Test \
410 -to recipient2@example.com" \
411 -b message
412 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
413
414
415 # check with no newline on stdin
416 # Shows different behavior than compiled mhmail, which was silent in this case.
417 cat > "$expected" <<EOF
418 EOF
419
420 cat > "$expected_err" <<EOF
421 mhmail: empty message not sent, use -body '' to force.
422 EOF
423
424 set +e
425 printf '' | mhmail recipient@example.com -server 127.0.0.1 -port $localport \
426 >"$actual" 2>"$actual_err"
427 set -e
428
429 check "$expected" "$actual"
430 check "$expected_err" "$actual_err"
431 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
432
433
434 # check with one newline on stdin
435 # Verified same behavior as compiled mhmail.
436 cat > "$expected" <<EOF
437 EHLO nosuchhost.example.com
438 MAIL FROM:<sender@localhost>
439 RCPT TO:<recipient@example.com>
440 DATA
441 To: recipient@example.com
442 From: sender@localhost
443 Date:
444
445
446 .
447 QUIT
448 EOF
449
450 test_mhmail "$expected" '-from sender@localhost' '|' '
451 '
452 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
453
454
455 # check with multiple newlines on stdin
456 # Verified same behavior as compiled mhmail.
457 cat > "$expected" <<EOF
458 EHLO nosuchhost.example.com
459 MAIL FROM:<sender@localhost>
460 RCPT TO:<recipient@example.com>
461 DATA
462 To: recipient@example.com
463 From: sender@localhost
464 Date:
465
466
467
468
469 .
470 QUIT
471 EOF
472
473 test_mhmail "$expected" '-from sender@localhost' '|' '
474
475
476 '
477 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
478
479
480 # check with text and no trailing newline on stdin
481 # Verified same behavior as compiled mhmail.
482 cat > "$expected" <<EOF
483 EHLO nosuchhost.example.com
484 MAIL FROM:<sender@localhost>
485 RCPT TO:<recipient@example.com>
486 DATA
487 To: recipient@example.com
488 From: sender@localhost
489 Date:
490
491 no newline in input
492 .
493 QUIT
494 EOF
495
496 test_mhmail "$expected" '-from sender@localhost' '|' 'no newline in input'
497 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
498
499
500 # check with text and multiple trailing blank lines on stdin
501 # Verified same behavior as compiled mhmail.
502 cat > "$expected" <<EOF
503 EHLO nosuchhost.example.com
504 MAIL FROM:<sender@localhost>
505 RCPT TO:<recipient@example.com>
506 DATA
507 To: recipient@example.com
508 From: sender@localhost
509 Date:
510
511 here's some text
512
513
514 .
515 QUIT
516 EOF
517
518 test_mhmail "$expected" '-from sender@localhost' '|' "here's some text
519
520
521 "
522 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
523
524
525 # check with no newline to -body
526 # Verified same behavior as compiled mhmail.
527 cat > "$expected" <<EOF
528 EHLO nosuchhost.example.com
529 MAIL FROM:<sender@localhost>
530 RCPT TO:<recipient@example.com>
531 DATA
532 To: recipient@example.com
533 From: sender@localhost
534 Date:
535
536
537 .
538 QUIT
539 EOF
540
541 test_mhmail "$expected" '-from sender@localhost' -b ''
542 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
543
544
545 # check with one newline to -body
546 # Shows different behavior than compiled mhmail, which suppressed the newline.
547 cat > "$expected" <<EOF
548 EHLO nosuchhost.example.com
549 MAIL FROM:<sender@localhost>
550 RCPT TO:<recipient@example.com>
551 DATA
552 To: recipient@example.com
553 From: sender@localhost
554 Date:
555
556
557
558 .
559 QUIT
560 EOF
561
562 test_mhmail "$expected" '-from sender@localhost' -b '
563 '
564 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
565
566
567 # check with multiple newlines to -body
568 # Shows different behavior than compiled mhmail, which suppressed one
569 # of the newlines.
570 cat > "$expected" <<EOF
571 EHLO nosuchhost.example.com
572 MAIL FROM:<sender@localhost>
573 RCPT TO:<recipient@example.com>
574 DATA
575 To: recipient@example.com
576 From: sender@localhost
577 Date:
578
579
580
581
582
583 .
584 QUIT
585 EOF
586
587 test_mhmail "$expected" '-from sender@localhost' -b '
588
589
590 '
591 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
592
593
594 # check with text and no trailing newline to -body
595 # Verified same behavior as compiled mhmail.
596 cat > "$expected" <<EOF
597 EHLO nosuchhost.example.com
598 MAIL FROM:<sender@localhost>
599 RCPT TO:<recipient@example.com>
600 DATA
601 To: recipient@example.com
602 From: sender@localhost
603 Date:
604
605 no newline in input
606 .
607 QUIT
608 EOF
609
610 test_mhmail "$expected" '-from sender@localhost' -b 'no newline in input'
611 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
612
613
614 # check with text and multiple trailing blank lines to -body
615 # Shows different behavior than compiled mhmail, which suppressed one
616 # of the newlines.
617 cat > "$expected" <<EOF
618 EHLO nosuchhost.example.com
619 MAIL FROM:<sender@localhost>
620 RCPT TO:<recipient@example.com>
621 DATA
622 To: recipient@example.com
623 From: sender@localhost
624 Date:
625
626 here's some text
627
628
629 .
630 QUIT
631 EOF
632
633 test_mhmail "$expected" '-from sender@localhost' -b "here's some text
634
635 "
636 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
637
638
639 # check -resent
640 # Verified same behavior as compiled mhmail.
641 cat > "$expected" <<EOF
642 EHLO nosuchhost.example.com
643 MAIL FROM:<orig_recipient@example.com>
644 RCPT TO:<recipient@example.com>
645 DATA
646 Resent-To: recipient@example.com
647 Resent-From: orig_recipient@example.com
648 To: recipient@example.com
649 From: sender@localhost
650 Date:
651 Resent-Date:
652
653 please resend this message, 1
654 .
655 QUIT
656 EOF
657
658 test_mhmail "$expected" '-from orig_recipient@example.com -resent' \
659 -b 'To: recipient@example.com
660 From: sender@localhost
661 Date: Sat Jun 16 18:35:15 -0500
662
663 please resend this message, 1'
664
665 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
666
667 # check -resent -profile, using stdin
668 # Not supported by compiled mhmail.
669 cat > "$expected" <<EOF
670 EHLO nosuchhost.example.com
671 MAIL FROM:<orig_recipient@example.com>
672 RCPT TO:<recipient@example.com>
673 DATA
674 To: recipient@example.com
675 From: sender@localhost
676 Date:
677 Resent-To: recipient@example.com
678 Resent-From: orig_recipient@example.com
679 Resent-Date:
680
681 please resend this message, 2
682 .
683 QUIT
684 EOF
685
686 test_mhmail "$expected" \
687 '-from orig_recipient@example.com -resent -profile -nomsgid' \
688 '|' 'To: recipient@example.com
689 From: sender@localhost
690 Date: Sat Jun 16 18:35:15 -0500
691
692 please resend this message, 2'
693
694 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
695
696
697 # check -resent -profile, using -b
698 # Not supported by compiled mhmail.
699 cat > "$expected" <<EOF
700 EHLO nosuchhost.example.com
701 MAIL FROM:<orig_recipient@example.com>
702 RCPT TO:<recipient@example.com>
703 DATA
704 To: recipient@example.com
705 From: sender@localhost
706 Date:
707 Resent-To: recipient@example.com
708 Resent-From: orig_recipient@example.com
709 Resent-Date:
710
711 please resend this message, 3
712 .
713 QUIT
714 EOF
715
716 test_mhmail "$expected" \
717 '-from orig_recipient@example.com -resent -profile -nomsgid' \
718 -b 'To: recipient@example.com
719 From: sender@localhost
720 Date: Sat Jun 16 18:35:15 -0500
721
722 please resend this message, 3'
723
724 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
725
726
727 # check -headerfield.
728 # Not supported by compiled mhmail.
729 cat > "$expected" <<EOF
730 EHLO nosuchhost.example.com
731 MAIL FROM:<sender@example.com>
732 RCPT TO:<recipient@example.com>
733 DATA
734 To: recipient@example.com
735 From: sender@example.com
736 User-Agent: nmh
737 Date:
738
739 with added header field
740 .
741 QUIT
742 EOF
743
744 test_mhmail "$expected" \
745 '-from sender@example.com -headerfield User-Agent:nmh' \
746 -b 'with added header field'
747
748 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
749
750
751 # check multiple -headerfields.
752 # Not supported by compiled mhmail.
753 cat > "$expected" <<EOF
754 EHLO nosuchhost.example.com
755 MAIL FROM:<sender@example.com>
756 RCPT TO:<recipient@example.com>
757 DATA
758 To: recipient@example.com
759 From: sender@example.com
760 MIME-Version: 1.0
761 Content-Type: text/plain;charset=utf-8
762 Content-Transfer-Encoding: 8bit
763 Date:
764
765 with added header fields
766 .
767 QUIT
768 EOF
769
770 test_mhmail "$expected" \
771 "-from sender@example.com -headerfield MIME-Version:1.0 \
772 -headerfield Content-Type:text/plain;charset=utf-8 \
773 -headerfield Content-Transfer-Encoding:8bit" \
774 -b 'with added header fields'
775
776 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
777
778
779 # check -attach
780 # Not supported by compiled mhmail.
781 cat > "$expected" <<EOF
782 EHLO nosuchhost.example.com
783 MAIL FROM:<sender@example.com>
784 RCPT TO:<recipient@example.com>
785 DATA
786 To: recipient@example.com
787 From: sender@example.com
788 MIME-Version: 1.0
789 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
790 Date:
791 Message-ID:
792
793 ------- =_aaaaaaaaaa0
794 Content-Type: text/plain; charset="us-ascii"
795
796 See how easy it is to add an attachment!
797
798 ------- =_aaaaaaaaaa0
799 Content-Type: text/plain; name="attachment.txt"; charset="us-ascii"
800 Content-Description: attachment.txt
801 Content-Disposition: attachment; filename="attachment.txt"
802
803 The future disappears into memory, With only a moment between,
804 Forever dwells in that moment, hope is what remains to be seen
805 Forever dwells in that moment, hope is what remains to be seen.
806
807 ------- =_aaaaaaaaaa0--
808 .
809 QUIT
810 EOF
811
812 test_mhmail "$expected" \
813 "-from sender@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
814 -b 'See how easy it is to add an attachment!'
815
816 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
817
818
819 exit ${failed:-0}