Added -mts switch to post, send, and whom. Replaced test-sendmail-pipe
[mmh] / test / fakesendmail
1 #! /bin/sh
2 ##
3 # fakesendmail - A fake sendmail program used by the nmh test suite
4 #                to test the sendmail/smtp and sendmail/pipe mts
5 #                methods.
6 #
7 # This code is Copyright (c) 2012, by the authors of nmh.  See the
8 # COPYRIGHT file in the root or documentation directory of the nmh
9 # distribution for complete copyright information.
10 ##
11
12 if [ "$MH_TEST_DIR"x = x ]; then
13   printf "$0 is intended for use only by the nmh test suite\n"
14   exit 1
15 fi
16
17 #### Puts message on stdin in a drop that the test knows about.
18 deliver="${MH_LIB_DIR}/rcvpack ${MH_TEST_DIR}/Mail/fakesendmail.mbox"
19
20 found_dasht=0
21 for arg in "$@"; do
22   [ "$arg" = -t ]  &&  found_dasht=1
23 done
24
25 if [ $found_dasht -eq 0 ]; then
26   # sendmail/smtp
27   msg=
28   datamode=0
29
30   printf "220 If it can't be done in Bourne shell it's not worth doing\n"
31   while read line; do
32     #### Strip off carriage returns, they confuse the pattern matching.
33     line=`printf "$line" | tr -d '\r'`
34
35     case "$line" in
36       DATA) printf "354 do tell\n"; datamode=1 ;;
37          .) printf "250 done\n"; datamode=0; printf "$msg" | $deliver; msg= ;;
38       QUIT) printf "221 byenow\n"; break ;;
39          *) [ $datamode -eq 1 ]  &&  msg="${msg}${line}
40 "  ||  printf "250 OK\n"
41     esac
42   done
43 else
44   # sendmail/pipe
45
46   #### This will delete any lines in the message body that start with Bcc:!
47   sed -e '/^[Bb][Cc][Cc]:/d' | $deliver
48 fi