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]]
87 and all post(8)/send(1) switches
90 mhmail -help >$actual 2>&1
91 check $expected $actual
95 # Verified same behavior as compiled mhmail.
98 * ) echo "$0: mhmail -v generated unexpected output" 1>&2
99 failed=`expr ${failed:-0} + 1`;;
103 # check with no arguments
104 # That will just run inc, which we don't want to do anything,
105 # so tell inc to just display its version.
106 # Verified same behavior as compiled mhmail.
107 printf "inc: -version\n" >> $MH
110 * ) echo "$0: mhmail generated unexpected output" 1>&2
111 failed=`expr ${failed:-0} + 1`;;
116 # Not supported by compiled mhmail.
117 mhmail -nosend recipient@example.com -from sender@localhost \
118 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
120 tmpfil=`head -1 $actual | sed -e 's/://'`
122 cat > "$expected" <<EOF
123 To: recipient@example.com
124 From: sender@localhost
129 cat > "$expected_err" <<EOF
132 check "$expected" "$actual"
133 check "$expected_err" "$actual_err"
134 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
138 # Not supported by compiled mhmail.
139 cat > "$expected" <<EOF
140 EHLO nosuchhost.example.com
141 MAIL FROM:<sender@localhost>
142 RCPT TO:<recipient@example.com>
144 To: recipient@example.com
145 From: sender@localhost
153 test_mhmail "$expected" "-from sender@localhost -nosend -send" '|' message
154 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
158 # Verified same behavior as compiled mhmail.
159 cat > "$expected" <<EOF
160 EHLO nosuchhost.example.com
161 MAIL FROM:<sender@localhost>
162 RCPT TO:<recipient@example.com>
164 To: recipient@example.com
165 From: sender@localhost
173 test_mhmail "$expected" "-from sender@localhost" '|' message
174 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
177 # check -from and -body
178 # Verified same behavior as compiled mhmail.
179 cat > "$expected" <<EOF
180 EHLO nosuchhost.example.com
181 MAIL FROM:<sender@localhost>
182 RCPT TO:<recipient@example.com>
184 To: recipient@example.com
185 From: sender@localhost
193 test_mhmail "$expected" "-from sender@localhost" -b body
194 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
197 # check -from and -cc
198 # Verified same behavior as compiled mhmail.
199 cat > "$expected" <<EOF
200 EHLO nosuchhost.example.com
201 MAIL FROM:<sender@localhost>
202 RCPT TO:<recipient@example.com>
203 RCPT TO:<recipient2@example.com>
205 To: recipient@example.com
206 Cc: recipient2@example.com
207 From: sender@localhost
215 test_mhmail "$expected" \
216 "-from sender@localhost -cc recipient2@example.com" '|' message
217 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
220 # check -from and multiple -cc addresses
221 # Verified same behavior as compiled mhmail.
222 cat > "$expected" <<EOF
223 EHLO nosuchhost.example.com
224 MAIL FROM:<sender@localhost>
225 RCPT TO:<recipient@example.com>
226 RCPT TO:<recipient2@example.com>
227 RCPT TO:<recipient3@example.com>
228 RCPT TO:<recipient4@example.com>
230 To: recipient@example.com
231 Cc: recipient2@example.com, recipient3@example.com,
232 recipient4@example.com
233 From: sender@localhost
241 test_mhmail "$expected" \
242 "-from sender@localhost -cc recipient2@example.com recipient3@example.com recipient4@example.com" '|' message
243 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
246 # check -from and -subject
247 # Verified same behavior as compiled mhmail.
248 cat > "$expected" <<EOF
249 EHLO nosuchhost.example.com
250 MAIL FROM:<sender@localhost>
251 RCPT TO:<recipient@example.com>
253 To: recipient@example.com
255 From: sender@localhost
263 test_mhmail "$expected" \
264 "-from sender@localhost -subject Test" '|' message
265 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
268 # check -from and -profile
269 # Show that -profile causes mhmail to 1) read the profile and
270 # 2) use send(1) by added a send switch to the profile and
271 # verifying that it gets used.
272 # Not supported by compiled mhmail.
273 printf "send: -msgid\n" >> $MH
275 cat > "$expected" <<EOF
276 EHLO nosuchhost.example.com
277 MAIL FROM:<sender@localhost>
278 RCPT TO:<recipient@example.com>
280 To: recipient@example.com
281 From: sender@localhost
290 test_mhmail "$expected" \
291 "-from sender@localhost -profile" '|' message
292 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
295 # check repeated -from and -subject arguments
296 # Verified same behavior as compiled mhmail.
297 cat > "$expected" <<EOF
298 EHLO nosuchhost.example.com
299 MAIL FROM:<sender2@localhost>
300 RCPT TO:<recipient@example.com>
302 To: recipient@example.com
304 From: sender2@localhost
312 test_mhmail "$expected" "-from sender@localhost -from sender2@localhost \
313 -subject Subject1 -subject Subject2" -b message
314 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
316 # check repeated -body arguments
317 # Verified same behavior as compiled mhmail.
318 cat > "$expected" <<EOF
319 EHLO nosuchhost.example.com
320 MAIL FROM:<sender@localhost>
321 RCPT TO:<recipient@example.com>
323 To: recipient@example.com
324 From: sender@localhost
332 test_mhmail "$expected" "-from sender@localhost -body body1" -b body2
333 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
336 # check multiple -cc arguments
337 # Verified same behavior as compiled mhmail.
338 cat > "$expected" <<EOF
339 EHLO nosuchhost.example.com
340 MAIL FROM:<sender@localhost>
341 RCPT TO:<recipient@example.com>
342 RCPT TO:<cc1@example.com>
343 RCPT TO:<cc2@example.com>
345 To: recipient@example.com
346 Cc: cc1@example.com, cc2@example.com
347 From: sender@localhost
355 test_mhmail "$expected" "-from sender@localhost \
356 -cc cc1@example.com -cc cc2@example.com" -b message
357 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
360 # check separated -cc arguments
361 # Verified same behavior as compiled mhmail.
362 cat > "$expected" <<EOF
363 EHLO nosuchhost.example.com
364 MAIL FROM:<sender@localhost>
365 RCPT TO:<recipient@example.com>
366 RCPT TO:<cc1@example.com>
367 RCPT TO:<cc2@example.com>
369 To: recipient@example.com
370 Cc: cc1@example.com, cc2@example.com
372 From: sender@localhost
380 test_mhmail "$expected" "-from sender@localhost \
381 -cc cc1@example.com -subject Test cc2@example.com" -b message
382 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
385 # check with no newline on stdin
386 # Shows different behavior than compiled mhmail, which was silent in this case.
387 cat > "$expected" <<EOF
390 cat > "$expected_err" <<EOF
391 mhmail: empty message not sent, use -body '' to force.
395 printf '' | mhmail recipient@example.com -server 127.0.0.1 -port $localport \
396 >"$actual" 2>"$actual_err"
399 check "$expected" "$actual"
400 check "$expected_err" "$actual_err"
401 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
404 # check with one newline on stdin
405 # Verified same behavior as compiled mhmail.
406 cat > "$expected" <<EOF
407 EHLO nosuchhost.example.com
408 MAIL FROM:<sender@localhost>
409 RCPT TO:<recipient@example.com>
411 To: recipient@example.com
412 From: sender@localhost
420 test_mhmail "$expected" "-from sender@localhost" '|' '\n'
421 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
424 # check with multiple newlines on stdin
425 # Verified same behavior as compiled mhmail.
426 cat > "$expected" <<EOF
427 EHLO nosuchhost.example.com
428 MAIL FROM:<sender@localhost>
429 RCPT TO:<recipient@example.com>
431 To: recipient@example.com
432 From: sender@localhost
442 test_mhmail "$expected" "-from sender@localhost" '|' '\n\n\n'
443 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
446 # check with text and no trailing newline on stdin
447 # Verified same behavior as compiled mhmail.
448 cat > "$expected" <<EOF
449 EHLO nosuchhost.example.com
450 MAIL FROM:<sender@localhost>
451 RCPT TO:<recipient@example.com>
453 To: recipient@example.com
454 From: sender@localhost
462 test_mhmail "$expected" "-from sender@localhost" '|' 'no newline in input'
463 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
466 # check with text and multiple trailing blank lines on stdin
467 # Verified same behavior as compiled mhmail.
468 cat > "$expected" <<EOF
469 EHLO nosuchhost.example.com
470 MAIL FROM:<sender@localhost>
471 RCPT TO:<recipient@example.com>
473 To: recipient@example.com
474 From: sender@localhost
484 test_mhmail "$expected" "-from sender@localhost" '|' "here's some text\n\n\n"
485 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
488 # check with no newline to -body
489 # Verified same behavior as compiled mhmail.
490 cat > "$expected" <<EOF
491 EHLO nosuchhost.example.com
492 MAIL FROM:<sender@localhost>
493 RCPT TO:<recipient@example.com>
495 To: recipient@example.com
496 From: sender@localhost
504 test_mhmail "$expected" "-from sender@localhost" -b ''
505 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
508 # check with one newline to -body
509 # Shows different behavior than compiled mhmail, which suppressed the newline.
510 cat > "$expected" <<EOF
511 EHLO nosuchhost.example.com
512 MAIL FROM:<sender@localhost>
513 RCPT TO:<recipient@example.com>
515 To: recipient@example.com
516 From: sender@localhost
525 test_mhmail "$expected" "-from sender@localhost" -b '
527 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
530 # check with multiple newlines to -body
531 # Shows different behavior than compiled mhmail, which suppressed one
533 cat > "$expected" <<EOF
534 EHLO nosuchhost.example.com
535 MAIL FROM:<sender@localhost>
536 RCPT TO:<recipient@example.com>
538 To: recipient@example.com
539 From: sender@localhost
550 test_mhmail "$expected" "-from sender@localhost" -b '
554 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
557 # check with text and no trailing newline to -body
558 # Verified same behavior as compiled mhmail.
559 cat > "$expected" <<EOF
560 EHLO nosuchhost.example.com
561 MAIL FROM:<sender@localhost>
562 RCPT TO:<recipient@example.com>
564 To: recipient@example.com
565 From: sender@localhost
573 test_mhmail "$expected" "-from sender@localhost" -b 'no newline in input'
574 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
577 # check with text and multiple trailing blank lines to -body
578 # Shows different behavior than compiled mhmail, which suppressed one
580 cat > "$expected" <<EOF
581 EHLO nosuchhost.example.com
582 MAIL FROM:<sender@localhost>
583 RCPT TO:<recipient@example.com>
585 To: recipient@example.com
586 From: sender@localhost
596 test_mhmail "$expected" "-from sender@localhost" -b "here's some text
599 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
603 # Verified same behavior as compiled mhmail.
604 cat > "$expected" <<EOF
605 EHLO nosuchhost.example.com
606 MAIL FROM:<recipient@example.com>
607 RCPT TO:<recipient@example.com>
609 Resent-To: recipient@example.com
610 Resent-From: recipient@example.com
611 To: recipient@example.com
612 From: sender@localhost
616 please resend this message
622 test_mhmail "$expected" "-from recipient@example.com -resent" \
623 -b "To: recipient@example.com
624 From: sender@localhost
625 Date: Sat Jun 16 18:35:15 -0500
627 please resend this message
630 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}