Fixed printf's in test suite.
[mmh] / test / format / test-mymbox
1 #!/bin/sh
2 #
3 # Test that the %(mymbox) function correctly determines whether or not
4 # a particular email address is "mine" or not
5 #
6
7 if test -z "${MH_OBJ_DIR}"; then
8     srcdir=`dirname "$0"`/../..
9     MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
10 fi
11
12 . "$MH_OBJ_DIR/test/common.sh"
13
14 setup_test
15
16 #### Use ap to get the username.  That will either be what's in the
17 #### Local-Mailbox profile component, which we don't use in the test
18 #### suite, or the user's login name.  ap will escape (quote) it if
19 #### needed.
20 user=`${MH_LIB_DIR}/ap -format '%(me)' 0`
21 host=`${MH_OBJ_DIR}/test/getfqdn`
22
23 output=`${MH_LIB_DIR}/ap -format '%(mymbox{text})' "${user}"`
24 run_test "echo $output" 1 "Basic user test"
25 output=`${MH_LIB_DIR}/ap -format '%(mymbox{text})' "${user}@${host}"`
26 run_test "echo $output" 1 "Basic user@host test"
27 run_test "${MH_LIB_DIR}/ap -format %(mymbox{text}) nosuchuser@nosuchhost.blah" \
28          0 "Basic non-matching test"
29
30 myname="Random User <random@user.something.com>"
31
32 #### Remove existing Local-Mailbox: profile component, if any.  Then
33 #### add one.
34 grep -v 'Local-Mailbox: ' ${MH} > ${MH}.new
35 mv -f ${MH}.new ${MH}
36 echo "Local-Mailbox: ${myname}" >> ${MH}
37
38 run_test "echo `${MH_LIB_DIR}/ap -format '%(mymbox{text})' "${myname}"`" \
39          1 "Local-Mailbox test"
40
41 output=`${MH_LIB_DIR}/ap -format '%(mymbox{text})' "${user}@${host}"`
42 run_test "echo $output" 0 "Local-mailbox overriding user@host test"
43
44 # Add an Alternate-Mailbox.  This caused ismymbox() to lose the
45 # Local-Mailbox, Bug #36635: -nocc me doesn't account for
46 # Alternate-Mailboxes.
47 printf 'Alternate-Mailboxes: user@example.com\n' >> $MH
48 run_test "echo `${MH_LIB_DIR}/ap -format '%(mymbox{text})' "${myname}"`" \
49          1 "Local-Mailbox with Alternate-Mailbox test"
50
51 exit $failed