Debian Codegraph @

test/format/test-mymbox

raw
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 #### Remove existing Local-Mailbox: profile component, if any.
17 grep -v 'Local-Mailbox: ' "$MH" > "$MH".new
18 mv -f "$MH".new "$MH"
19
20 user=`id -nu`
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}) [email protected]" \
30 0 "Basic non-matching test"
31
32 myname="Random User <[email protected]>"
33
34 #### Add Local-Mailbox profile component.
35 echo "Local-Mailbox: ${myname}" >> "$MH"
36
37 run_test "echo \
38 `run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${myname}"`" \
39 1 "Local-Mailbox test"
40
41 output=`run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${user}@${host}"`
42 run_test "echo $output" 0 "Local-Mailbox overriding user@host test"
43
44 #### Test getusername() when there is a Local-Mailbox profile component.
45 run_test 'fmttest -raw -format %(me) ""' "${user}"
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: [email protected]\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 start_test "getmymbox, without match"
57 run_test 'fmttest -message -format %(getmymbox{from}) first' ''
58
59 # check getmyaddr, without match
60 start_test "getmyaddr, without match"
61 run_test 'fmttest -message -format %(getmyaddr{from}) first' ''
62
63 grep -v 'Alternate-Mailboxes: ' "$MH" > "$MH".new
64 mv -f "$MH".new "$MH"
65 cat >>"$MH" <<EOF
66 Alternate-Mailboxes: [email protected]
67 EOF
68
69 # check getmymbox, with match
70 start_test "getmymbox, with match"
71 run_test 'fmttest -message -format %(getmymbox{from}) first' \
72 'Test1 <[email protected]>'
73
74 # check getmyaddr, with match
75 start_test "getmyaddr, with match"
76 run_test 'fmttest -message -format %(getmyaddr{from}) first' \
77 '[email protected]'
78
79 # check getmymbox and getmyaddr, with match of other than first address in
80 start_test "getmymbox and getmyaddr, with match of other than first address in"
81 # component
82 cat >`mhpath new` <<'EOF'
83 From: Test11 <[email protected]>
84 Cc: Test0 <[email protected]>, Test3 <[email protected]>,
85 Test1 <[email protected]>, Test2 <[email protected]>
86 To: Some User <[email protected]>
87 Date: Fri, 29 Sep 2006 00:00:00
88 Message-Id: [email protected]
89 Subject: Testing message 11
90
91 This is message number 11
92 EOF
93 run_test 'fmttest -message -format %(getmymbox{cc}) last' \
94 'Test1 <[email protected]>'
95 run_test 'fmttest -message -format %(getmyaddr{cc}) last' \
96 '[email protected]'
97
98 finish_test
99 exit $failed