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