b072cacaa976cdbd8b4eda45d856ac790d3245ab
[mmh] / test / post / test-messageid
1 #!/bin/sh
2 #
3 # Test post -messageid
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
19 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
20 From: Mr Nobody <nobody@example.com>
21 To: Somebody Else <somebody@example.com>
22 Subject: Test
23
24 This is a test
25 EOF
26
27 cat > "${testname}.expected" <<EOF
28 EHLO nosuchhost.example.com
29 MAIL FROM:<nobody@example.com>
30 RCPT TO:<somebody@example.com>
31 DATA
32 From: Mr Nobody <nobody@example.com>
33 To: Somebody Else <somebody@example.com>
34 Subject: Test
35 Date:
36
37 This is a test
38 .
39 QUIT
40 EOF
41
42 # check invalid -messageid selection
43 run_test "send -draft -messageid invalid" \
44 "post: unsupported messageid \"invalid\"
45 send: message not delivered to anyone"
46
47 #### Rely on sendmail/pipe below to override default mts.
48 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
49 cp "${MHMTSCONF}" "$mts_fakesendmail"
50 printf "%s\n" "sendmail: ${srcdir}/test/fakesendmail" >>"$mts_fakesendmail"
51 MHMTSCONF="$mts_fakesendmail"
52
53 # $1: -messageid switch selection
54 # arguments: expected output(s)
55 test_messageid ()
56 {
57   msgid_style="$1"
58   send -draft -mts sendmail/pipe -msgid -messageid "$msgid_style"
59   shift
60
61   # fakesendmail drops the message and any cc's into this mbox.
62   mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
63   inc -silent -file "$mbox"
64   rm -f "$mbox" "$mbox.map"
65
66   n=1
67   for expected in "$@"; do
68     cur=`mhpath cur`
69     # Verify that Message-ID is of the right form.  We'll see how
70     # portable these grep regular expressions are.
71     case "$msgid_style" in
72       localname)
73         # e.g., Message-ID: <5348.1342884222@localhost.localdomain>
74         id='^Message-ID: <[0-9]\{1,\}\.[0-9]\{1,\}@'
75         ;;
76       random)
77         # e.g., Message-ID: <5364-1342884222.165897@ldYMFXwUbBqKcZwg>
78         id=\
79 '^Message-ID: <[0-9]\{1,\}-[0-9]\{1,\}\.[0-9]\{6,6\}@[+/0-9A-Za-z]\{16,16\}'
80         ;;
81       *)         printf "$0: unexpected messageid: $msgid_style"; exit 1;;
82     esac
83
84     if grep "$id" "$cur" >/dev/null; then
85       :
86     else
87       mv "$cur" "${testname}.actual"
88       printf "$0: unexpected "$msgid_style" Message-ID format, \
89 see ${testname}.actual\n"
90       exit 1
91     fi
92
93     #
94     # It's hard to calculate the exact Date: header post is going to
95     # use, so we'll just use sed to remove the actual date so we can easily
96     # compare it against our "correct" output.  And same for
97     # Message-ID.
98     #
99     sed -e 's/^Date:.*/Date:/' \
100         -e 's/^Message-ID:.*/Message-ID:/' \
101         "$cur" > "${testname}.actual$n"
102
103     check "${testname}.actual$n" "$expected"
104
105     if [ "$cur" != "`mhpath last`" ]; then
106       folder next >/dev/null
107       arith_eval $n + 1; n=$arith_val
108     fi
109   done
110 }
111
112 # check -messageid localname (the default)
113 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
114 From: Mr Nobody <nobody@example.com>
115 To: Somebody Else <somebody@example.com>
116 Subject: Test
117
118 This is a test
119 .
120 EOF
121
122 cat > "${testname}.expected" <<EOF
123 From: Mr Nobody <nobody@example.com>
124 To: Somebody Else <somebody@example.com>
125 Subject: Test
126 Date:
127 Message-ID:
128
129 This is a test
130 .
131 EOF
132
133 test_messageid localname "${testname}.expected"
134
135 # check -messageid random
136 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
137 From: Mr Nobody <nobody@example.com>
138 To: Somebody Else <somebody@example.com>
139 Subject: Test
140
141 This is a test
142 .
143 EOF
144
145 cat > "${testname}.expected" <<EOF
146 From: Mr Nobody <nobody@example.com>
147 To: Somebody Else <somebody@example.com>
148 Subject: Test
149 Date:
150 Message-ID:
151
152 This is a test
153 .
154 EOF
155
156 test_messageid random "${testname}.expected"
157
158
159 rm -f ${MHMTSCONF}
160
161 exit ${failed:-0}