2 ######################################################
6 ######################################################
10 if test -z "${MH_OBJ_DIR}"; then
11 srcdir=`dirname $0`/../..
12 MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
15 . "${srcdir}/test/post/test-post-common.sh"
17 # Customize test_post () for use with mhmail.
18 # $1 is expected output file, provided by caller
19 # $2 is mhmail switches, except for -body
20 # $3 of -b signifies use -body switch, | signifies provide body on stdin
21 # $4 contains message body. When using stdin, can contain printf(1) format
25 "${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport &
28 # The server doesn't always come up fast enough, so sleep and
29 # retry a few times if it fails...
31 for i in 0 1 2 3 4 5 6 7 8 9; do
33 if printf "$4" | mhmail recipient@example.com $2 \
34 -server 127.0.0.1 -port $localport; then
39 if mhmail recipient@example.com $2 -body "$4" \
40 -server 127.0.0.1 -port $localport; then
47 [ $status -eq 0 ] || exit 1
52 # It's hard to calculate the exact Date: header post is going to
53 # use, so we'll just use sed to remove the actual date so we can easily
54 # compare it against our "correct" output. And same for
58 sed -e 's/^Date:.*/Date:/' \
59 -e 's/^Resent-Date:.*/Resent-Date:/' \
60 -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate
63 check "$actual".nodate "$1"
66 expected=$MH_TEST_DIR/test-mhmail$$.expected
67 expected_err=$MH_TEST_DIR/test-mhmail$$.expected_err
68 actual=$MH_TEST_DIR/test-mhmail$$.actual
69 actual_err=$MH_TEST_DIR/test-mhmail$$.actual_err
73 # Verified behavior consistent with compiled sendmail.
75 Usage: mhmail [addrs ... [switches]]
86 and all post(8)/send(1) switches
89 mhmail -help >$actual 2>&1
90 check $expected $actual
94 # Verified same behavior as compiled mhmail.
97 * ) echo "$0: mhmail -v generated unexpected output" 1>&2
98 failed=`expr ${failed:-0} + 1`;;
102 # check with no arguments
103 # That will just run inc, which we don't want to do anything,
104 # so tell inc to just display its version.
105 # Verified same behavior as compiled mhmail.
106 printf "inc: -version\n" >> $MH
109 * ) echo "$0: mhmail generated unexpected output" 1>&2
110 failed=`expr ${failed:-0} + 1`;;
115 # Not supported by compiled mhmail.
116 mhmail -debug recipient@example.com -from sender@localhost \
117 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
119 tmpfil=`head -1 $actual | sed -e 's/://'`
121 cat > "$expected" <<EOF
123 To: recipient@example.com
124 From: sender@localhost
127 $MH_INST_DIR$auxexecdir/post ${tmpfil} -server 127.0.0.1 -port $localport
130 cat > "$expected_err" <<EOF
133 check "$expected" "$actual"
134 check "$expected_err" "$actual_err"
135 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
139 # Verified same behavior as compiled mhmail.
140 cat > "$expected" <<EOF
141 EHLO nosuchhost.example.com
142 MAIL FROM:<sender@localhost>
143 RCPT TO:<recipient@example.com>
145 To: recipient@example.com
146 From: sender@localhost
154 test_mhmail "$expected" "-from sender@localhost" '|' message
155 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
158 # check -from and -body
159 # Verified same behavior as compiled mhmail.
160 cat > "$expected" <<EOF
161 EHLO nosuchhost.example.com
162 MAIL FROM:<sender@localhost>
163 RCPT TO:<recipient@example.com>
165 To: recipient@example.com
166 From: sender@localhost
174 test_mhmail "$expected" "-from sender@localhost" -b body
175 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
178 # check -from and -cc
179 # Verified same behavior as compiled mhmail.
180 cat > "$expected" <<EOF
181 EHLO nosuchhost.example.com
182 MAIL FROM:<sender@localhost>
183 RCPT TO:<recipient@example.com>
184 RCPT TO:<recipient2@example.com>
186 To: recipient@example.com
187 Cc: recipient2@example.com
188 From: sender@localhost
196 test_mhmail "$expected" \
197 "-from sender@localhost -cc recipient2@example.com" '|' message
198 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
201 # check -from and multiple -cc addresses
202 # Verified same behavior as compiled mhmail.
203 cat > "$expected" <<EOF
204 EHLO nosuchhost.example.com
205 MAIL FROM:<sender@localhost>
206 RCPT TO:<recipient@example.com>
207 RCPT TO:<recipient2@example.com>
208 RCPT TO:<recipient3@example.com>
209 RCPT TO:<recipient4@example.com>
211 To: recipient@example.com
212 Cc: recipient2@example.com, recipient3@example.com,
213 recipient4@example.com
214 From: sender@localhost
222 test_mhmail "$expected" \
223 "-from sender@localhost -cc recipient2@example.com recipient3@example.com recipient4@example.com" '|' message
224 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
227 # check -from and -subject
228 # Verified same behavior as compiled mhmail.
229 cat > "$expected" <<EOF
230 EHLO nosuchhost.example.com
231 MAIL FROM:<sender@localhost>
232 RCPT TO:<recipient@example.com>
234 To: recipient@example.com
236 From: sender@localhost
244 test_mhmail "$expected" \
245 "-from sender@localhost -subject Test" '|' message
246 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
249 # check -from and -profile
250 # Show that -profile causes mhmail to 1) read the profile and
251 # 2) use send(1) by added a send switch to the profile and
252 # verifying that it gets used.
253 # Not supported by compiled mhmail.
254 printf "send: -msgid\n" >> $MH
256 cat > "$expected" <<EOF
257 EHLO nosuchhost.example.com
258 MAIL FROM:<sender@localhost>
259 RCPT TO:<recipient@example.com>
261 To: recipient@example.com
262 From: sender@localhost
271 test_mhmail "$expected" \
272 "-from sender@localhost -profile" '|' message
273 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
276 # check repeated -from and -subject arguments
277 # Verified same behavior as compiled mhmail.
278 cat > "$expected" <<EOF
279 EHLO nosuchhost.example.com
280 MAIL FROM:<sender2@localhost>
281 RCPT TO:<recipient@example.com>
283 To: recipient@example.com
285 From: sender2@localhost
293 test_mhmail "$expected" "-from sender@localhost -from sender2@localhost \
294 -subject Subject1 -subject Subject2" -b message
295 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
297 # check repeated -body arguments
298 # Verified same behavior as compiled mhmail.
299 cat > "$expected" <<EOF
300 EHLO nosuchhost.example.com
301 MAIL FROM:<sender@localhost>
302 RCPT TO:<recipient@example.com>
304 To: recipient@example.com
305 From: sender@localhost
313 test_mhmail "$expected" "-from sender@localhost -body body1" -b body2
314 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
317 # check multiple -cc arguments
318 # Verified same behavior as compiled mhmail.
319 cat > "$expected" <<EOF
320 EHLO nosuchhost.example.com
321 MAIL FROM:<sender@localhost>
322 RCPT TO:<recipient@example.com>
323 RCPT TO:<cc1@example.com>
324 RCPT TO:<cc2@example.com>
326 To: recipient@example.com
327 Cc: cc1@example.com, cc2@example.com
328 From: sender@localhost
336 test_mhmail "$expected" "-from sender@localhost \
337 -cc cc1@example.com -cc cc2@example.com" -b message
338 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
341 # check separated -cc arguments
342 # Verified same behavior as compiled mhmail.
343 cat > "$expected" <<EOF
344 EHLO nosuchhost.example.com
345 MAIL FROM:<sender@localhost>
346 RCPT TO:<recipient@example.com>
347 RCPT TO:<cc1@example.com>
348 RCPT TO:<cc2@example.com>
350 To: recipient@example.com
351 Cc: cc1@example.com, cc2@example.com
353 From: sender@localhost
361 test_mhmail "$expected" "-from sender@localhost \
362 -cc cc1@example.com -subject Test cc2@example.com" -b message
363 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
366 # check with no newline on stdin
367 # Shows different behavior than compiled mhmail, which was silent in this case.
368 cat > "$expected" <<EOF
371 cat > "$expected_err" <<EOF
372 mhmail: empty message not sent, use -body '' to force.
376 printf '' | mhmail recipient@example.com -server 127.0.0.1 -port $localport \
377 >"$actual" 2>"$actual_err"
380 check "$expected" "$actual"
381 check "$expected_err" "$actual_err"
382 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
385 # check with one newline on stdin
386 # Verified same behavior as compiled mhmail.
387 cat > "$expected" <<EOF
388 EHLO nosuchhost.example.com
389 MAIL FROM:<sender@localhost>
390 RCPT TO:<recipient@example.com>
392 To: recipient@example.com
393 From: sender@localhost
401 test_mhmail "$expected" "-from sender@localhost" '|' '\n'
402 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
405 # check with multiple newlines on stdin
406 # Verified same behavior as compiled mhmail.
407 cat > "$expected" <<EOF
408 EHLO nosuchhost.example.com
409 MAIL FROM:<sender@localhost>
410 RCPT TO:<recipient@example.com>
412 To: recipient@example.com
413 From: sender@localhost
423 test_mhmail "$expected" "-from sender@localhost" '|' '\n\n\n'
424 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
427 # check with text and no trailing newline on stdin
428 # Verified same behavior as compiled mhmail.
429 cat > "$expected" <<EOF
430 EHLO nosuchhost.example.com
431 MAIL FROM:<sender@localhost>
432 RCPT TO:<recipient@example.com>
434 To: recipient@example.com
435 From: sender@localhost
443 test_mhmail "$expected" "-from sender@localhost" '|' 'no newline in input'
444 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
447 # check with text and multiple trailing blank lines on stdin
448 # Verified same behavior as compiled mhmail.
449 cat > "$expected" <<EOF
450 EHLO nosuchhost.example.com
451 MAIL FROM:<sender@localhost>
452 RCPT TO:<recipient@example.com>
454 To: recipient@example.com
455 From: sender@localhost
465 test_mhmail "$expected" "-from sender@localhost" '|' "here's some text\n\n\n"
466 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
469 # check with no newline to -body
470 # Verified same behavior as compiled mhmail.
471 cat > "$expected" <<EOF
472 EHLO nosuchhost.example.com
473 MAIL FROM:<sender@localhost>
474 RCPT TO:<recipient@example.com>
476 To: recipient@example.com
477 From: sender@localhost
485 test_mhmail "$expected" "-from sender@localhost" -b ''
486 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
489 # check with one newline to -body
490 # Shows different behavior than compiled mhmail, which suppressed the newline.
491 cat > "$expected" <<EOF
492 EHLO nosuchhost.example.com
493 MAIL FROM:<sender@localhost>
494 RCPT TO:<recipient@example.com>
496 To: recipient@example.com
497 From: sender@localhost
506 test_mhmail "$expected" "-from sender@localhost" -b '
508 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
511 # check with multiple newlines to -body
512 # Shows different behavior than compiled mhmail, which suppressed one
514 cat > "$expected" <<EOF
515 EHLO nosuchhost.example.com
516 MAIL FROM:<sender@localhost>
517 RCPT TO:<recipient@example.com>
519 To: recipient@example.com
520 From: sender@localhost
531 test_mhmail "$expected" "-from sender@localhost" -b '
535 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
538 # check with text and no trailing newline to -body
539 # Verified same behavior as compiled mhmail.
540 cat > "$expected" <<EOF
541 EHLO nosuchhost.example.com
542 MAIL FROM:<sender@localhost>
543 RCPT TO:<recipient@example.com>
545 To: recipient@example.com
546 From: sender@localhost
554 test_mhmail "$expected" "-from sender@localhost" -b 'no newline in input'
555 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
558 # check with text and multiple trailing blank lines to -body
559 # Shows different behavior than compiled mhmail, which suppressed one
561 cat > "$expected" <<EOF
562 EHLO nosuchhost.example.com
563 MAIL FROM:<sender@localhost>
564 RCPT TO:<recipient@example.com>
566 To: recipient@example.com
567 From: sender@localhost
577 test_mhmail "$expected" "-from sender@localhost" -b "here's some text
580 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
584 # Verified same behavior as compiled mhmail.
585 cat > "$expected" <<EOF
586 EHLO nosuchhost.example.com
587 MAIL FROM:<recipient@example.com>
588 RCPT TO:<recipient@example.com>
590 Resent-To: recipient@example.com
591 Resent-From: recipient@example.com
592 To: recipient@example.com
593 From: sender@localhost
597 please resend this message
603 test_mhmail "$expected" "-from recipient@example.com -resent" \
604 -b "To: recipient@example.com
605 From: sender@localhost
606 Date: Sat Jun 16 18:35:15 -0500
608 please resend this message
611 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}