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 check_exit
'-eq 1' dist
-
20 check_exit
'-eq 1' dist
-editor
21 check_exit
'-eq 1' dist
-editor foo
-editor
22 check_exit
'-eq 1' dist
-nowhatnowproc -whatnowproc foo
-whatnowproc
23 check_exit
'-eq 1' dist
-file
24 check_exit
'-eq 1' dist
-file foo
-file bar
25 check_exit
'-eq 1' dist
-form
26 check_exit
'-eq 1' dist
-draftfolder
27 check_exit
'-eq 1' dist
-draftfolder foo
-draftfolder bar
28 check_exit
'-eq 1' dist
-draftmessage
29 check_exit
'-eq 1' dist
-draftmessage 42 -draftmessage 314
30 check_exit
'-eq 1' dist
-from
31 check_exit
'-eq 1' dist
-to
32 check_exit
'-eq 1' dist
-cc
33 check_exit
'-eq 1' dist
-fcc
34 check_exit
'-eq 1' dist
-width
35 check_exit
'-eq 1' dist
-width 42 -width 0
36 check_exit
'-eq 1' dist
-atfile -noatfile -
37 check_exit
'-eq 1' dist
+ @
38 check_exit
'-eq 1' dist
42 314
39 check_exit
'-eq 1' dist
-file foo
42
41 expected
=$MH_TEST_DIR/$$.expected
42 expected_err
=$MH_TEST_DIR/$$.expected_err
43 actual
=$MH_TEST_DIR/$$.actual
44 actual_err
=$MH_TEST_DIR/$$.actual_err
45 localmbox
=`${MH_LIBEXEC_DIR}/ap -format "%(localmbox)" 0 | sed 's/^<\(.*\)>$/\1/'`
47 #### Use sendmail/pipe below to override default mts.
48 mts_fakesendmail
="${MHMTSCONF}-fakesendmail"
49 sed -e 's/^mts:.*/mts: sendmail\/pipe/' "${MHMTSCONF}" > "$mts_fakesendmail"
50 printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
51 MHMTSCONF
="$mts_fakesendmail"
53 # arguments: dist switches
56 printf 'send\n' | run_prog dist
"$@" >/dev
/null
58 # fakesendmail drops the message and any cc's into this mbox.
59 mbox
="${MH_TEST_DIR}"/Mail
/fakesendmail.mbox
60 inc
-silent -file "$mbox"
63 # It's hard to calculate the exact Date: header post is going to
64 # use, so we'll just use sed to remove the actual date so we can
65 # easily compare it against our "correct" output.
66 sed -e 's/^Resent-Date:.*/Resent-Date:/' `mhpath last` > "$actual"
68 check
"$expected" "$actual"
74 cat >"$expected" <<EOF
75 Usage: dist [+folder] [msg] [switches]
97 #### Skip nmh intro text.
98 dist
-help 2>&1 | sed '/^$/,$d' >"$actual"
99 check
"$expected" "$actual"
102 start_test
"-version"
105 * ) printf '%s: dist -v generated unexpected output\n' "$0" >&2
106 failed
=`expr ${failed:-0} + 1`;;
109 # check unknown switch
110 start_test
"unknown switch"
111 run_test
"dist -nonexistent" 'dist: -nonexistent unknown'
113 folder
+outbox
-create -fast >/dev
/null
114 folder
+inbox
-fast 1 >/dev
/null
116 # For most tests, use -nowhatnow and just check that the draft
119 # check basic dist operation, including -noedit and -to
120 start_test
"basic dist operation, including -noedit and -to"
121 cat >"$expected" <<EOF
122 From: Test1 <test1@example.com>
123 To: Some User <user@example.com>
124 Date: Fri, 29 Sep 2006 00:00:00
125 Message-Id: 1@test.nmh
126 Subject: Testing message 1
127 Resent-From: ${localmbox}
128 Resent-To: somebody@example.com
131 This is message number 1
134 test_dist
-noedit -to somebody@example.com
136 # check +folder and msg
137 start_test
"+folder and msg"
138 folder
+outbox
-fast >/dev
/null
140 cat >"$expected" <<EOF
141 From: Test1 <test1@example.com>
142 To: Some User <user@example.com>
143 Date: Fri, 29 Sep 2006 00:00:00
144 Message-Id: 1@test.nmh
145 Subject: Testing message 1
146 Resent-From: ${localmbox}
147 Resent-To: somebody@example.com
150 This is message number 1
153 test_dist
+inbox
1 -noedit -to somebody@example.com
157 cat >"${MH_TEST_DIR}/Mail/distform" <<'EOF'
158 Resent-From: me@example.com
159 Resent-To: you@example.com
162 cat >"$expected" <<EOF
163 From: Test1 <test1@example.com>
164 To: Some User <user@example.com>
165 Date: Fri, 29 Sep 2006 00:00:00
166 Message-Id: 1@test.nmh
167 Subject: Testing message 1
168 Resent-From: me@example.com
169 Resent-To: you@example.com
172 This is message number 1
175 test_dist
1 -noedit -form "${MH_TEST_DIR}"/Mail
/distform
177 rm "${MH_TEST_DIR}"/Mail
/distform
180 start_test
"-annotate"
181 cat >"$expected" <<EOF
182 From: Test2 <test2@example.com>
183 To: Some User <user@example.com>
184 Date: Fri, 29 Sep 2006 00:00:00
185 Message-Id: 2@test.nmh
186 Subject: Testing message 2
187 Resent-From: ${localmbox}
188 Resent-To: somebody@example.com
191 This is message number 2
194 test_dist
2 -noedit -to somebody@example.com
-annotate
196 cat >"$expected" <<EOF
198 Resent: somebody@example.com
199 From: Test2 <test2@example.com>
200 To: Some User <user@example.com>
201 Date: Fri, 29 Sep 2006 00:00:00
202 Message-Id: 2@test.nmh
203 Subject: Testing message 2
205 This is message number 2
208 # The annotation is done by a separate process, so we need to wait for
211 until grep '^Resent:' "${MH_TEST_DIR}"/Mail
/inbox
/2 >/dev
/null
; do
215 if [ $i -gt 60 ]; then
216 printf '%s: -annotate failed, will not wait any longer\n' "$0"
221 # Strip date from line of this form:
222 # Resent: Sat, 06 Oct 2012 08:24:08 -0500
223 sed -e 's/^Resent:.*:.*/Resent:/' "${MH_TEST_DIR}"/Mail
/inbox
/2 >"$actual"
225 check
"$expected" "$actual"
228 start_test
"-noannotate"
229 cat >"$expected" <<EOF
230 From: Test1 <test1@example.com>
231 To: Some User <user@example.com>
232 Date: Fri, 29 Sep 2006 00:00:00
233 Message-Id: 1@test.nmh
234 Subject: Testing message 1
235 Resent-From: ${localmbox}
236 Resent-To: somebody@example.com
239 This is message number 1
242 test_dist
1 -noedit -to somebody@example.com
-annotate -noannotate
244 cat >"$expected" <<EOF
245 From: Test1 <test1@example.com>
246 To: Some User <user@example.com>
247 Date: Fri, 29 Sep 2006 00:00:00
248 Message-Id: 1@test.nmh
249 Subject: Testing message 1
251 This is message number 1
254 check
"${MH_TEST_DIR}"/Mail
/inbox
/1 "$expected" 'keep first'
257 if [ $hard_links_supported -eq 1 ]; then
259 start_test
"-noinplace"
260 # Hard link the message and verify that the new one doesn't get annotated.
261 cp "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.copy"
262 ln "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
263 cat >"$expected" <<EOF
264 From: Test8 <test8@example.com>
265 To: Some User <user@example.com>
266 Date: Fri, 29 Sep 2006 00:00:00
267 Message-Id: 8@test.nmh
268 Subject: Testing message 8
269 Resent-From: ${localmbox}
270 Resent-To: somebody@example.com
273 This is message number 8
275 test_dist
8 -noedit -to somebody@example.com
-annotate -noinplace
276 mv -f "${MH_TEST_DIR}/Mail/inbox/8.copy" "${MH_TEST_DIR}/Mail/inbox/8"
277 check
"${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link" \
281 start_test
"-inplace"
282 # Hard link the message and verify that the new one does get annotated.
283 ln "${MH_TEST_DIR}/Mail/inbox/9" "${MH_TEST_DIR}/Mail/inbox/9.link"
284 cat >"$expected" <<EOF
285 From: Test9 <test9@example.com>
286 To: Some User <user@example.com>
287 Date: Fri, 29 Sep 2006 00:00:00
288 Message-Id: 9@test.nmh
289 Subject: Testing message 9
290 Resent-From: ${localmbox}
291 Resent-To: somebody@example.com
294 This is message number 9
296 test_dist
9 -noedit -to somebody@example.com
-annotate -noinplace -inplace
297 check
"${MH_TEST_DIR}/Mail/inbox/9" "${MH_TEST_DIR}/Mail/inbox/9.link"
301 start_test
"-draftfolder"
302 cat >"$expected" <<EOF
303 From: Test3 <test3@example.com>
304 To: Some User <user@example.com>
305 Date: Fri, 29 Sep 2006 00:00:00
306 Message-Id: 3@test.nmh
307 Subject: Testing message 3
308 Resent-From: ${localmbox}
309 Resent-To: somebody@example.com
312 This is message number 3
315 test_dist
3 -noedit -to somebody@example.com
-draftfolder drafts
318 start_test
"-draftmsg"
319 cat >"$expected" <<EOF
320 From: Test3 <test3@example.com>
321 To: Some User <user@example.com>
322 Date: Fri, 29 Sep 2006 00:00:00
323 Message-Id: 3@test.nmh
324 Subject: Testing message 3
325 Resent-From: ${localmbox}
326 Resent-To: somebody@example.com
329 This is message number 3
332 touch $MH_TEST_DIR/Mail
/drafts
/3
333 test_dist
3 -noedit -to somebody@example.com
-draftfolder drafts
-draftmessage 2
335 # check -nodraftfolder
336 start_test
"-nodraftfolder"
337 cat >"$expected" <<EOF
338 From: Test3 <test3@example.com>
339 To: Some User <user@example.com>
340 Date: Fri, 29 Sep 2006 00:00:00
341 Message-Id: 3@test.nmh
342 Subject: Testing message 3
343 Resent-From: ${localmbox}
344 Resent-To: somebody@example.com
347 This is message number 3
350 test_dist
3 -noedit -to somebody@example.com
-draftfolder nonexistent \
352 if test -d "${MH_TEST_DIR}/Mail/nonexistent"; then
353 echo "$0: -nodraftfolder test failed."
354 failed
=`expr ${failed:-0} + 1`
359 cat >"$expected" <<EOF
360 From: Test1 <test1@example.com>
361 To: Some User <user@example.com>
362 Date: Fri, 29 Sep 2006 00:00:00
363 Message-Id: 1@test.nmh
364 Subject: Testing message 1
365 Resent-From: me@example.com
366 Resent-To: somebody@example.com
369 This is message number 1
372 test_dist
1 -noedit -to somebody@example.com
-from me@example.com
376 cat >"$expected" <<EOF
377 From: Test1 <test1@example.com>
378 To: Some User <user@example.com>
379 Date: Fri, 29 Sep 2006 00:00:00
380 Message-Id: 1@test.nmh
381 Subject: Testing message 1
382 Resent-From: ${localmbox}
383 Resent-To: somebody@example.com
384 Resent-cc: cc@example.com
387 This is message number 1
390 test_dist
1 -noedit -to somebody@example.com
-cc cc@example.com
394 cat >"$expected" <<EOF
395 From: Test1 <test1@example.com>
396 To: Some User <user@example.com>
397 Date: Fri, 29 Sep 2006 00:00:00
398 Message-Id: 1@test.nmh
399 Subject: Testing message 1
400 Resent-From: ${localmbox}
401 Resent-To: somebody@example.com
404 This is message number 1
407 test_dist
1 -noedit -to somebody@example.com
-fcc outbox
408 run_test
'scan +outbox -width 6' ' 1 '
411 start_test
"-fcc with +"
412 cat >"$expected" <<EOF
413 From: Test1 <test1@example.com>
414 To: Some User <user@example.com>
415 Date: Fri, 29 Sep 2006 00:00:00
416 Message-Id: 1@test.nmh
417 Subject: Testing message 1
418 Resent-From: ${localmbox}
419 Resent-To: somebody@example.com
422 This is message number 1
425 test_dist
+inbox
1 -noedit -to somebody@example.com
-fcc +outbox
426 run_test
'scan +outbox -width 6 2' ' 2 '
428 # check Distribute- and Distribution-
429 start_test
"Distribute- and Distribution-"
430 cat >"$expected" <<EOF
431 -- Network Recipients --
432 dist-recipient at example.com
435 folder
-f +inbox
>/dev
/null
436 arith_eval
`pick last` + 1
438 cat >`mhpath new` <<EOF
439 From: Test$new_msg <test$new_msg@example.com>
440 Date: Sun, 10 May 2020 10:00:00
443 cat >`mhpath new` <<EOF
444 Distribution-From: <a@example.com>
445 Distribute-To: <dist-recipient@example.com>
448 mhdist
=`pick last` mhaltmsg
=`mhpath $new_msg` whom
`mhpath last` >"$actual"
449 check
"$expected" "$actual"
452 # Check that dist encodes headers using RFC-2047 properly
454 start_test
"dist encodes headers using RFC-2047 properly"
455 require_locale en_US.UTF-8 en_US.UTF8 en_US.utf-8 en_US.utf8
457 cat >"$expected" <<EOF
458 From: Test1 <test1@example.com>
459 To: Some User <user@example.com>
460 Date: Fri, 29 Sep 2006 00:00:00
461 Message-Id: 1@test.nmh
462 Subject: Testing message 1
463 Resent-From: =?UTF-8?Q?Mr_F=C3=B8o_Bar?= <resent-from@example.com>
464 Resent-To: =?UTF-8?Q?Mr_Nobod=C3=BF?= <resent-to@example.com>
467 This is message number 1
470 test_dist
+inbox
1 -noedit -from 'Mr Føo Bar <resent-from@example.com>' \
471 -to 'Mr Nobodÿ <resent-to@example.com>' -fcc +outbox