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