2 ######################################################
6 ######################################################
10 if test -z "${MH_OBJ_DIR}"; then
11 srcdir=`dirname $0`/../..
12 MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
15 . "$MH_OBJ_DIR/test/common.sh"
19 expected=$MH_TEST_DIR/$$.expected
20 actual=$MH_TEST_DIR/$$.actual
22 # Add an 11th message.
25 -e 's/^To:\(.*\)/To:\1\
26 Cc: <another@example.com>/' \
27 -e 's/^\(Date:.*\)2006\( 00:00:\)00/\12008\200\
28 Delivery-Date: \12009\241/' \
29 $MH_TEST_DIR/Mail/inbox/10 >$MH_TEST_DIR/Mail/inbox/11
31 # Test message specification.
32 run_test 'pick first last' '1
36 run_test 'pick -subject message.3 -and -from Test3' '3'
37 run_test 'pick -subject message.3 -and -from Test4' \
38 'pick: no messages match specification
42 run_test 'pick -subject message.3 -or -from Test3' '3'
43 run_test 'pick -subject message.3 -or -from Test4' '3
47 run_test 'pick -not -subject message.8 last:5' '7
52 # Test -lbrace, -rbrace.
53 run_test 'pick -subject message.12 -and -subject message.3 -or -from Test4' '4'
54 run_test 'pick -subject message.12 -and -lbrace -subject message.3 -rbrace' \
55 'pick: no messages match specification
58 # -and takes precedence over -or.
59 run_test 'pick -subject message.12 -or -subject message.3 -and -from Test3' '3'
60 run_test 'pick -subject message.12 -or -subject message.3 -and -from Test4' \
61 'pick: no messages match specification
64 # -not takes precedence over -and.
65 run_test 'pick -not -subject message.12 -and -subject message.3' '3'
66 run_test 'pick -not -lbrace -subject NoMatch -and -subject message.3 -rbrace' \
80 # Don't use run_prog here because it loses the environment setting.
81 MHPDEBUG=1 pick -not -lbrace -subject NoMatch -and -subject message.3 -rbrace \
82 >/dev/null 2>"$actual"
83 cat >"$expected" <<EOF
86 | | PATTERN(header) ^subject[ ]*:.*NoMatch
87 | | PATTERN(header) ^subject[ ]*:.*message.3
89 check "$expected" "$actual"
93 # Produce 0 if no messages match and standard output is not a tty.
94 # Note that there is an error message on stderr, but it's redirected
97 `run_prog pick -subject message.3 -and -from Test4 >"$actual" 2>/dev/null` \
99 cat >"$expected" <<EOF
102 check "$expected" "$actual"
104 if test -t 1 && (printf '' >/dev/tty) 2>/dev/null; then
105 # Produce no standard output if no messages match and standard
106 # output is a tty. To test that even when run with stdout
107 # detached, write directly to /dev/tty. Can't capture the
108 # output so hopefully the user will notice it.
109 run_prog pick -subject message.3 -and -from Test4 >/dev/tty 2>/dev/null
112 # Also, check that the exit status is 1.
113 run_prog pick -subject message.3 -and -from Test4 >/dev/null 2>&1
114 run_test "echo $?" '1'
119 run_test 'pick -cc another' '11'
122 run_test 'pick -date 29.Sep.2008' '11'
125 run_test 'pick -from test7' '7'
128 run_test 'pick -search This.is.message.number.[456]' '4
133 run_test 'pick -subject message.2' '2'
136 run_test 'pick -to some -nolist' '11 hits'
137 run_test 'pick -to user@example.com -nolist' '11 hits'
140 run_prog pick -after '28 Sep 2008 00:00:00' >"$actual" 2>&1
141 cat >"$expected" <<EOF
144 check "$expected" "$actual"
146 # Invert exit status so execution doesn't terminate due to -e.
148 run_prog pick -after '29 Sep 2008 00:00:00' >"$actual" 2>/dev/null
150 cat >"$expected" <<EOF
153 check "$expected" "$actual"
155 # Test -before. While -after doesn't include the specified date, -before does.
156 run_prog pick -before '29 Sep 2008 00:00:01' last:3 >"$actual" 2>&1
157 cat >"$expected" <<EOF
162 check "$expected" "$actual"
163 run_prog pick -before '28 Sep 2008 00:00:00:' last:3 >"$actual" 2>&1
164 cat >"$expected" <<EOF
168 check "$expected" "$actual"
170 run_prog pick -before '28 Sep 2006 00:00:00' last:3 >"$actual" 2>/dev/null
172 cat >"$expected" <<EOF
175 check "$expected" "$actual"
179 run_prog pick -datefield date -after '29 Sep 2008 00:00:00' \
180 >"$actual" 2>/dev/null
182 cat >"$expected" <<EOF
185 check "$expected" "$actual"
186 run_prog pick -datefield delivery-date -after '29 Sep 2008 00:00:00' \
188 cat >"$expected" <<EOF
191 check "$expected" "$actual"
193 # Test sequence creation.
194 run_test 'pick 2 4 6 8 10 -sequence even' '5 hits'
195 run_test 'mark -s even -list' 'even: 2 4 6 8 10'
197 # Test private sequence creation.
198 # Set current message for following tests.
199 folder +inbox 1 > /dev/null
200 run_test 'pick -date 29.Sep.2008 -sequence privateseq -nopublic' '1 hit'
201 run_test 'mark -list' 'cur: 1
203 privateseq (private): 11'
205 # Test add to private sequence.
206 run_test 'pick first -sequence privateseq -nozero -nopublic' '1 hit'
207 run_test 'mark -list' 'cur: 1
209 privateseq (private): 1 11'
211 # Test sequence creation, with -list.
212 run_test 'pick 5 7 -sequence odd -list' '5
214 run_test 'mark -s odd -list' 'odd: 5 7'
216 # Test sequence creation, with default of -zero.
217 run_test 'pick 1 3 -sequence odd' '2 hits'
218 run_test 'mark -s odd -list' 'odd: 1 3'
220 # Test sequence creation, with -nozero.
221 run_test 'pick 5 7 9 -sequence odd -nozero' '3 hits'
222 run_test 'mark -s odd -list' 'odd: 1 3 5 7 9'
224 # Test sequence creation, with explicit folder, -public, and -zero.
225 run_test 'pick +inbox 5 7 9 11 -public -sequence odd' '4 hits'
226 run_test 'mark -s odd -list' 'odd: 5 7 9 11'
229 run_test 'pick all -nolist' '11 hits'
231 # Test unfolding of multi-line header fields: it should only
232 # remove embedded newlines.
233 cat >"$MH_TEST_DIR/Mail/inbox/12" <<EOF
234 From: Test12 <test12@example.com>
235 To: Some User <user@example.com>
236 Date: Fri, 29 Sep 2006 00:00:00
237 Message-Id: 12@test.nmh
241 This is message number 12
246 run_prog pick -subject 'multi-line header field' 12 >"$actual" 2>&1
247 check "$expected" "$actual"
249 # Test MIME-encoded header.
250 cat >"$MH_TEST_DIR/Mail/inbox/13" <<EOF
251 From: Test13 <test13@example.com>
252 To: Some User <user@example.com>
253 Date: Fri, 29 Sep 2006 00:00:00
254 Message-Id: 13@test.nmh
255 Subject: =?us-ascii?q?=66=6f=6f?=
256 =?utf-8?q?=62=61=72?=
258 This is message number 13, with MIME-encoded Subject "foobar".
265 # Don't use run_prog here because it loses the environment setting.
266 LC_ALL=en_US.UTF-8 pick -subject foobar 13 >"$actual" 2>&1
268 check "$expected" "$actual"
271 run_test 'pick +inbox 5 7 9 11 -sequence test -nosequence' '5
275 run_test 'mark -list -sequence test' 'test: '