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