With -messageid random, make the part after the @ more resemble a
[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@ldYM.FXwU.bBqK>
78         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\}'
79         ;;
80       *)         printf "$0: unexpected messageid: $msgid_style"; exit 1;;
81     esac
82
83     if grep "$id" "$cur" >/dev/null; then
84       :
85     else
86       mv "$cur" "${testname}.actual"
87       printf "$0: unexpected "$msgid_style" Message-ID format, \
88 see ${testname}.actual\n"
89       exit 1
90     fi
91
92     #
93     # It's hard to calculate the exact Date: header post is going to
94     # use, so we'll just use sed to remove the actual date so we can easily
95     # compare it against our "correct" output.  And same for
96     # Message-ID.
97     #
98     sed -e 's/^Date:.*/Date:/' \
99         -e 's/^Message-ID:.*/Message-ID:/' \
100         "$cur" > "${testname}.actual$n"
101
102     check "${testname}.actual$n" "$expected"
103
104     if [ "$cur" != "`mhpath last`" ]; then
105       folder next >/dev/null
106       arith_eval $n + 1; n=$arith_val
107     fi
108   done
109 }
110
111 # check -messageid localname (the default)
112 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
113 From: Mr Nobody <nobody@example.com>
114 To: Somebody Else <somebody@example.com>
115 Subject: Test
116
117 This is a test
118 .
119 EOF
120
121 cat > "${testname}.expected" <<EOF
122 From: Mr Nobody <nobody@example.com>
123 To: Somebody Else <somebody@example.com>
124 Subject: Test
125 Date:
126 Message-ID:
127
128 This is a test
129 .
130 EOF
131
132 test_messageid localname "${testname}.expected"
133
134 # check -messageid random
135 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
136 From: Mr Nobody <nobody@example.com>
137 To: Somebody Else <somebody@example.com>
138 Subject: Test
139
140 This is a test
141 .
142 EOF
143
144 cat > "${testname}.expected" <<EOF
145 From: Mr Nobody <nobody@example.com>
146 To: Somebody Else <somebody@example.com>
147 Subject: Test
148 Date:
149 Message-ID:
150
151 This is a test
152 .
153 EOF
154
155 test_messageid random "${testname}.expected"
156
157
158 rm -f ${MHMTSCONF}
159
160 exit ${failed:-0}