spost(8) has been merged into post(8). Its functionality is
[mmh] / test / post / test-pipe
1 #!/bin/sh
2 #
3 # Test the basic behavior of post when configured with pipe delivery method.
4 #
5
6 set -e
7
8 if test -z "${MH_OBJ_DIR}"; then
9     srcdir=`dirname "$0"`/../..
10     MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
11 fi
12
13 . "${MH_OBJ_DIR}/test/common.sh"
14
15 setup_test
16 testname="${MH_TEST_DIR}/$$"
17
18 #### Force test of pipe regardless of configuration.
19 mts_pipe="${MHMTSCONF}-pipe"
20 sed -e 's/mts: *.*/mts: pipe/' "${MHMTSCONF}" >"$mts_pipe"
21 printf "%s\n" "sendmail: ${srcdir}/test/fakesendmail" >>"$mts_pipe"
22 MHMTSCONF="$mts_pipe"
23
24 test_pipe ()
25 {
26   send -draft
27
28   # fakesendmail drops the message and any cc's into this mbox.
29   mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
30   inc -silent -file "$mbox"
31   rm -f "$mbox" "$mbox.map"
32
33   n=1
34   for expected in "$@"; do
35     #
36     # It's hard to calculate the exact Date: header post is going to
37     # use, so we'll just use sed to remove the actual date so we can easily
38     # compare it against our "correct" output.
39     #
40     sed -e 's/^Date:.*/Date:/' "`mhpath cur`" > "${testname}.actual$n"
41
42     check "${testname}.actual$n" "$expected"
43
44     if [ "`mhpath cur`" != "`mhpath last`" ]; then
45       folder next >/dev/null
46       arith_eval $n + 1; n=$arith_val
47     fi
48   done
49 }
50
51 #
52 # Basic test - Simple message, single user, single recipient.
53 # Dots are not stuffed because pipe invokes sendmail with -i.
54 #
55 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
56 From: Mr Nobody <nobody@example.com>
57 To: Somebody Else <somebody@example.com>
58 Subject: Test
59
60 This is a test
61 .
62 EOF
63
64 cat > "${testname}.expected" <<EOF
65 From: Mr Nobody <nobody@example.com>
66 To: Somebody Else <somebody@example.com>
67 Subject: Test
68 Date:
69
70 This is a test
71 .
72 EOF
73
74 test_pipe "${testname}.expected"
75
76
77 # check Bcc
78 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
79 From: Mr Nobody <nobody@example.com>
80 To: Somebody Else <somebody@example.com>
81 Bcc: Silent Partner <bcc@example.com>
82 Subject: Test
83
84 This is a test
85 .
86 EOF
87
88 cat > "${testname}.expected1" <<EOF
89 From: Mr Nobody <nobody@example.com>
90 To: Somebody Else <somebody@example.com>
91 Subject: Test
92 Date:
93
94 This is a test
95 .
96 EOF
97
98 cat > "${testname}.expected2" <<EOF
99 Date:
100 Subject: Test
101
102 ------- Blind-Carbon-Copy
103
104 From: Mr Nobody <nobody@example.com>
105 To: Somebody Else <somebody@example.com>
106 Subject: Test
107 Date:
108
109 This is a test
110 .
111
112 ------- End of Blind-Carbon-Copy
113 EOF
114
115 test_pipe "${testname}.expected1" "${testname}.expected2"
116
117
118 rm -f ${MHMTSCONF}
119
120 exit ${failed:-0}