. functions

echo "Testing the nullmailer-smtpd program"

out=$tmpdir/smtpd.out.$$

smtpd <<EOF 2>&1 | cat -v >$out
HELO
HELO somebody
EHLO
EHLO somebody
HELP
HELP something
DATA
RCPT
RCPT TO:<r@example.com>
MAIL
MAIL FROM:<f@example.com>
RCPT
RCPT TO:<r@example.com>
RSET
RCPT TO:<r@example.com>
MAIL FROM:<>
RSET
MAIL FROM:<f0@example.com>
RCPT TO:<r0@example.com>
mail from f@example.com
rcpt to r@example.com
rcpt <@example.org:r2@example.com>
DATA
Subject: test

testing SMTP
.line 2
..line 3
.
QUIT
QUIT
EOF

diff -u - $out <<EOF
220 nullmailer-smtpd ready^M
501 5.5.2 Syntax error, command requires a parameter^M
250 2.3.0 OK^M
501 5.5.2 Syntax error, command requires a parameter^M
250 2.3.0 OK^M
214 2.0.0 Help not available^M
214 2.0.0 Help not available^M
503 5.5.1 You must send a valid sender first^M
501 5.5.2 Syntax error, command requires a parameter^M
503 5.5.1 You must send a valid sender first^M
501 5.5.2 Syntax error, command requires a parameter^M
250 2.1.0 Sender accepted^M
501 5.5.2 Syntax error, command requires a parameter^M
250 2.1.5 Recipient accepted^M
250 2.3.0 OK^M
503 5.5.1 You must send a valid sender first^M
250 2.1.0 Sender accepted^M
250 2.3.0 OK^M
250 2.1.0 Sender accepted^M
250 2.1.5 Recipient accepted^M
250 2.1.0 Sender accepted^M
250 2.1.5 Recipient accepted^M
250 2.1.5 Recipient accepted^M
354 End your message with a period on a line by itself^M
250 2.6.0 Accepted message^M
221 2.0.0 Good bye^M
EOF

echo '  testing queued message envelope'
qf=$QUEUEDIR/queue/*
grep -q '^f@example.com$' $qf
grep -q '^r@example.com$' $qf
grep -q '^r2@example.com$' $qf
not grep -q '^f0@example.com$' $qf
not grep -q '^r0@example.com$' $qf
echo '  testing queued message contents'
grep -q '^Subject: test$' $qf
grep -q '^Received: ' $qf
grep -q '^testing SMTP$' $qf
grep -q '^line 2$' $qf
grep -q '^\.line 3$' $qf
test $( wc -l < $qf ) = 11
test $( wc -w < $qf ) = 25
