]> diplodocus.org Git - nmh/blob - test/format/test-mymbox
Allow a RRULE in an iCalendar request to not have an INTERVAL on its
[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 host=`${MH_OBJ_DIR}/test/getcanon`
22
23 output=`run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${user}"`
24 run_test "echo $output" 1 "Basic user test"
25 output=`run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${user}@${host}"`
26 run_test "echo $output" 1 "Basic user@host test"
27 run_test "${MH_LIBEXEC_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 \
39 `run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${myname}"`" \
40 1 "Local-Mailbox test"
41
42 output=`run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${user}@${host}"`
43 run_test "echo $output" 0 "Local-mailbox overriding user@host test"
44
45 # Add an Alternate-Mailbox. This caused ismymbox() to lose the
46 # Local-Mailbox, Bug #36635: -nocc me doesn't account for
47 # Alternate-Mailboxes.
48 printf 'Alternate-Mailboxes: user@example.com\n' >> $MH
49 run_test "echo \
50 `run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${myname}"`" \
51 1 "Local-Mailbox with Alternate-Mailbox test"
52
53 # check getmymbox, without match
54 run_test 'fmttest -message -format %(getmymbox{from}) first' ''
55
56 # check getmyaddr, without match
57 run_test 'fmttest -message -format %(getmyaddr{from}) first' ''
58
59 grep -v 'Alternate-Mailboxes: ' "$MH" > "$MH".new
60 mv -f "$MH".new "$MH"
61 cat >>"$MH" <<EOF
62 Alternate-Mailboxes: test1@example.com
63 EOF
64
65 # check getmymbox, with match
66 run_test 'fmttest -message -format %(getmymbox{from}) first' \
67 'Test1 <test1@example.com>'
68
69 # check getmyaddr, with match
70 run_test 'fmttest -message -format %(getmyaddr{from}) first' \
71 'test1@example.com'
72
73 # check getmymbox and getmyaddr, with match of other than first address in
74 # component
75 cat >`mhpath new` <<'EOF'
76 From: Test11 <test11@example.com>
77 Cc: Test0 <test0@example.com>, Test3 <test3@example.com>,
78 Test1 <test1@example.com>, Test2 <test2@example.com>
79 To: Some User <user@example.com>
80 Date: Fri, 29 Sep 2006 00:00:00
81 Message-Id: 11@test.nmh
82 Subject: Testing message 11
83
84 This is message number 11
85 EOF
86 run_test 'fmttest -message -format %(getmymbox{cc}) last' \
87 'Test1 <test1@example.com>'
88 run_test 'fmttest -message -format %(getmyaddr{cc}) last' \
89 'test1@example.com'
90
91 exit $failed