]> diplodocus.org Git - nmh/blob - test/format/test-mymbox
Fixed extra and missing trailing commas in SEE ALSO sections of man pages.
[nmh] / 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=`run_prog ${MH_LIBEXEC_DIR}/ap -format '%(me)' 0`
21 set +e
22 host=`${MH_OBJ_DIR}/test/getcanon`
23 set -e
24
25 output=`run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${user}"`
26 run_test "echo $output" 1 "Basic user test"
27 output=`run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${user}@${host}"`
28 run_test "echo $output" 1 "Basic user@host test"
29 run_test "${MH_LIBEXEC_DIR}/ap -format %(mymbox{text}) nosuchuser@nosuchhost.blah" \
30 0 "Basic non-matching test"
31
32 myname="Random User <random@user.something.com>"
33
34 #### Remove existing Local-Mailbox: profile component, if any. Then
35 #### add one.
36 grep -v 'Local-Mailbox: ' "$MH" > "$MH".new
37 mv -f "$MH".new "$MH"
38 echo "Local-Mailbox: ${myname}" >> "$MH"
39
40 run_test "echo \
41 `run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${myname}"`" \
42 1 "Local-Mailbox test"
43
44 output=`run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${user}@${host}"`
45 run_test "echo $output" 0 "Local-mailbox overriding user@host test"
46
47 # Add an Alternate-Mailbox. This caused ismymbox() to lose the
48 # Local-Mailbox, Bug #36635: -nocc me doesn't account for
49 # Alternate-Mailboxes.
50 printf 'Alternate-Mailboxes: user@example.com\n' >> $MH
51 run_test "echo \
52 `run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${myname}"`" \
53 1 "Local-Mailbox with Alternate-Mailbox test"
54
55 # check getmymbox, without match
56 run_test 'fmttest -message -format %(getmymbox{from}) first' ''
57
58 # check getmyaddr, without match
59 run_test 'fmttest -message -format %(getmyaddr{from}) first' ''
60
61 grep -v 'Alternate-Mailboxes: ' "$MH" > "$MH".new
62 mv -f "$MH".new "$MH"
63 cat >>"$MH" <<EOF
64 Alternate-Mailboxes: test1@example.com
65 EOF
66
67 # check getmymbox, with match
68 run_test 'fmttest -message -format %(getmymbox{from}) first' \
69 'Test1 <test1@example.com>'
70
71 # check getmyaddr, with match
72 run_test 'fmttest -message -format %(getmyaddr{from}) first' \
73 'test1@example.com'
74
75 # check getmymbox and getmyaddr, with match of other than first address in
76 # component
77 cat >`mhpath new` <<'EOF'
78 From: Test11 <test11@example.com>
79 Cc: Test0 <test0@example.com>, Test3 <test3@example.com>,
80 Test1 <test1@example.com>, Test2 <test2@example.com>
81 To: Some User <user@example.com>
82 Date: Fri, 29 Sep 2006 00:00:00
83 Message-Id: 11@test.nmh
84 Subject: Testing message 11
85
86 This is message number 11
87 EOF
88 run_test 'fmttest -message -format %(getmymbox{cc}) last' \
89 'Test1 <test1@example.com>'
90 run_test 'fmttest -message -format %(getmyaddr{cc}) last' \
91 'test1@example.com'
92
93 exit $failed